ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hycel Taylor <hyc...@gmail.com>
Subject Doing Batch Processing with IBatis from DAO Manager
Date Thu, 11 Aug 2005 01:30:11 GMT
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.

Mime
View raw message