Sun Adapter for DB2 Tutorials

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 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.