Skip Navigation Links | |
Exit Print View | |
Oracle Java CAPS Adapter for DB2 Tutorials Java CAPS Documentation |
Oracle Java CAPS Adapter for DB2 Tutorials
About the Oracle Java CAPS Adapter for DB2 Sample Projects
Sample Input Trigger Files and Output Files
Operations Used in the DB2 Sample Projects
About the Oracle Java CAPS Business Process Manager Project
Associating Business Process Manager Operators
Deploying JCD-Based Operations in the Business Process Manager
About the Java Collaboration Definition Sample Project
Importing Non-JBI Based Sample Projects
To Import a Non-JBI Based Sample Project
Creating the Java Collaboration Definition-Based Project for the Oracle Java CAPS Adapter for DB2
Create the Inbound and Outbound DTD OTDs
Creating the Collaboration Definitions (Java)
Create the Java Collaborations
Using the Java Collaboration Editor to create Business Rules
Creating the Business Rules for the jcdDelete Collaboration
Create the jcdDelete Collaboration Business Rules
jcdDelete Collaboration Java Code
Creating the Business Rules for the jcdInsert Collaboration
Create the jcdInsert Collaboration Business Rules
jcdInsert Collaboration Java Code
Creating the Business Rules for the jcdPsSelect Collaboration
Using the Collaboration Editor's Java Source Editor
Create the jcdPsSelect Collaboration Business Rules
Creating the Business Rules for the jcdTableSelect Collaboration
Create the jcdTableSelect Collaboration Business Rules
jcdTableSelect Collaboration Java Code
Creating the Business Rules for the jcdUpdate Collaboration
Create the jcdUpdate Collaboration Business Rules
Creating the Connectivity Maps
Adding Connectivity Maps to a Project
Add the Connectivity Maps to the Project
Populating and Binding the Connectivity Maps using the Connectivity Map Generator
Populate the Connectivity Maps using the Connectivity Map Generator.
Configuring the Adapter Properties
Configuring the Connectivity Map Properties
Configure the Connectivity Map Properties
File1 Inbound Adapter Properties
File2 Outbound Adapter Properties
DB21 Outbound Adapter Properties
Configuring the Environment Properties
Configure the Environment Properties
File Adapter Environment Properties
DB2 Adapter Environment Properties
Creating the Deployment Profile
Building and Deploying the Project
Deploying the Project from NetBeans
Creating the BPEL-Based Project for the Oracle Java CAPS Adapter for DB2
Creating the Business Processes
Create the bpDelete Business Process
Create the bpInsert Business Process
Create the bpPsSelect Business Process
Create the bpTableSelect Business Process
Create the bpUpdate Business Process
Using Business Process Designer to Create Business Rules
Creating the bpDelete Business Rules
Create the bpDelete Business Rules
Creating the bpInsert Business Rules
Create the bpInsert Business Rules
Creating the bpPsSelect Business Rules
Create the bpPsSelect Business Rules
Creating the bpTableSelect Business Rules
Create the bpTableSelect Business Rules
The prjDB2_JCD Project uses five Java Collaborations you created previously. To complete the Collaborations, use the Java Collaboration Editor's Business Rules Designer to create the business rules.
The Java Collaboration Editor also allows you to enter Java code to create business rules. The Java Source code is provided at the end of each Collaboration section, and can be copied into the Collaboration Editor's Java Source Editor to create the Collaboration.
This section contains the following topics:
Creating the Business Rules for the jcdPsSelect Collaboration
Creating the Business Rules for the jcdTableSelect Collaboration
The jcdDelete Collaboration implements the Input Web Service Operation to read the TriggerDelete.in file and then delete the record emp_no = 500. The Collaboration also writes a message to JCD_Delete_output1.dat to confirm a deleted 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 TriggerDelete.in file is empty.
The Java Collaboration Editor opens to the jcdDelete Collaboration.
A String method box is added to the Business Rules Designer canvas.
A visible link now connects the output node of the String method box and the Text node. The Business Rules tree now displays the new rule: Copy "Deleting record............" to FileClient_1.Text.
The method selection window appears.
The write method box appears in the Business Rules Designer canvas. The FileClient_1.write rule is added to the Business Rules tree.
The method selection window appears.
The delete 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 delete method box.
A String method box is added to the Business Rules Designer canvas.
The method selection window appears.
The write method box appears in the Business Rules Designer canvas. The FileClient_1.write rule is added to the Business Rules tree.
The completed jcdDelete Collaboration definition appears as follows:
The completed Java source code for the jcdDelete Collaboration appears as follows:
package prjDB2_JCDjcdALL; public class jcdDelete { 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( "Deleting record............" ); FileClient_1.write(); otdDB2_1.getDB_EMPLOYEE().delete( input.getText() ); FileClient_1.setText( "Delete Done." ); FileClient_1.write(); } }
Note - The above code has been wrapped for display purposes.
The jcdInsert Collaboration implements the Input Web Service Operation to read the TriggerInsert.in. file. It then unmarshals data from the input data into the otdInputDTD_DBEmployees OTD, calls the otdDB2 OTD, and inserts records into the database via a For Loop. The Collaboration also writes a message to JCD_Insert_output1.dat to confirm an inserted record.
The Java Collaboration Editor opens to the jcdInsert Collaboration.
A String method box is added to the Business Rules Designer canvas.
The method selection window appears.
The write method box appears in the Business Rules Designer canvas. The FileClient_1.write rule is added to the Business Rules tree.
The method selection window appears.
The unmarshalFromString method box appears in the Business Rules Designer canvas, and a link connects the otdInputDTD_DB_Employee_1 node in the left pane of the Business Rules Designer to the Db_employee input node of the unmarshalFromString method box.
The method selection window appears.
The insert 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 insert method box.
The Create Variable dialog box appears.
The i1 variable is added to the Business Rules Designer.
The Less Than method box appears in the Business Rules Designer canvas, and a link connects the i1 variable node in the left pane of the Business Rules Designer to the number1 input node of the i1 method box.
The countX_sequence_A method box appears in the Business Rules Designer canvas, and a link connects the otdInputDTD_DB_Employee_1 node in the left pane of the Business Rules Designer to the Db_Employee input node of the countX_sequence_A method box.
The method selection window appears.
The Add method box appears in the Business Rules Designer canvas, and a link connects the i1 node in the left pane of the Business Rules Designer to the value1 input node of the insert method box.
The Business Rules Designer adds the necessary code for stringToShort type conversion.
A BigDecimal method box appears in the Business Rules Designer Canvas.
A Date.valueOf method box appears in the Business Rules Designer Canvas.
The method selection window appears.
The insertRow 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 insertRow method box.
A new rule is added to the main trunk of the Business Rules tree.
A String method box is added to the Business Rules Designer canvas.
The method selection window appears.
The write method box appears in the Business Rules Designer canvas. The FileClient_1.write rule is added to the Business Rules tree.
The completed Collaboration definition appears as follows:
The completed Java source code for the jcdInsert Collaboration appears as follows:
package prjDB2_JCDjcdALL; public class jcdInsert { 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, dtd.otdInputDTD630345798 .DB_employee otdInputDTD_DB_employee_1, otdDB2.OtdDB2OTD otdDB2_1 ) throws Throwable { FileClient_1.setText( "Inserting records in to db_employee table......" ); FileClient_1.write(); otdInputDTD_DB_employee_1.unmarshalFromString( input.getText() ); otdDB2_1.getDB_EMPLOYEE().insert(); for (int i1 = 0; i1 < otdInputDTD_DB_employee_1.countX_sequence_A(); i1 += 1) { otdDB2_1.getDB_EMPLOYEE().setEMP_NO( typeConverter.stringToShort( otdInputDTD_DB_employee_1.getX_sequence_A( i1 ).getEmpNo(), "#", false, 0 ) ); otdDB2_1.getDB_EMPLOYEE().setLAST_NAME( otdInputDTD_DB_employee_1. getX_sequence_A( i1 ).getLastname() ); otdDB2_1.getDB_EMPLOYEE().setFIRST_NAME( otdInputDTD_DB_employee_1. getX_sequence_A( i1 ).getFirstname() ); otdDB2_1.getDB_EMPLOYEE().setRATE( new java.math.BigDecimal( otdInputDTD_DB_employee_1.getX_sequence_A( i1 ).getRate() ) ); otdDB2_1.getDB_EMPLOYEE().setLAST_UPDATE( java.sql.Date.valueOf( otdInputDTD_DB_employee_1.getX_sequence_A( i1 ).getLastDate() ) ); otdDB2_1.getDB_EMPLOYEE().insertRow(); } FileClient_1.setText( "Insert Done." ); FileClient_1.write(); } }
Note - The above code has been wrapped for display purposes.
The jcdPsSelect Collaboration implements the Input Web Service Operation to read the TriggerPsSelect.in file. It then copies the database resultset (as noted in the prepared statement query) into the otdInputDTD_DBEmployee OTD and selects all available records from the database. The Collaboration also writes a message to JCD_PsSelect_output1.dat to confirm when records are selected, or when no records are available.
To create the third Java Collaboration, jcdPsSelect, we will use the Java Source Editor. The Java Source Editor allows you to write your business rules in the editor, or copy code into the Collaboration Editor that you have written with another tool.
jcdPsSelect Collaboration Java Code
The completed Java source code for the jcdPsSelect Collaboration appears as follows:
package prjDB2_JCD_workjcdALL; public class jcdPsSelect { 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, dtd.otdOutputDTD262244478. DB_employee otdOutputDTD_DB_employee_1, otdDB2.OtdDB2OTD otdDB2_1 ) throws Throwable { FileClient_1.setText( "Selecting records from db_employee table via Prepared Statement select...." ); FileClient_1.write(); otdDB2_1.getSelect_ps().setParam1( typeConverter. stringToShort( "0", "#", false, 0 ) ); otdDB2_1.getSelect_ps().executeQuery(); if (otdDB2_1.getSelect_ps().resultsAvailable()) { while (otdDB2_1.getSelect_ps().get$Select_psResults().next()) { otdOutputDTD_DB_employee_1.setEmpNo( typeConverter.shortToString ( otdDB2_1.getSelect_ps().get$Select_psResults().getEMP_NO(), "#", false, "" ) ); otdOutputDTD_DB_employee_1.setLastname( otdDB2_1.getSelect_ps(). get$Select_psResults().getLAST_NAME() ); otdOutputDTD_DB_employee_1.setFirstname( otdDB2_1.getSelect_ps(). get$Select_psResults().getFIRST_NAME() ); otdOutputDTD_DB_employee_1.setRate( otdDB2_1.getSelect_ps(). get$Select_psResults().getRATE().toString() ); otdOutputDTD_DB_employee_1.setLastDate( typeConverter. dateToString( otdDB2_1.getSelect_ps().get$Select_psResults(). getLAST_UPDATE(), "yyyy-MM-dd hh:mm:ss", false, "" ) ); FileClient_1.setText( otdOutputDTD_DB_employee_1.marshalToString() ); FileClient_1.write(); } } else { FileClient_1.setText( "No record found!" ); FileClient_1.write(); } FileClient_1.setText( "Select Done." ); FileClient_1.write(); } }
Note - The above code has been wrapped for display purposes.
The Java Collaboration Editor opens to the jcdPsSelect Collaboration.
The Collaboration displays the Business Rules window and the Java Source Editor window.
If the code contains any errors they will be listed for you in the Validation window at the bottom of the NetBeans IDE. Correct these errors if necessary, and click the Commit changes button again.
The completed Collaboration definition appears as follows:
The jcdTableSelect Collaboration implements the Input Web Service Operation to read the TriggerTableSelect.in file. It then copies the database resultset into the otdInputDTD_DBEmployee OTD and selects all available records from the database that meet the criteria emp_no = 100. The Collaboration also writes a message to JCD_TableSelect_output1.dat to confirm when records are selected, or when no records are available.
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.
You can create the jcdTableSelect Java Collaboration business rules by following the steps below, or by copying the jcdTableSelect Collaboration Java Code into the Collaboration Editor's Java Source Editor as described in Using the Collaboration Editor's Java Source Editor.
The Java Collaboration Editor opens to the jcdTableSelect Collaboration.
A String method box is added to the Business Rules Designer canvas.
The method selection window appears.
The write method box appears in the Business Rules Designer canvas. The FileClient_1.write rule is added to the Business Rules tree.
The method selection window appears.
The select 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 select method box.
The method selection window appears.
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.
The Business Rules Designer adds the necessary code for shortToString type conversion.
The method selection window appears.
The toString method box appears in the Business Rules Designer canvas, and a link connects the RATE node in the left pane of the Business Rules Designer to the BigDecimal input node of the toString method box.
The Business Rules Designer adds the necessary code for dateToString type conversion.
The method selection window appears.
The marshalToString method box appears in the Business Rules Designer canvas, and a link connects otdOutputDTD_DB_employee_1 in the left pane of the Business Rules Designer to the DB_employee input node of the marshalToString method box.
The method selection window appears.
The write method box appears in the Business Rules Designer canvas. The FileClient_1.write rule is added to the Business Rules tree.
A new rule is added to the main trunk of the Business Rules tree.
A String method box is added to the Business Rules Designer canvas.
The method selection window appears.
The write method box appears in the Business Rules Designer canvas. The FileClient_1.write rule is added to the Business Rules tree.
The completed jcdTableSelect Collaboration definition appears as follows:
The completed Java source code for the jcdTableSelect Collaboration appears as follows:
package prjDB2_JCD_workjcdALL; public class jcdTableSelect { 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, dtd.otdOutputDTD262244478. DB_employee otdOutputDTD_DB_employee_1, otdDB2.OtdDB2OTD otdDB2_1 ) throws Throwable { FileClient_1.setText( "Selectiong records from db_employee table via Table Select........" ); FileClient_1.write(); otdDB2_1.getDB_EMPLOYEE().select( input.getText() ); while (otdDB2_1.getDB_EMPLOYEE().next()) { otdOutputDTD_DB_employee_1.setEmpNo( typeConverter.shortToString( otdDB2_1. getDB_EMPLOYEE().getEMP_NO(), "#", false, "" ) ); otdOutputDTD_DB_employee_1.setLastname( otdDB2_1.getDB_EMPLOYEE(). getLAST_NAME() ); otdOutputDTD_DB_employee_1.setFirstname( otdDB2_1.getDB_EMPLOYEE(). getFIRST_NAME() ); otdOutputDTD_DB_employee_1.setRate( otdDB2_1.getDB_EMPLOYEE(). getRATE().toString() ); otdOutputDTD_DB_employee_1.setLastDate( typeConverter.dateToString ( otdDB2_1.getDB_EMPLOYEE().getLAST_UPDATE(), "yyyy-MM-dd hh:mm:ss", false, "" ) ); FileClient_1.setText( otdOutputDTD_DB_employee_1.marshalToString() ); FileClient_1.write(); } FileClient_1.setText( "Table Select Done." ); FileClient_1.write(); } }
Note - The above code has been wrapped for display purposes.
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.
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.
The Java Collaboration Editor opens to the jcdUpdate Collaboration.
A String method box is added to the Business Rules Designer canvas.
The method selection window appears.
The write method box appears in the Business Rules Designer canvas. The FileClient_1.write rule is added to the Business Rules tree.
The method selection window appears.
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.
The method selection window appears.
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.
The Class Browser appears. with BigDecimal selected as the class.
The BigDecimal method box appears.
The Date.valueOf method box appears.
The method selection window appears.
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.
A new rule is added to the main trunk of the Business Rules tree.
A String method box is added to the Business Rules Designer canvas.
The method selection window appears.
The write method box appears in the Business Rules Designer canvas. The FileClient_1.write rule is added to the Business Rules tree.
The completed jcdUpdate Collaboration definition appears as follows:
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.
For your next step, see Creating the Connectivity Maps .