ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hycel Taylor <hyc...@gmail.com>
Subject How do I do batch processing with IBatis DAO
Date Thu, 11 Aug 2005 11:19:16 GMT
Hi,

I apologize, if this is the second time my email appears on the forum.
 I didn't see the first one show up after I posted it and this is my
first time posting on this forum.  Also, the first time I posted this
email, there were '3D' characters all in my code example.  I don't
know how they got there, so I removed them.

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;

destConnection = 
  connectionFactory.getConnection
    (ServiceConnectionFactory.CUSTOM_CONNECTION);

final ServiceConnection serviceConnection = 
  new ServiceConnection(destConnection, true, "MaxDB");

final DAOFactory daoFactory = new DAOFactory(serviceConnection);

schoolDAO = (SchoolDAO) daoFactory.getDAO(DAOFactory.SCHOLE_DAO);
majorDAO =  (MajorDAO) daoFactory.getDAO(DAOFactory.MAJOR_DAO);
courseDAO = (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.

Mime
View raw message