K2ROM and Transactions


Badge +2
Can anyone confirm for me whether calls to the K2ROM are transactional?

For example, if a method in a transactional ASP.NET page calls the K2ROM (eg to update some K2 process instance data) and also updates some other transactional resource (eg another SQL server database), will the two updates be treated as a single atomic transaction?

I know that events and activities within a K2 workflow support transactions, but does the K2ROM support transactions when called from outside a K2 workflow (as in my example above)?

Thanks in advance

Simon Ainsworth, Technical Architect, Wildnet :?:

11 replies

Badge +2
Since posting my original question I have carried out the following tests to check how K2 handles transactions:

Test 1:
Create an activity consisting of one transactional event, which uses K2ROM to update some process instance data then deliberately throws an exception.
As expected, this results in the updates being rolled back.

Test 2:
Create an activity consisting of two transactional events, each of which updates data in an external SQL server database. The 2nd event deliberately throws an exception after the update. The activity is configured to run all events in 1 transaction.
As expected the updates from both events are rolled back.

Test 3:
Create an activity consisting of two transactional events, each of which use K2ROM to update some process instance data. The 2nd event deliberately throws an exception after the update. The activity is configured to run all events in 1 transaction.
I expected the updates from both events to be rolled back. But instead, only the updates from event 2 are rolled back.

Test 4:
Create a transactional ASP.NET web page containing a button. In the click event handler for the button use K2ROM to update a data field of a K2 process instance, then throw an exception.
I expected the updates to be rolled back. But instead they persist despite the exception.

These test results suggest that K2ROM is transactional only inside individual events. It does not appear to be transactional across events, nor within a web page.

Please correct me if I am wrong.

Thanks

Simon
Badge
Hi Simon,

I'm trying to get the transaction thing work in K2Studio.
Can you show me how the COM+ thing work?
If possible can you give me an example?

Thanks alot.
Badge +2
Hi Hong,

I hope the following additional information helps you:

In Test 1 we set up the K2 server event as follows:
- Tick the "Execute Event in a transaction" checkbox in the Event General tab of the event properties page.
- Add the following code to the event (where "MyField" is already defined as a process instance data field):
K2.ProcessInstance.DataFields["MyField"].Value = 123;
throw new Exception("Whoops!");

In Test 2 we created a K2 activity consisting of two server events. The activity was set up as follows:
- Tick the "Execute all event as one transaction" checkbox in the Activity General tab of the activity properties page.

Each event in Test 2 was set up as follows:
- Tick the "Execute Event in a transaction" checkbox in the Event General tab of the event properties page.
- Add code to the event to call an external .NET DLL that updates an external SQL Server database (the DLL we used does not explicit manage transactions itself, and so runs within the caller's transaction).
- Add the following line of code at the end of the 2nd event:
throw new Exception("Whoops!");

In Test 3 we created a K2 activity consisting of two server events. The activity was set up as described above in Test 2. Each event was set up as described above in Test 1 (except that only the 2nd event threw an exception).

In Test 4 we created a ASP web page containing the following transaction directive (this makes all event handlers automatically begin/end a transaction):
<@ Page Transaction= Required >

We then added a button with the following click event handler:
private void MyButton_Click(object sender, System.EventArgs e)
{
SourceCode.K2ROM.Connection myConn = new SourceCode.K2ROM.Connection();
myConn.Open("MyServer");
Worklist myList = myConn.OpenWorklist("ASP");
WorklistItem myItem = myList[0];
ProcessInstance myProc = myItem.ProcessInstance;
myProc.DataFields["MyField"].Value = 234;
myProc.Update();
myConn.Close();
throw new Exception("Whoops!");
}

Hope this helps

Now does anyone have an answer to my original question? Is anyone from K2 reading this user group?

Simon
Badge +1
In answer to your original question, no. K2ROM is not transaction aware.
Badge
Hi,

Worklist myList = myConn.OpenWorklist("ASP");


As I guess, the value "ASP" is the name of the platform. But I am wondering if we must always use "ASP" or there is any other platform?
Badge +11
Hi,

In K2.net 2003 Studio, when you specify a client event's platform, you can define ANY platform you like. The only thing to keep in mind is that K2.net 2003 Workspace and the K2.net Sharepoint Tasklist will ONLY show items defined with the "ASP" platform.

Therefore, if you would like to create worklist items which should NOT be visible from the normal K2.net 2003 Workspace, but maybe only from an external custom worklist, you can create the worklist items with a "CUSTOM" platform.

Hope this makes sense,
Ockert
Badge
Thanks Ockert for your helpful reply.
But I have another question and it would be nice to hear your answer.
You said that:
pentaco)" target="_blank">http://www.pentaco.co.za/K2/K2_net%20Enterprise%20Workflow%20Manage.htm]pentaco)
Badge +11
Hi,

I agree, this can be a bit confusing. It is actually two totally different things we're talking about here.

The platform associated with a worklist item (and passed-in as a parameter to some of the K2ROM's methods), is actually nothing more than a Filter used to retrieve specific 'Types' of worklist items. Instead of "ASP", we could have used something like "K2" for internal component use like K2.net 2003 Workspace and the K2 Sharepoint Tasklist - but unfortunately this was something which rolled over from previous K2.net 2.4 (COM and ASP based) implementations.

As you can see, this has got nothing to do with technologies such as ASP, JSP and PHP you can use to interact with K2ROM.

Hope this makes sense,
Ockert
Badge
Many thanks Ockert.
Badge +9
(Just my 5 scents worth) The Platform plays a significant role in custom worklist development, have a look at the following example. Our sales people spend most of the week on the road, to be able to get hold of work they make use of PDA s hand held devises. We have developed a custom worklist that is optimized to run on PDA s. Some days the sales people will work from the office, they prefer to use notebooks whiles in the office. We have configured the process to create a Worklist item for each worklist. The default worklist items we kept the platform APS and for mobile devises we made the platform Mobile . On the OpenWorklist method we specify the correct platform and only return the items associated with the device/worklist we use, giving the sales people the ability to action task effectively regardless of the technology they make use of (Notebook or PDA).
Badge +9
I guess the other question will be:

Where do I specify the Platform?
Configure a default client event in K2.net Studio, select the Use Code option on the properties of the event and click on the Edit Code button.
Locate the following line of code:

 Function HTTPFunction(Byval K2 as ClientEventContext)
Dim strURL as String
strURL = "http://myserver/mysite/mypage.aspx?sn={SERIALNO}"
strURL = strURL.Replace("{SERIALNO}",K2.SerialNumber)
K2.AddWorklist("ASP",System.Web.HttpUtility.UrlPathEncode(strURL))
End Function


Note: The AddWorklist method takes 2 parameters, the first being the Platform

Can I change the Platform?
Yes! (Look at next question)

What do I need to consider when changing the Platform?
The standard K2.net 2003 Worklist and SPS Tasklist will only display items where the platform is ASP . Changing the platform to anything other than ASP will cause these items not to be available from our standard worklist.

Reply