From b88db7a594e86721f247dc89ee83732e35e6032c Mon Sep 17 00:00:00 2001 From: Thomas Risberg Date: Thu, 12 Nov 2009 19:39:39 +0000 Subject: [PATCH] extracted creation of new ArgPreparedStatementSetter and ArgTypePreparedStatementSetter into protected methods to allow sub-classes to override (SPR-3977) --- .../jdbc/core/JdbcTemplate.java | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java index 869f540941..df14692e35 100644 --- a/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java +++ b/org.springframework.jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java @@ -666,11 +666,11 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } public T query(String sql, Object[] args, int[] argTypes, ResultSetExtractor rse) throws DataAccessException { - return query(sql, new ArgTypePreparedStatementSetter(args, argTypes), rse); + return query(sql, newArgTypePreparedStatementSetter(args, argTypes), rse); } public T query(String sql, Object[] args, ResultSetExtractor rse) throws DataAccessException { - return query(sql, new ArgPreparedStatementSetter(args), rse); + return query(sql, newArgPreparedStatementSetter(args), rse); } public void query(PreparedStatementCreator psc, RowCallbackHandler rch) throws DataAccessException { @@ -682,11 +682,11 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } public void query(String sql, Object[] args, int[] argTypes, RowCallbackHandler rch) throws DataAccessException { - query(sql, new ArgTypePreparedStatementSetter(args, argTypes), rch); + query(sql, newArgTypePreparedStatementSetter(args, argTypes), rch); } public void query(String sql, Object[] args, RowCallbackHandler rch) throws DataAccessException { - query(sql, new ArgPreparedStatementSetter(args), rch); + query(sql, newArgPreparedStatementSetter(args), rch); } public List query(PreparedStatementCreator psc, RowMapper rowMapper) throws DataAccessException { @@ -843,11 +843,11 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } public int update(String sql, Object[] args, int[] argTypes) throws DataAccessException { - return update(sql, new ArgTypePreparedStatementSetter(args, argTypes)); + return update(sql, newArgTypePreparedStatementSetter(args, argTypes)); } public int update(String sql, Object... args) throws DataAccessException { - return update(sql, new ArgPreparedStatementSetter(args)); + return update(sql, newArgPreparedStatementSetter(args)); } public int[] batchUpdate(String sql, final BatchPreparedStatementSetter pss) throws DataAccessException { @@ -1232,6 +1232,28 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } } + /** + * Create a new ArgPreparedStatementSetter using the args passed in. This method allows the + * creation to be overridden by sub-classes. + * @param args object array woth arguments + * @return the new ArgPreparedStatementSetter + */ + protected ArgPreparedStatementSetter newArgPreparedStatementSetter(Object[] args) { + return new ArgPreparedStatementSetter(args); + } + + /** + * Create a new ArgTypePreparedStatementSetter using the args and argTypes passed in. + * This method allows the creation to be overridden by sub-classes. + * @param args object array woth arguments + * @param argTypes int array of SQLTypes for arguments + * @return the new ArgTypePreparedStatementSetter + */ + protected ArgTypePreparedStatementSetter newArgTypePreparedStatementSetter(Object[] args, int[] argTypes) { + return new ArgTypePreparedStatementSetter(args, argTypes); + } + + /** * Determine SQL from potential provider object. * @param sqlProvider object that's potentially a SqlProvider