Sun Adapter for Oracle 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_output0.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 otdOracle_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 otdOracle_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: otdOracle_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 otdOracle_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 Double("888").doubleValue to otdOracle_1.DB_EMPLOYEE.RATE rule beneath the While -> rules node.

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

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

      The Class Browser appears.

    3. From the Class Browser, select Double as the class, and Double(String s) as the (constructor) method. Click Select.

      The Double method box is added to the Business Rules Designer canvas.

    4. Double-click the s (String) field of the Double method box, and enter a value of 888.

    5. Right-click the result (Double) output node of the Double method box and select Browse this type from the popup menu.

      The Class Browser appears.

    6. From the Class Browser, select Double as the class, and doubleValue() as the method. Click Select.

      The doubleValue method box is added to the Business Rules Designer canvas.

    7. Map the result (Double) output node of the Double method box, to the the Double input node of the doubleValue method box.

    8. Map the result (double) output node of the doubleValue method box, to RATE node, under otdOracle_1 -> DB_EMPLOYEE in the right pane of the Business Rules Designer.

      Image shows the JCD Editor displaying the Copy new Double
Rate doubleValue to otdOracle_1.DB_EMPLOYEE.RATE rule.
  7. Create the Copy Date.valueOf("2006-06-06") to otdOracle_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 today's date as the value.

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

  8. Create the otdOracle_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 prjOracle_JCD;


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, otdOracle.OtdOracleOTD otdOracle_1, com.stc.connector.appconn.file.FileApplication FileClient_1 )
       throws Throwable
   {
       FileClient_1.setText( "Update the Rate and Last_update fields .. " );
       FileClient_1.write();
       otdOracle_1.getDB_EMPLOYEE().update( input.getText() );
       while (otdOracle_1.getDB_EMPLOYEE().next()) {
           otdOracle_1.getDB_EMPLOYEE().setRATE( (new Double( "888" )).doubleValue() );
           otdOracle_1.getDB_EMPLOYEE().setLAST_UPDATE( java.sql.Date.valueOf( "2008-08-08" ) );
           otdOracle_1.getDB_EMPLOYEE().updateRow();
       }
       FileClient_1.setText( "Done Update." );
       FileClient_1.write();
   }

}

Note –

The above code has been wrapped for display purposes.


Next Steps

For your next step, see Creating the Connectivity Maps .