diff --git a/src/main/java/com/avaje/ebeaninternal/server/persist/BatchedBeanHolder.java b/src/main/java/com/avaje/ebeaninternal/server/persist/BatchedBeanHolder.java index 533b20b72..7e761ce47 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/persist/BatchedBeanHolder.java +++ b/src/main/java/com/avaje/ebeaninternal/server/persist/BatchedBeanHolder.java @@ -54,7 +54,7 @@ public class BatchedBeanHolder { * Set of beans in this batch. This is used to ensure that a single bean instance is not included * in the batch twice (two separate insert requests etc). */ - private final IdentityHashMap persistedBeans = new IdentityHashMap(); + private final IdentityHashMap persistedBeans = new IdentityHashMap(); /** * Create a new entry with a given type and depth. @@ -100,7 +100,7 @@ public class BatchedBeanHolder { } public String toString() { - StringBuilder sb = new StringBuilder(shortDesc.length()+18); + StringBuilder sb = new StringBuilder(shortDesc.length() + 18); sb.append(shortDesc); if (inserts != null) { sb.append(" i:").append(inserts.size()); diff --git a/src/main/java/com/avaje/ebeaninternal/server/persist/BatchedPstmt.java b/src/main/java/com/avaje/ebeaninternal/server/persist/BatchedPstmt.java index 1e3420ef4..fd82116fb 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/persist/BatchedPstmt.java +++ b/src/main/java/com/avaje/ebeaninternal/server/persist/BatchedPstmt.java @@ -16,142 +16,143 @@ import com.avaje.ebeaninternal.server.core.PstmtBatch; */ public class BatchedPstmt { - /** - * The underlying statement. - */ - private PreparedStatement pstmt; - - /** - * True if an insert that uses generated keys. - */ - private final boolean isGenKeys; - - /** - * The list of BatchPostExecute used to perform post processing. - */ - private final ArrayList list = new ArrayList(); - - private final String sql; - - private final PstmtBatch pstmtBatch; - - private final boolean occCheck; - - - /** - * Create with a given statement. - * @param isGenKeys true if an insert that uses generatedKeys - */ - public BatchedPstmt(PreparedStatement pstmt, boolean isGenKeys, String sql, PstmtBatch pstmtBatch, boolean occCheck) { - - this.pstmt = pstmt; - this.isGenKeys = isGenKeys; - this.sql = sql; - this.pstmtBatch = pstmtBatch; - this.occCheck = occCheck; + /** + * The underlying statement. + */ + private PreparedStatement pstmt; + + /** + * True if an insert that uses generated keys. + */ + private final boolean isGenKeys; + + /** + * The list of BatchPostExecute used to perform post processing. + */ + private final ArrayList list = new ArrayList(); + + private final String sql; + + private final PstmtBatch pstmtBatch; + + private final boolean occCheck; + + + /** + * Create with a given statement. + * + * @param isGenKeys true if an insert that uses generatedKeys + */ + public BatchedPstmt(PreparedStatement pstmt, boolean isGenKeys, String sql, PstmtBatch pstmtBatch, boolean occCheck) { + + this.pstmt = pstmt; + this.isGenKeys = isGenKeys; + this.sql = sql; + this.pstmtBatch = pstmtBatch; + this.occCheck = occCheck; + } + + /** + * Return the number of batched statements. + */ + public int size() { + return list.size(); + } + + /** + * Return the sql + */ + public String getSql() { + return sql; + } + + /** + * Return the statement. + */ + public PreparedStatement getStatement() { + return pstmt; + } + + /** + * Add the BatchPostExecute to the list for post execute processing. + */ + public void add(BatchPostExecute batchExecute) { + list.add(batchExecute); + } + + /** + * Execute the statement using executeBatch(). + * Run any post processing including getGeneratedKeys. + */ + public void executeBatch(boolean getGeneratedKeys) throws SQLException { + + executeAndCheckRowCounts(); + if (isGenKeys && getGeneratedKeys) { + getGeneratedKeys(); } - - /** - * Return the number of batched statements. - */ - public int size() { - return list.size(); + postExecute(); + close(); + } + + /** + * Close the underlying statement. + */ + public void close() throws SQLException { + if (pstmt != null) { + pstmt.close(); + pstmt = null; } - - /** - * Return the sql - */ - public String getSql() { - return sql; + } + + private void postExecute() throws SQLException { + for (int i = 0; i < list.size(); i++) { + list.get(i).postExecute(); + } + } + + private void executeAndCheckRowCounts() throws SQLException { + + if (pstmtBatch != null) { + // oracle specific JDBC batch processing + int rc = pstmtBatch.executeBatch(pstmt, list.size(), sql, occCheck); + if (list.size() == 1) { + list.get(0).checkRowCount(rc); + } + // the optimistic concurrency row count check + // has already been done by pstmtBatch so just return + return; + } - /** - * Return the statement. - */ - public PreparedStatement getStatement() { - return pstmt; - } - - /** - * Add the BatchPostExecute to the list for post execute processing. - */ - public void add(BatchPostExecute batchExecute){ - list.add(batchExecute); - } - - /** - * Execute the statement using executeBatch(). - * Run any post processing including getGeneratedKeys. - */ - public void executeBatch(boolean getGeneratedKeys) throws SQLException { - - executeAndCheckRowCounts(); - if (isGenKeys && getGeneratedKeys){ - getGeneratedKeys(); - } - postExecute(); - close(); - } - - /** - * Close the underlying statement. - */ - public void close() throws SQLException { - if (pstmt != null){ - pstmt.close(); - pstmt = null; - } - } - - private void postExecute() throws SQLException { - for (int i = 0; i < list.size(); i++) { - list.get(i).postExecute(); - } - } - - private void executeAndCheckRowCounts() throws SQLException { + // normal JDBC batch processing + int[] results = pstmt.executeBatch(); - if (pstmtBatch != null){ - // oracle specific JDBC batch processing - int rc = pstmtBatch.executeBatch(pstmt, list.size(), sql, occCheck); - if (list.size() == 1){ - list.get(0).checkRowCount(rc); - } - // the optimistic concurrency row count check - // has already been done by pstmtBatch so just return - return; - - } - - // normal JDBC batch processing - int[] results = pstmt.executeBatch(); - - if (results.length != list.size()){ - String s = "results array error "+results.length+" "+list.size(); - throw new SQLException(s); - } - - // check for concurrency exceptions... - for (int i = 0; i < results.length; i++) { - list.get(i).checkRowCount(results[i]); - } + if (results.length != list.size()) { + String s = "results array error " + results.length + " " + list.size(); + throw new SQLException(s); } - - private void getGeneratedKeys() throws SQLException { - - int index = 0; - ResultSet rset = pstmt.getGeneratedKeys(); - try { - while(rset.next()) { - Object idValue = rset.getObject(1); - list.get(index).setGeneratedKey(idValue); - index++; - } - } finally { - if (rset != null){ - rset.close(); - } - } + + // check for concurrency exceptions... + for (int i = 0; i < results.length; i++) { + list.get(i).checkRowCount(results[i]); } - + } + + private void getGeneratedKeys() throws SQLException { + + int index = 0; + ResultSet rset = pstmt.getGeneratedKeys(); + try { + while (rset.next()) { + Object idValue = rset.getObject(1); + list.get(index).setGeneratedKey(idValue); + index++; + } + } finally { + if (rset != null) { + rset.close(); + } + } + } + } diff --git a/src/main/java/com/avaje/ebeaninternal/server/persist/BeanPersister.java b/src/main/java/com/avaje/ebeaninternal/server/persist/BeanPersister.java index 31d8adc28..3e3719025 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/persist/BeanPersister.java +++ b/src/main/java/com/avaje/ebeaninternal/server/persist/BeanPersister.java @@ -9,19 +9,19 @@ import com.avaje.ebeaninternal.server.core.PersistRequestBean; */ public interface BeanPersister { - /** - * execute the insert bean request. - */ - void insert(PersistRequestBean request) throws PersistenceException; + /** + * execute the insert bean request. + */ + void insert(PersistRequestBean request) throws PersistenceException; - /** - * execute the update bean request. - */ - void update(PersistRequestBean request) throws PersistenceException; + /** + * execute the update bean request. + */ + void update(PersistRequestBean request) throws PersistenceException; - /** - * execute the delete bean request. - */ - void delete(PersistRequestBean request) throws PersistenceException; + /** + * execute the delete bean request. + */ + void delete(PersistRequestBean request) throws PersistenceException; } diff --git a/src/main/java/com/avaje/ebeaninternal/server/persist/BeanPersisterFactory.java b/src/main/java/com/avaje/ebeaninternal/server/persist/BeanPersisterFactory.java index eced4bee4..bc0c59089 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/persist/BeanPersisterFactory.java +++ b/src/main/java/com/avaje/ebeaninternal/server/persist/BeanPersisterFactory.java @@ -6,10 +6,10 @@ import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; * Factory for creating BeanPersister implementations. */ public interface BeanPersisterFactory { - - /** - * Create the BeanPersister implemenation for a given type. - */ - BeanPersister create(BeanDescriptor desc); + + /** + * Create the BeanPersister implemenation for a given type. + */ + BeanPersister create(BeanDescriptor desc); } diff --git a/src/main/java/com/avaje/ebeaninternal/server/persist/BindValues.java b/src/main/java/com/avaje/ebeaninternal/server/persist/BindValues.java index 41f1d5d36..bb41fd74b 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/persist/BindValues.java +++ b/src/main/java/com/avaje/ebeaninternal/server/persist/BindValues.java @@ -7,81 +7,81 @@ import java.util.ArrayList; */ public class BindValues { - final ArrayList list = new ArrayList(); - - /** - * Create with a Binder. - */ - public BindValues(){ - } - - /** - * Return the number of bind values. - */ - public int size() { - return list.size(); - } - - /** - * Add a bind value with its JDBC datatype. - * - * @param value the bind value - * @param dbType the type as per java.sql.Types - */ - public void add(Object value, int dbType, String name){ - list.add(new Value(value, dbType, name)); - } - - /** - * List of bind values. - */ - public ArrayList values() { - return list; - } - - /** - * A Value has additionally the JDBC data type. - */ - public static class Value { - - private final Object value; - - private final int dbType; - - private final String name; - - /** - * Create the value. - */ - public Value(Object value, int dbType, String name) { - this.value = value; - this.dbType = dbType; - this.name = name; - } + final ArrayList list = new ArrayList(); - /** - * Return the type as per java.sql.Types. - */ - public int getDbType() { - return dbType; - } - - /** - * Return the value. - */ - public Object getValue() { - return value; - } - - /** - * Return the property name. - */ - public String getName() { - return name; - } - - public String toString(){ - return ""+value; - } + /** + * Create with a Binder. + */ + public BindValues() { + } + + /** + * Return the number of bind values. + */ + public int size() { + return list.size(); + } + + /** + * Add a bind value with its JDBC datatype. + * + * @param value the bind value + * @param dbType the type as per java.sql.Types + */ + public void add(Object value, int dbType, String name) { + list.add(new Value(value, dbType, name)); + } + + /** + * List of bind values. + */ + public ArrayList values() { + return list; + } + + /** + * A Value has additionally the JDBC data type. + */ + public static class Value { + + private final Object value; + + private final int dbType; + + private final String name; + + /** + * Create the value. + */ + public Value(Object value, int dbType, String name) { + this.value = value; + this.dbType = dbType; + this.name = name; } + + /** + * Return the type as per java.sql.Types. + */ + public int getDbType() { + return dbType; + } + + /** + * Return the value. + */ + public Object getValue() { + return value; + } + + /** + * Return the property name. + */ + public String getName() { + return name; + } + + public String toString() { + return "" + value; + } + } } diff --git a/src/main/java/com/avaje/ebeaninternal/server/persist/DefaultPersister.java b/src/main/java/com/avaje/ebeaninternal/server/persist/DefaultPersister.java index 3a38a543a..4854a728e 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/persist/DefaultPersister.java +++ b/src/main/java/com/avaje/ebeaninternal/server/persist/DefaultPersister.java @@ -1066,7 +1066,7 @@ public final class DefaultPersister implements Persister { /** * Cascade delete child entities by Id. - *

+ *

* Will use delete by object if the child entity has manyToMany relationships. */ private void deleteChildrenById(SpiTransaction t, BeanDescriptor targetDesc, List childIds) { @@ -1202,7 +1202,7 @@ public final class DefaultPersister implements Persister { /** * Create an Insert or Update PersistRequestBean when cascading. - *

+ *

* This call determines the PersistRequest.Type based on bean state and the insert flag (root persist type). */ private PersistRequestBean createRequest(T bean, Transaction t, Object parentBean, boolean insertMode) { diff --git a/src/main/java/com/avaje/ebeaninternal/server/persist/DeleteUnloadedForeignKeys.java b/src/main/java/com/avaje/ebeaninternal/server/persist/DeleteUnloadedForeignKeys.java index be4491759..fc6640bf2 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/persist/DeleteUnloadedForeignKeys.java +++ b/src/main/java/com/avaje/ebeaninternal/server/persist/DeleteUnloadedForeignKeys.java @@ -20,76 +20,76 @@ import com.avaje.ebeaninternal.server.transaction.DefaultPersistenceContext; * This bean effectively holds the foreign properties that where not loaded, and * helps fetch the foreign keys and delete the appropriate rows. *

- * + * * @author rbygrave */ public class DeleteUnloadedForeignKeys { - private final List> propList = new ArrayList>(4); - - private final SpiEbeanServer server; - - private final PersistRequestBean request; + private final List> propList = new ArrayList>(4); - private EntityBean beanWithForeignKeys; - - public DeleteUnloadedForeignKeys(SpiEbeanServer server, PersistRequestBean request) { - this.server = server; - this.request = request; - } - - public boolean isEmpty() { - return propList.isEmpty(); - } - - public void add(BeanPropertyAssocOne prop) { - propList.add(prop); + private final SpiEbeanServer server; + + private final PersistRequestBean request; + + private EntityBean beanWithForeignKeys; + + public DeleteUnloadedForeignKeys(SpiEbeanServer server, PersistRequestBean request) { + this.server = server; + this.request = request; + } + + public boolean isEmpty() { + return propList.isEmpty(); + } + + public void add(BeanPropertyAssocOne prop) { + propList.add(prop); + } + + /** + * Execute a query fetching the missing (unloaded) foreign keys. We need to + * fetch these key values before the parent bean is deleted. + */ + public void queryForeignKeys() { + + BeanDescriptor descriptor = request.getBeanDescriptor(); + SpiQuery q = (SpiQuery) server.createQuery(descriptor.getBeanType()); + + Object id = request.getBeanId(); + + StringBuilder sb = new StringBuilder(30); + for (int i = 0; i < propList.size(); i++) { + sb.append(propList.get(i).getName()).append(","); } - /** - * Execute a query fetching the missing (unloaded) foreign keys. We need to - * fetch these key values before the parent bean is deleted. - */ - public void queryForeignKeys() { + // run query in a separate persistence context + q.setPersistenceContext(new DefaultPersistenceContext()); + q.setPersistenceContextScope(PersistenceContextScope.QUERY); + q.setAutofetch(false); + q.select(sb.toString()); + q.where().idEq(id); - BeanDescriptor descriptor = request.getBeanDescriptor(); - SpiQuery q = (SpiQuery) server.createQuery(descriptor.getBeanType()); - - Object id = request.getBeanId(); - - StringBuilder sb = new StringBuilder(30); - for (int i = 0; i < propList.size(); i++) { - sb.append(propList.get(i).getName()).append(","); - } - - // run query in a separate persistence context - q.setPersistenceContext(new DefaultPersistenceContext()); - q.setPersistenceContextScope(PersistenceContextScope.QUERY); - q.setAutofetch(false); - q.select(sb.toString()); - q.where().idEq(id); - - SpiTransaction t = request.getTransaction(); - if (t.isLogSummary()) { - t.logSummary("-- Ebean fetching foreign key values for delete of " + descriptor.getName() + " id:" + id); - } - beanWithForeignKeys = (EntityBean)server.findUnique(q, t); + SpiTransaction t = request.getTransaction(); + if (t.isLogSummary()) { + t.logSummary("-- Ebean fetching foreign key values for delete of " + descriptor.getName() + " id:" + id); } + beanWithForeignKeys = (EntityBean) server.findUnique(q, t); + } - /** - * Delete the rows relating to the foreign keys. These deletions occur after - * the parent bean has been deleted. - */ - public void deleteCascade() { + /** + * Delete the rows relating to the foreign keys. These deletions occur after + * the parent bean has been deleted. + */ + public void deleteCascade() { - for (int i = 0; i < propList.size(); i++) { - BeanPropertyAssocOne prop = propList.get(i); - Object detailBean = prop.getValue(beanWithForeignKeys); + for (int i = 0; i < propList.size(); i++) { + BeanPropertyAssocOne prop = propList.get(i); + Object detailBean = prop.getValue(beanWithForeignKeys); - // if bean exists with a unique id then delete it - if (detailBean != null && prop.hasId((EntityBean)detailBean)) { - server.delete(detailBean, request.getTransaction()); - } - } + // if bean exists with a unique id then delete it + if (detailBean != null && prop.hasId((EntityBean) detailBean)) { + server.delete(detailBean, request.getTransaction()); + } } + } } diff --git a/src/main/java/com/avaje/ebeaninternal/server/persist/DmlUtil.java b/src/main/java/com/avaje/ebeaninternal/server/persist/DmlUtil.java index c1b74091b..92e99a3fe 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/persist/DmlUtil.java +++ b/src/main/java/com/avaje/ebeaninternal/server/persist/DmlUtil.java @@ -2,14 +2,14 @@ package com.avaje.ebeaninternal.server.persist; /** - * Utility object with helper methods for DML. + * Utility object with helper methods for DML. */ public class DmlUtil { - /** - * Return true if the value is null or a Numeric 0 (for primitive int's and long's) or Option empty. - */ - public static boolean isNullOrZero(Object value) { + /** + * Return true if the value is null or a Numeric 0 (for primitive int's and long's) or Option empty. + */ + public static boolean isNullOrZero(Object value) { return value == null || value instanceof Number && ((Number) value).longValue() == 0l; } } diff --git a/src/main/java/com/avaje/ebeaninternal/server/persist/PersistExecute.java b/src/main/java/com/avaje/ebeaninternal/server/persist/PersistExecute.java index 26807719f..6cc2e1fcc 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/persist/PersistExecute.java +++ b/src/main/java/com/avaje/ebeaninternal/server/persist/PersistExecute.java @@ -12,43 +12,42 @@ import com.avaje.ebeaninternal.server.core.PersistRequestUpdateSql; * A Persister 'front-ends' this object and handles the * batching, cascading, concurrency mode detection etc. *

- * */ public interface PersistExecute { - - /** - * Create a BatchControl for the current transaction. - */ - BatchControl createBatchControl(SpiTransaction t); - - /** - * Execute a Bean (or MapBean) insert. - */ - void executeInsertBean(PersistRequestBean request); - /** - * Execute a Bean (or MapBean) update. - */ - void executeUpdateBean(PersistRequestBean request); + /** + * Create a BatchControl for the current transaction. + */ + BatchControl createBatchControl(SpiTransaction t); - /** - * Execute a Bean (or MapBean) delete. - */ - void executeDeleteBean(PersistRequestBean request); + /** + * Execute a Bean (or MapBean) insert. + */ + void executeInsertBean(PersistRequestBean request); - /** - * Execute a Update. - */ - int executeOrmUpdate(PersistRequestOrmUpdate request); - - /** - * Execute a CallableSql. - */ - int executeSqlCallable(PersistRequestCallableSql request); + /** + * Execute a Bean (or MapBean) update. + */ + void executeUpdateBean(PersistRequestBean request); - /** - * Execute a UpdateSql. - */ - int executeSqlUpdate(PersistRequestUpdateSql request); + /** + * Execute a Bean (or MapBean) delete. + */ + void executeDeleteBean(PersistRequestBean request); + + /** + * Execute a Update. + */ + int executeOrmUpdate(PersistRequestOrmUpdate request); + + /** + * Execute a CallableSql. + */ + int executeSqlCallable(PersistRequestCallableSql request); + + /** + * Execute a UpdateSql. + */ + int executeSqlUpdate(PersistRequestUpdateSql request); } diff --git a/src/main/java/com/avaje/ebeaninternal/server/persist/PstmtFactory.java b/src/main/java/com/avaje/ebeaninternal/server/persist/PstmtFactory.java index ccbae3539..7131beb0a 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/persist/PstmtFactory.java +++ b/src/main/java/com/avaje/ebeaninternal/server/persist/PstmtFactory.java @@ -18,79 +18,79 @@ import com.avaje.ebeaninternal.server.core.PstmtBatch; public class PstmtFactory { - private final PstmtBatch pstmtBatch; - - public PstmtFactory(PstmtBatch pstmtBatch) { - this.pstmtBatch = pstmtBatch; - } - - /** - * Get a callable statement without any batching. - */ - public CallableStatement getCstmt(SpiTransaction t, String sql) throws SQLException { - Connection conn = t.getInternalConnection(); - return conn.prepareCall(sql); - } + private final PstmtBatch pstmtBatch; - /** - * Get a prepared statement without any batching. - */ - public PreparedStatement getPstmt(SpiTransaction t, String sql) throws SQLException { - Connection conn = t.getInternalConnection(); - return conn.prepareStatement(sql); - } + public PstmtFactory(PstmtBatch pstmtBatch) { + this.pstmtBatch = pstmtBatch; + } - /** - * Return a prepared statement taking into account batch requirements. - */ - public PreparedStatement getPstmt(SpiTransaction t, boolean logSql, String sql, BatchPostExecute batchExe) - throws SQLException { + /** + * Get a callable statement without any batching. + */ + public CallableStatement getCstmt(SpiTransaction t, String sql) throws SQLException { + Connection conn = t.getInternalConnection(); + return conn.prepareCall(sql); + } - BatchedPstmtHolder batch = t.getBatchControl().getPstmtHolder(); - PreparedStatement stmt = batch.getStmt(sql, batchExe); + /** + * Get a prepared statement without any batching. + */ + public PreparedStatement getPstmt(SpiTransaction t, String sql) throws SQLException { + Connection conn = t.getInternalConnection(); + return conn.prepareStatement(sql); + } - if (stmt != null) { - return stmt; - } + /** + * Return a prepared statement taking into account batch requirements. + */ + public PreparedStatement getPstmt(SpiTransaction t, boolean logSql, String sql, BatchPostExecute batchExe) + throws SQLException { - if (logSql){ - t.logSql(sql); - } - - Connection conn = t.getInternalConnection(); - stmt = conn.prepareStatement(sql); + BatchedPstmtHolder batch = t.getBatchControl().getPstmtHolder(); + PreparedStatement stmt = batch.getStmt(sql, batchExe); - if (pstmtBatch != null){ - pstmtBatch.setBatchSize(stmt, t.getBatchControl().getBatchSize()); - } - - BatchedPstmt bs = new BatchedPstmt(stmt, false, sql, pstmtBatch, false); - batch.addStmt(bs, batchExe); - return stmt; - } + if (stmt != null) { + return stmt; + } - /** - * Return a callable statement taking into account batch requirements. - */ - public CallableStatement getCstmt(SpiTransaction t, boolean logSql, String sql, BatchPostExecute batchExe) - throws SQLException { + if (logSql) { + t.logSql(sql); + } - BatchedPstmtHolder batch = t.getBatchControl().getPstmtHolder(); - CallableStatement stmt = (CallableStatement) batch.getStmt(sql, batchExe); + Connection conn = t.getInternalConnection(); + stmt = conn.prepareStatement(sql); - if (stmt != null) { - return stmt; - } - - if (logSql){ - t.logSql(sql); - } + if (pstmtBatch != null) { + pstmtBatch.setBatchSize(stmt, t.getBatchControl().getBatchSize()); + } - Connection conn = t.getInternalConnection(); - stmt = conn.prepareCall(sql); + BatchedPstmt bs = new BatchedPstmt(stmt, false, sql, pstmtBatch, false); + batch.addStmt(bs, batchExe); + return stmt; + } - BatchedPstmt bs = new BatchedPstmt(stmt, false, sql, pstmtBatch, false); - batch.addStmt(bs, batchExe); - return stmt; - } + /** + * Return a callable statement taking into account batch requirements. + */ + public CallableStatement getCstmt(SpiTransaction t, boolean logSql, String sql, BatchPostExecute batchExe) + throws SQLException { + + BatchedPstmtHolder batch = t.getBatchControl().getPstmtHolder(); + CallableStatement stmt = (CallableStatement) batch.getStmt(sql, batchExe); + + if (stmt != null) { + return stmt; + } + + if (logSql) { + t.logSql(sql); + } + + Connection conn = t.getInternalConnection(); + stmt = conn.prepareCall(sql); + + BatchedPstmt bs = new BatchedPstmt(stmt, false, sql, pstmtBatch, false); + batch.addStmt(bs, batchExe); + return stmt; + } }