Description
iBatis SQLMaps incorporates a mechanism for utilizing the JDBC API's underlying batching capabilities (Statement.addBatch()) to efficiently group a set of database operations together for maximum performance. This mechanism works as expected for dynamic SQL, but does not work for callable statements.
This behavior has been deduced using P6Spy (configured to log to a Log4j SocketAppender) in conjunction with the SQL Profiler tool. As a note - NOT all JDBC Drivers support batching of callable statements. Older DB2 type 4 drivers did not support batching of callable statements. However, most modern drivers do (e.g. Sybase jConnect, Oracle JDBC Driver etc)
The fix for this issue is straightforward. Change the method definition for sqlExecuteUpdate in class com.ibatis.sqlmap.engine.mapping.statement.ProcedureStatement to be as follows:
protected int sqlExecuteUpdate(RequestScope request, Connection conn, String sqlString, Object[] parameters) throws SQLException {
if (request.getSession().isInBatch())
{ getSqlExecutor().addBatch(request, conn, sqlString, parameters); return 0; }else
{ return getSqlExecutor().executeUpdateProcedure(request, conn, sqlString.trim(), parameters); }}