ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Koka Kiknadze" <226...@gmail.com>
Subject Re: Passing ArrayList of Object for insert
Date Wed, 22 Nov 2006 14:35:06 GMT
Here's how I use it:
Lets assume insertObjects is an array of InsertObject -s that we want to
persist
            try
            {
                sqlMapClient.startTransaction();
                sqlMapClient.startBatch();
                for (InsertObject insertObject : insertObjects)
                {
                    sqlMapClient.insert("XMLFile.insertStatement",
insertObject);
                }
                sqlMapClient.executeBatch();
            }
            catch (SQLException ex)
            {
                 // log error etc. but note no explicit rollback needed
            }
            finally
            {
                try
                {
                    sqlMapClient.endTransaction();
                }
                catch (SQLException ex)
                {
                      \\ wow something's very very wrong
                }
            }
Please not that if the array is quite large (more than couple of hundred
objects) you'd better use startBatch-executeBatch-commits not for entire
loop, but slice it to say every 100. Of course these numbers are usually
determined by simply trying several values in the range  ~20-1000

Mime
View raw message