Actually, iBATIS will take care of this automatically for you - it will break a batch into "sub-batches" based on the different statements. So option 1 works fine - you can intermix statement types. And iBATIS always uses prepared statements.
However, it would still be best to group inserts and updates together - if you don't you might end up with a lot of different "sub batches" and lose the performance benefits of a batch.
Some psuedo code to demonstrate this:
try {
startTransaction();
startBatch();
allInserts();
allUpdates();
executeBatch(); //optional - because the commitTransaction will also execute the batch
commitTransaction();
} finally {
endTransaction();
}
There is some greater detail about this in the latest developers guide in SVN.
Jeff Butler
On 7/27/06, Mkhitaryan, Aram <[EMAIL PROTECTED]> wrote:
Between start and execute Batch() methods you can execute only inserts and updates.
SqlMap every statement executes with PreparedStatements.
Use also startTransaction(), commitTransaction(), endTransaction() methods.
Only with this methods batch works normal.
Example:
try {
sqlMap.startTransaction();
sqlMap.startBtach()
all inserts
sqlMap.executeBatch()
sqlMap.startBtach()
all updates
sqlMap.executeBatch()
sqlMap.commitTransaction();
} finally {
sqlMap.endTransaction();
}
Best,
Aram
-----Original Message-----
From: Sumanta Ghosh [mailto:[EMAIL PROTECTED]]
Sent: Thursday, July 27, 2006 3:21 PM
To: [email protected]
Subject: IBATIS Batch Support
Does IBATIS have Batch support for preparedstatements e.g. suppose I have got
4 statements, 2 inserts and 2 update. How should I call batch?
Option 1:
sqlMap.startBatch();
all statements
sqlMap.executeBatch()
Option 2:
sqlMap.startBtach()
all inserts
sqlMap.executeBatch()
sqlMap.startBtach ()
all updates
sqlMap.executeBatch()
In my idea for option 1 you cannot use preparedstatement, have to use
statements.
Am I Correct? please confirm.
--
View this message in context: http://www.nabble.com/IBATIS-Batch-Support-tf2008779.html#a5518529
Sent from the iBATIS - User - Java forum at Nabble.com.
