Sun Adapter for Oracle Tutorials

Creating the Business Rules for the jcdPsSelect Collaboration

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_output0.dat to confirm when records are selected, or when no records are available.

Using the Collaboration Editor's Java Source Editor

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 prjOracle_JCD;


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, 
otdOracle.OtdOracleOTD otdOracle_1, dtd.otdOutputDTD1007064608.
DBemployee otdOutputDTD_DBemployee_1, com.stc.connector.appconn.file.FileApplication 
FileClient_1 )
       throws Throwable
   {
       FileClient_1.setText( "Selecting record(s) from db_employee table via Prepared 
Statement select .." );
       FileClient_1.write();
       otdOracle_1.getSelect_ps().setEmpno( new java.math.BigDecimal( "0" ) );
       otdOracle_1.getSelect_ps().executeQuery();
       if (otdOracle_1.getSelect_ps().resultsAvailable()) {
           while (otdOracle_1.getSelect_ps().get$Select_psResults().next()) {
               otdOutputDTD_DBemployee_1.setEmpNo( otdOracle_1.getSelect_ps().get$Select_psResults().getEMP_NO().toString() );
               otdOutputDTD_DBemployee_1.setLastname( otdOracle_1.getSelect_ps().get$Select_psResults().getLAST_NAME() );
               otdOutputDTD_DBemployee_1.setFirstname( otdOracle_1.getSelect_ps().get$Select_psResults().getFIRST_NAME() );
               otdOutputDTD_DBemployee_1.setRate( Double.toString( otdOracle_1.getSelect_ps().get$Select_psResults().getRATE() ) );
               otdOutputDTD_DBemployee_1.setLastDate( otdOracle_1.getSelect_ps().get$Select_psResults().getLAST_UPDATE().toString() );
               FileClient_1.setText( otdOutputDTD_DBemployee_1.marshalToString() );
               FileClient_1.write();
           }
       } else {
           FileClient_1.setText( "No record found!" );
           FileClient_1.write();
       }
       FileClient_1.setText( "Done Select." );
       FileClient_1.write();
   }

} 

Note –

The above code has been wrapped for display purposes.


ProcedureCreate the jcdPsSelect Collaboration Business Rules

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

    The Java Collaboration Editor opens to the jcdPsSelect Collaboration.

  2. From the Collaboration Editor toolbar, select the Source Code Mode button.

    The Collaboration displays the Business Rules window and the Java Source Editor window.

  3. Copy the code above and paste it into the Java Source Editor, replacing the current code. The above code was wrapped in 10 places for display purposes. Correct the wrapped lines of code (the wrapped lines contain no left margin) by placing your cursor at the beginning of the line and hitting backspace (or the equivalent)

  4. Once you have corrected the code, click the Commit changes button on the Java Source Editor toolbar.

    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.

  5. Expand the business rules in the Business Rules window to see the completed Collaboration. Click the Advanced Mode button in the Collaboration Editor toolbar to open the Business Rules Designer window. Double click on a line of code in the Java Source Editor, and that rule is displayed graphically in the Business Rule Designer.

  6. Click Save All to save your current changes.

    The completed Collaboration definition appears as follows:

    Image shows the completed jcdPsSelect Java Collaboration
Definition business rules.