Sun Adapter for DB2 Tutorials

Creating the Business Rules for the jcdUpdate Collaboration

The jcdUpdate Collaboration implements the Input Web Service Operation to read the TriggerUpdate.in. file and then update the record emp_no = 300. The Collaboration also writes a message to JCD_Update_output1.dat to confirm an updated record.


Note –

The where clause in the business rule reads the trigger value as a placeholder for input. This permits you to modify the query to select a specific record. Also note that all records are selected from the database when the TriggerTableSelect.in file is empty.


ProcedureCreate the jcdUpdate Collaboration Business Rules

You can create the jcdTableSelect Java Collaboration business rules by following the steps below, or by copying the jcdUpdate Collaboration Java Code into the Collaboration Editor's Java Source Editor as described in Using the Collaboration Editor's Java Source Editor.

  1. From the Project window, double-click the jcdUpdate Collaboration under your project's jcdALL node.

    The Java Collaboration Editor opens to the jcdUpdate Collaboration.

  2. Create the Copy "Updating the Rate and Last_update fields .. " to FileClient_1.Text rule.

    1. Click the rule icon on the Business Rules toolbar to add a new rule in the Business Rules pane.

    2. From the Business Rules Designer toolbar's String menu, select Literal String.

      A String method box is added to the Business Rules Designer canvas.

    3. Double-click the value field of the String method box and enter Updating the Rate and Last_update fields .. as the value.

    4. Map the output node of the String method box, to Text, under FileClient_1 in the right pane of the Business Rules Designer.

  3. Create the FileClient_1.write rule.

    1. Click the rule icon on the Business Rules toolbar to add a new rule in the Business Rules pane.

    2. Right-click the FileClient_1 node in the left pane of the Business Rules Designer, and choose Select method to call from the popup menu.

      The method selection window appears.

    3. Select and double-click write() from the method selection window.

      The write method box appears in the Business Rules Designer canvas. The FileClient_1.write rule is added to the Business Rules tree.

  4. Create the otdDB2_1.DB_EMPLOYEE.update(input.Text) rule.

    1. Click the rule icon on the Business Rules toolbar to add a new rule in the Business Rules pane.

    2. Right-click DB_EMPLOYEE under otdDB2_1 in the left pane of the Business Rules Designer, and choose Select method to call from the popup menu.

      The method selection window appears.

    3. Select update(String sWhere) from the method selection window.

      The update method box appears in the Business Rules Designer canvas, and a link connects the DB_EMPLOYEE node in the left pane of the Business Rules Designer to the DB_EMPLOYEE input node of the update method box.

    4. Map Text under the input node in the left pane of the Business Rules Designer, to the sWhere (String) input node of the update method box.

  5. Add a While statement and create the condition: otdDB2_1.DB_EMPLOYEE.next rule.

    1. Click the While icon on the Business Rules toolbar to add a While statement to the Business Rules tree.

    2. Right-click DB_EMPLOYEE under otdDB2_1 in the left pane of the Business Rules Designer, and choose Select method to call from the popup menu.

      The method selection window appears.

    3. Select next() from the method selection window.

      The next method box appears in the Business Rules Designer canvas, and a link connects the DB_EMPLOYEE node in the left pane of the Business Rules Designer to the DB_EMPLOYEE input node of the next method box.

    4. Map the result (boolean) output node of the next method box, to the While condition in the right pane of the Business Rules Designer.

  6. Create the Copy new BigDecimal("22.2") to otdDB2_1.DB_EMPLOYEE.RATE rule beneath the While -> rules node.

    1. Select the rules node under the While statement on the Business Rules tree, and click the rule icon on the Business Rules toolbar to add a new rule.

    2. Right—click RATE node, under otdDB2_1 -> DB_EMPLOYEE in the right pane of the Business Rules Designer, and select Browse this type from the popup menu.

      The Class Browser appears. with BigDecimal selected as the class.

    3. From the ClassBrowser, select BigDecimal as the class, select theBigDecimal(String val) constructor as the method, and click Select.

      The BigDecimal method box appears.

    4. Double-click the val (String) field of the BigDecimal method box and enter 22.2 as the value.

    5. Map the result (BigDecimal) output node of the BigDecimal method box to the RATE node, under otdDB2_1 -> DB_EMPLOYEE in the right pane of the Business Rules Designer.

  7. Create the Copy Date.valueOf("2006-06-06") to otdDB2_1.DB_EMPLOYEE.LAST_UPDATE rule under the last rule.

    1. Click the rule icon on the Business Rules toolbar to add a new rule under your last rule.

    2. From the Business Rules Designer toolbar, click the Class Browser button.

    3. From the ClassBrowser, select Date as the class, select thevalueOf(String s) method, and click Select.

      The Date.valueOf method box appears.

    4. Double-click the s (String) field of the Date.valueOf method box and enter todays date as the value.

    5. Map the result (Date) output node of the Date.valueOf method box to the LAST_UPDATE node, under otdDB2_1 -> DB_EMPLOYEE in the right pane of the Business Rules Designer.

  8. Create the otdDB2_1.DB_EMPLOYEE.updateRow rule under the last rule.

    1. Click the rule icon on the Business Rules toolbar to add a new rule.

    2. Right-click DB_EMPLOYEE in the left pane of the Business Rules Designer, and choose Select method to call from the popup menu.

      The method selection window appears.

    3. Select updateRow() from the method selection window.

      The updateRow method box appears in the Business Rules Designer canvas, and a link connects the DB_EMPLOYEE node in the left pane of the Business Rules Designer to the DB_EMPLOYEE input node of the updateRow method box.

  9. Create the Copy "Update Done." to FileClient_1.Text rule.

    1. From the Business Rules tree, select the While statement, then click the rule icon on the Business Rules toolbar to add a new rule.

      A new rule is added to the main trunk of the Business Rules tree.

    2. From the Business Rules Designer toolbar's String menu, select Literal String.

      A String method box is added to the Business Rules Designer canvas.

    3. Double-click the value field of the String method box and enter Update Done. as the value.

    4. Map the output node of the String method box, to Text, under FileClient_1 in the right pane of the Business Rules Designer.

  10. Create the FileClient_1.write rule.

    1. Click the rule icon on the Business Rules toolbar to add a new rule in the Business Rules pane.

    2. Right-click the FileClient_1 node in the left pane of the Business Rules Designer, and choose Select method to call from the popup menu.

      The method selection window appears.

    3. Select and double-click write() from the method selection window.

      The write method box appears in the Business Rules Designer canvas. The FileClient_1.write rule is added to the Business Rules tree.

  11. Click Save All to save your current changes.

    The completed jcdUpdate Collaboration definition appears as follows:

    Image shows the completed jcdUpdate Java Collaboration
Definition business rules.

jcdUpdate Collaboration Java Code

The completed Java source code for the jcdUpdate Collaboration appears as follows:


package prjDB2_JCDjcdALL;


public class jcdUpdate
{

   public com.stc.codegen.logger.Logger logger;

   public com.stc.codegen.alerter.Alerter alerter;

   public com.stc.codegen.util.CollaborationContext collabContext;

   public com.stc.codegen.util.TypeConverter typeConverter;

   public void receive( com.stc.connector.appconn.file.FileTextMessage input, com.stc.
connector.appconn.file.FileApplication FileClient_1, otdDB2.OtdDB2OTD otdDB2_1 )
       throws Throwable
   {
       FileClient_1.setText( "Updating the Rate and Last_update fields .. " );
       FileClient_1.write();
       otdDB2_1.getDB_EMPLOYEE().update( input.getText() );
       while (otdDB2_1.getDB_EMPLOYEE().next()) {
           otdDB2_1.getDB_EMPLOYEE().setRATE( new java.math.BigDecimal( "22.2" ) );
           otdDB2_1.getDB_EMPLOYEE().setLAST_UPDATE( java.sql.Date.
valueOf( "2006-06-06" ) );
           otdDB2_1.getDB_EMPLOYEE().updateRow();
       }
       FileClient_1.setText( "Update Done." );
       FileClient_1.write();
   }

}

Note –

The above code has been wrapped for display purposes.


Next Steps

For your next step, see Creating the Connectivity Maps .