To enable the rollback of all committed procedures when a fault is thrown in a business process service, you must build a compensation routine.
Use the following example to assist you in building a compensation routine in a business process. Follows the instructions carefully. They include the creation of complex and nested activities.
Example Business Process with Compensation Routine
To build a compensation routine:
Create two JMS message services.
These will be used later in the process.
Define input and output parameters for the service operation:
Select the Service Interface tab in the Business Process service editor.
Select the operation on the service interface.
Expand the Operation Parameters section and add the following parameters:
Save the service. Select File|Save from the main menu bar.
Create two Local variables for the business process:
Select the Business Process tab to display the business process canvas.
Expand the Business Process Variables section.
Right-click the Local Variables category and select New variable from the context menu twice.
newVariable1 and newVariable2 are added to the Local Variables list.
Expand the Local Variables list, right-click NewVariable1, and select Edit variable from the context menu. Expand the Properties panel and change the variable Name and Data type to be the following:
Name = counter
Datatype = Simple/integer
Right-click NewVariable2, and select Edit variable from the context menu. Then, change the variable name and data type in the Properties panel to be the following:
Name = loopCounter
Datatype = Simple/integer
Save the service. Select File|Save from the main menu bar.
Add an Assign activity to the business process:
Click inside the Business Process canvas and then select the Tool Palette using the Fast View shortcut bar.
Select Assign from the Activities palette and drag it on to the canvas.
Define the source and target for the Assign:
Drag the input parameter from the Interface Variables category in the Business Process Variables section into the Source column in the Properties panel.
Drag the counter from the Local Variables list in the Business Process Variables section into the Target column in the Properties panel.
Save the service. Select File|Save from the main menu bar.
Add a Complex activity to the business process service named Scope1:
Click inside the Business Process canvas and then select the Tool Palette using the Fast View shortcut bar.
Select Complex from the Activities palette and drag it on to the canvas.
Select the Complex activity on the canvas and rename Complex to Scope1 in the Properties panel.
Save the service. Select File|Save from the main menu bar.
Add a Fault Handler to Scope1:
Maximize the Scope1 activity to increase your work space.
Select Handle Fault from the Exception Processing tool palette and drag it into Scope1.
Maximize the Handle Fault activity to increase your work space.
Select Compensate from the Exception Processing tool palette and drag it onto the Handle Fault activity.
Connect the Start and Compensate activities.
Minimize the Handle Fault activity twice to return to the Scope1 activity.
Add a Complex activity to Scope1 named LoopScope:
Select another Complex from the Activities tool palette and drag it on into Scope1.
Select Complex on the canvas and define its properties in the Properties panel:
Select the Properties tab and rename the activity to LoopScope.
Select the Iterations tab and select This activity runs iteratively to open the Expression editor.
Drag the loopCounter (Local variable) from the Business Process Variables section to the Counter variable field in the Iteration Settings.
Click … in the Counter initial value row to open the Variable Reference Dialog. Select Literal and set the value to 1.
Click … in the Counter increment row to open the Variable Reference Dialog. Select Literal and set the value to 1.
Save the service. Select File|Save from the main menu bar.
Define an expression for LoopScope using the following example:
Replace the Select Variable in the Expression editor. Drag the local variable loopCounter from the Business Process Variables section onto the Select Variable.
Delete is equal to and string constant from the Expression editor. Right-click and select Delete from the context menu.
Drag the local variable counter from the Business Process Variables section onto the Expression editor.
Add another operator. Right-click inside the Expression editor canvas and select Boolean Functions|is less than or equal to.
Connect loopCounter to the upper node of the is less than or equal to operator.
Connect counter to the lower node of the is less than or equal to operator.
Save the service. Select File|Save from the main menu bar.
Add a Complex activity to LoopScope named TestCompLoop using the following example:
Select Complex from the Activities tool palette and drag it into LoopScope.
Select the Complex activity on the canvas and rename the activity to TestCompLoop in the Properties panel.
Maximize the TestCompLoop activity.
Add an Assign activity to TestCompLoop. Select Assign from the Activities tool palette and drag it into the TestCompLoop.
Add the first JMS Message Service to the activity. In the Service Explorer, expand the first JMS Message Service to display its operations. Drag the send operation from the Service Explorer into the TestCompLoop activity.
Define the source and target for the Assign:
Drag the loopCounter (Local variable) from the Business Process Variables section to the Source column in the Properties panel.
Drag the input parameter of the JMS message service from the Invoked Service Variables category in the Business Process Variables section into the Target column in the Properties panel.
Connect the flow of execution diagramed in the preceding example.
Add a Compensation Routine to TestLoopComp using the following example:
Select Compensation Routine from the Exception Processing tool palette and drag it into the TestLoopComp activity.
Maximize the Compensation Routine activity.
Select Assign from the Activities tool palette and drag it into the Compensation Routine.
Add the second JMS Message Service to the Compensation Routine. In the Service Explorer, expand the second JMS Message Service to display its operations. Drag the send operation from the Service Explorer into the Compensation Routine.
Connect the flow of execution diagramed in the preceding example.
Define the source and target for the Assign:
Drag the loopCounter local variable from the Business Process Variables section to the Source column in the Properties panel.
Drag the input parameter of the JMS message service from the Invoked Service Variables category in the Business Process Variables section into the Target column in the Properties panel.
Connect the flow of execution diagramed in the preceding example.
Save the service. Select File|Save from the main menu bar.
Minimize the Compensation Routine activity.
Minimize the TestCompLoop activity to return to LoopScope.
Connect Start to TestCompLoop.
Minimize LoopScope to return Scope1.
Connect Start to LoopScope.
Minimize Scope1 to return to the business process.
Connect the flow of execution as diagramed in the introductory example.
Save the service. Select File|Save from the main menu bar.
Send your feedback on this help topic to Sybase Tech Pubs: pubs@sybase.com