Hi,

Our DAO layer is a persistence abstraction layer...that is, it has no concept of batching, as it's specific to JDBC and relational databases.  The you can batch statements, and control the execution of them by simply writing your own executeBatch() method.

I recommend writing a single DAO for this, with the batch control methods.  So your code would look something like this:

try {
  daoManager.startTransaction();
  batchControlDAO.startBatch();
  schoolDAO.doWork();
  majorDAO.doWork();
  courseDAO.doWork();
  batchControlDAO.executeBatch();
  daoManager.commitTransaction();
} finally {
  daoManager.endTransaction();
}

All of your SQLMap DAOs (or JDBC DAOs) will have access to batch control methods within the DAO.

Hope that helps.

Clinton



On 8/10/05, Hycel Taylor <[EMAIL PROTECTED]> wrote:
Hi,

I'm converting my home grown custom DAO's over to IBatis sqlMaps and
the IBatis DAO's.  I'm finding IBatis a lot simpler to use than my
own.  However, I need to do a lot of batch processing and I need to do
it from the DAO tier.  With my custom DAO manager, I simply passed the
same connection to all the DAO's and batching was pretty transparent
and simple.  For example, I would instantiate my DAO's with the
following code:

private Connection destConnection;
private SchoolDAO schoolDAO;
private MajorDAO majorDAO;
private CourseDAO courseDAO;
=20
destConnection =3D
connectionFactory.getConnection(ServiceConnectionFactory.CUSTOM_CONNECTION )=
;
     final ServiceConnection serviceConnection =3D new
ServiceConnection(destConnection, true, "MaxDB");
     final DAOFactory daoFactory =3D new DAOFactory(serviceConnection);

schoolDAO =3D (SchoolDAO) daoFactory.getDAO(DAOFactory.SCHOLE_DAO);
majorDAO =3D (MajorDAO) daoFactory.getDAO(DAOFactory.MAJOR_DAO);
courseDAO =3D (CourseDAO) daoFactory.getDAO(DAOFactory.COURSE_DAO);

I would do insertions, updates or deletes using the given DAO's, for N
(say 1000) iterations.  Then I would use a method like the following
to execute a batch.

private void doBatchUpdate() throws SQLException {
   schoolDAO.executeBatch();
   majorDAO.executeBatch();
   courseDAO.executeBatch();
   destConnection.commit();
   destConnection.close();
}

This has been very powerful for me.  Because no matter how complex my
model and no matter how many DAO's I happen to be using, I can easily
accomplish my task.  I've even moved this capability up to my service
tier.  By passing in a connection at the service tier I have
simplified my code even further because a given service class may one
or more DAO's.

I would like to have the same functionality using IBatis Data Access
Objects.  Currently, I don't understand how to do this using your DAO
Manager.  You have a clear example of how to do batching directly
using SqlMaps.  But, I need to be able to do batching at the DAO tier.

Please, could you explain to me how I may do Batch processing using
IBatis DAO's.

Thank you.

Reply via email to