I am new to iBatis and have used Spring JDBC Templates.  I want to use iBatis SQL Mapping for its abstraction, but I have some questions about things that I can currently do and how would I best implement them in iBatis.

1) I have a TransferObjectAssembler that calls multiple DAO queries to assemble a composite object.  In iBatis, would I just call these multiple iBatis template/queries and use the results to assemble the object.

2) With XA, there seems to be quite a bit of issue with some of our complex processes.  For instance, we have to run multiple select statements from three datasources, delete records from two datasources, and then insert records into three datasources.  XA appears to get angry when you open and close multiple connections...multiple times...to multiple datasources.  So in order to get XA to play nice, we have to open a connection to one datasource and perform all its operations...then close that connection, and then move onto the next datasource.  Can you use the same connection for multiple iBatis queries?

3) I modified the Spring JDBC Template piece for executing batch so that I could allow developers to suggest a commit size for executing the batch.  So if you were updating 100,000 records...you could executeBatch every 100 or so to make sure you did not overflow the cache of buffering too many prepared statements.  I don't see that functionality...so I wanted to know if something like the following would be a correct way to implement this based on the sample code in the SqlMapClient javadoc:

  int commitSize = 100;
  boolean commitBatch = false;
  int totalRecordsUpdated = 0;
  int commitBatchUpdated = 0;
  try {
   List list = (Employee) sqlMap.queryForList("getFiredEmployees", null);
   for(int i=0; i < list.size(); i++) {
      sqlMap.startBatch();
      sqlMap.delete ("deleteEmployee", list.get(i));
      if(i == commitSize -1) {
        commitBatch = true;
      }
      else if(i == list.size() -1) {
        commitBatch = true;
      }
      if(commitBatch) {
        commitBatchUpdated = sqlMap.executeBatch();
        totalRecordsUpdated = totalRecordsUpdated + commitBatchUpdated;
        commitBatch = false;
      }
   }
 catch(SQLException e) {
    if(commitBatchUpdated == 0) {
      throw new RuntimeException("No records were modified by the batch statement.", e);
    }
    else {
      throw new RuntimeException("Statement was unable to complete successfully.", e)
    }
 }
 return totalRecordsUpdated;

Thanks for your help...and I look forward to using iBatis!

--
jay blanton
[EMAIL PROTECTED]

Reply via email to