Saturday, October 15, 2011

Ex2. Batch Transaction Type

In this example2, I will cover ‘Batch’ Transaction type for JCAF.
  • FTP File to FTP File : svcFileMappingExample
  • File to Database : svcDBTableMappingExample
Through this example of Batch Transaction Type, you can explore the following unique characteristics from other JCAPS implementation.
1. Dynamic Routing  
    1
.1 Subscribing to JMS with JMS Message Selector
    1.2 Publishing to JMS
          - In CM, it has only queDummy.
          - Actual dynamic routing is done in Collaboration level with the JMSOTD.sendTo() utility.
2. No Batch Adapter used to read / write files
    - In CM, there is no Batch adapter to read or write to/from a file.
    - BatchLocalFileUtil Class will be used to handle files.
Example:
        BatchLocalFileUtil batchLocalFileUtil = new BatchLocalFileUtil();
        batchLocalFileUtil.setFileName(inputFullPathFileName);
        while ((record = batchLocalFileUtil.readLine()) != null) {
            otdPurchaseOrderApprovalRequest.unmarshalFromString(record);
        }
3. Template based Collaboration
   - Based on 4 different transaction types, it has a different Collaboration template. So just simply copying it will dramatically reduce your development.
   - Tamplate Projects will be released in the future.
4. Exception Handler
   - handleException() method will capture every Exception and will send information to CMSF. It will send automatic Alert notification email to Support and User.
5. Minimize System Usage
   5.1 File reading and writing should be handled with line by line.
        while ((record = batchLocalFileUtil.readLine()) != null) {
           batchLocalOutputFileUtil.writeBufferedFile(OTD.marshalToString());
        }
-With this approach, JCAPS can handle unlimited file size as long as OS allows with a really small system resource.
5.2 Single Element in Custom OTD
- When you create Custom OTD, don’t use group and repeated elements if possible.
- Combined 5.1 approach, we can always protect JCAPS Environment with minimal system usage.
6. Use JDBC Database eWay(Adapter)
    - As long as Database supports JDBC, you don’t need to have specific database adapter. (Cost Saving)
7. Database Connection OTD
    6.1 For the same user database connection, create only one DB OTD and reuse it.
    6.2 Don’t put any detail SQL information in the OTD.
    - Why you create specific DB OTD over and over? Here is example how this approach works. (Refer to jcdDBTableMappingExample Collaboration)
transform(input, otdEAICommonHeaderIn, otdDataStorage.getConnection());

transform(……, Connection conDataStorage){
         String insert = “INSERT ……. VALUES(?,?,?,?)”;
         conDataStorage.setAutoCommit(false);
         preparedStatement = conDataStorage.prepareStatement(insert);
}
8. com.wwlee.jcaps.cs.connection.ExternalDatabaseConnection Java Utility    - Let’s assume you have so many different types of daily, weekly, or monthly Batch interfaces and  need to insert information to different databases such as SQL, Oracle, Teradata, DB2, etc.
    - In this case, do we need to create all of OTDs and put them in Connectivity Map? Answer is no. You don’t need to have Database Connection Pool because is batch.
    - If this is the interface which you have, you can use ExternalDatabaseConnection Java Utility. (Refer to jcdDBTableMappingExample)
8. Always close DB Cursor.
    - Whenever you create statement clause in JDBC, it opens cursor in database side. If you don’t close it and this number is reached to maximum, all of Collaborations which use the same database schema will get the JDBC cursor exception.
     - To prevent this critical issue, the best practice is ‘close the cursor’.
     - In addition, if you use ExternalDatabaseConnection Java Utility, DB Connection should be always closed.
     - I recommend Connection and PreparedStatement should be defined as global variables.
     - Here is example. (Refer to jcdDBTableMappingExample)
    private Connection conMimicBatchExternal;
    private PreparedStatement preparedStatement;
    public void receive(){
         try{
         }catch(Exception ex){
         } finally {
             finallyClose();
         }
    }
   private void finallyClose()
            throws Exception {
        if (preparedStatement != null) {
            preparedStatement.close();
            preparedStatement = null;
        }
        if (conMimicBatchExternal != null && !conMimicBatchExternal.isClosed()) {
            conMimicBatchExternal.close();
            conMimicBatchExternal = null;
        }
    }

For the detailed setup and test scenarios, refer to the below document and sample zip file.
Example2_Batch_For_JCAF.doc
Example2_Batch.zip

No comments:

Post a Comment