|
|
|
|
@ -78,8 +78,7 @@ public abstract class AbstractJdbcInsert {
@@ -78,8 +78,7 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Has this operation been compiled? Compilation means at least checking |
|
|
|
|
* that a DataSource or JdbcTemplate has been provided, but subclasses |
|
|
|
|
* may also implement their own custom validation. |
|
|
|
|
* that a DataSource or JdbcTemplate has been provided. |
|
|
|
|
*/ |
|
|
|
|
private boolean compiled = false; |
|
|
|
|
|
|
|
|
|
@ -91,14 +90,16 @@ public abstract class AbstractJdbcInsert {
@@ -91,14 +90,16 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Constructor for sublasses to delegate to for setting the DataSource. |
|
|
|
|
* Constructor to be used when initializing using a {@link DataSource}. |
|
|
|
|
* @param dataSource the DataSource to be used |
|
|
|
|
*/ |
|
|
|
|
protected AbstractJdbcInsert(DataSource dataSource) { |
|
|
|
|
this.jdbcTemplate = new JdbcTemplate(dataSource); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Constructor for sublasses to delegate to for setting the JdbcTemplate. |
|
|
|
|
* Constructor to be used when initializing using a {@link JdbcTemplate}. |
|
|
|
|
* @param jdbcTemplate the JdbcTemplate to use |
|
|
|
|
*/ |
|
|
|
|
protected AbstractJdbcInsert(JdbcTemplate jdbcTemplate) { |
|
|
|
|
Assert.notNull(jdbcTemplate, "JdbcTemplate must not be null"); |
|
|
|
|
@ -112,7 +113,7 @@ public abstract class AbstractJdbcInsert {
@@ -112,7 +113,7 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get the {@link JdbcTemplate} that is configured to be used. |
|
|
|
|
* Get the configured {@link JdbcTemplate}. |
|
|
|
|
*/ |
|
|
|
|
public JdbcTemplate getJdbcTemplate() { |
|
|
|
|
return this.jdbcTemplate; |
|
|
|
|
@ -271,8 +272,9 @@ public abstract class AbstractJdbcInsert {
@@ -271,8 +272,9 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Method to perform the actual compilation. Subclasses can override this template method |
|
|
|
|
* to perform their own compilation. Invoked after this base class's compilation is complete. |
|
|
|
|
* Delegate method to perform the actual compilation. |
|
|
|
|
* <p>Subclasses can override this template method to perform their own compilation. |
|
|
|
|
* Invoked after this base class's compilation is complete. |
|
|
|
|
*/ |
|
|
|
|
protected void compileInternal() { |
|
|
|
|
this.tableMetaDataContext.processMetaData( |
|
|
|
|
@ -287,7 +289,7 @@ public abstract class AbstractJdbcInsert {
@@ -287,7 +289,7 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Hook method that subclasses may override to react to compilation. |
|
|
|
|
* This implementation does nothing. |
|
|
|
|
* <p>This implementation is empty. |
|
|
|
|
*/ |
|
|
|
|
protected void onCompileInternal() { |
|
|
|
|
} |
|
|
|
|
@ -329,9 +331,9 @@ public abstract class AbstractJdbcInsert {
@@ -329,9 +331,9 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Method that provides execution of the insert using the passed in Map of parameters |
|
|
|
|
* Delegate method that executes the insert using the passed-in Map of parameters. |
|
|
|
|
* @param args Map with parameter names and values to be used in insert |
|
|
|
|
* @return number of rows affected |
|
|
|
|
* @return the number of rows affected |
|
|
|
|
*/ |
|
|
|
|
protected int doExecute(Map<String, Object> args) { |
|
|
|
|
checkCompiled(); |
|
|
|
|
@ -340,9 +342,9 @@ public abstract class AbstractJdbcInsert {
@@ -340,9 +342,9 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Method that provides execution of the insert using the passed in {@link SqlParameterSource} |
|
|
|
|
* Delegate method that executes the insert using the passed-in {@link SqlParameterSource}. |
|
|
|
|
* @param parameterSource parameter names and values to be used in insert |
|
|
|
|
* @return number of rows affected |
|
|
|
|
* @return the number of rows affected |
|
|
|
|
*/ |
|
|
|
|
protected int doExecute(SqlParameterSource parameterSource) { |
|
|
|
|
checkCompiled(); |
|
|
|
|
@ -351,7 +353,7 @@ public abstract class AbstractJdbcInsert {
@@ -351,7 +353,7 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Method to execute the insert. |
|
|
|
|
* Delegate method to execute the insert. |
|
|
|
|
*/ |
|
|
|
|
private int executeInsertInternal(List<Object> values) { |
|
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
|
@ -361,9 +363,8 @@ public abstract class AbstractJdbcInsert {
@@ -361,9 +363,8 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Method that provides execution of the insert using the passed in Map of parameters |
|
|
|
|
* and returning a generated key |
|
|
|
|
* |
|
|
|
|
* Method that provides execution of the insert using the passed-in |
|
|
|
|
* Map of parameters and returning a generated key. |
|
|
|
|
* @param args Map with parameter names and values to be used in insert |
|
|
|
|
* @return the key generated by the insert |
|
|
|
|
*/ |
|
|
|
|
@ -374,9 +375,8 @@ public abstract class AbstractJdbcInsert {
@@ -374,9 +375,8 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Method that provides execution of the insert using the passed in {@link SqlParameterSource} |
|
|
|
|
* and returning a generated key |
|
|
|
|
* |
|
|
|
|
* Method that provides execution of the insert using the passed-in |
|
|
|
|
* {@link SqlParameterSource} and returning a generated key. |
|
|
|
|
* @param parameterSource parameter names and values to be used in insert |
|
|
|
|
* @return the key generated by the insert |
|
|
|
|
*/ |
|
|
|
|
@ -387,9 +387,8 @@ public abstract class AbstractJdbcInsert {
@@ -387,9 +387,8 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Method that provides execution of the insert using the passed in Map of parameters |
|
|
|
|
* and returning all generated keys |
|
|
|
|
* |
|
|
|
|
* Method that provides execution of the insert using the passed-in |
|
|
|
|
* Map of parameters and returning all generated keys. |
|
|
|
|
* @param args Map with parameter names and values to be used in insert |
|
|
|
|
* @return the KeyHolder containing keys generated by the insert |
|
|
|
|
*/ |
|
|
|
|
@ -400,9 +399,8 @@ public abstract class AbstractJdbcInsert {
@@ -400,9 +399,8 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Method that provides execution of the insert using the passed in {@link SqlParameterSource} |
|
|
|
|
* and returning all generated keys |
|
|
|
|
* |
|
|
|
|
* Method that provides execution of the insert using the passed-in |
|
|
|
|
* {@link SqlParameterSource} and returning all generated keys. |
|
|
|
|
* @param parameterSource parameter names and values to be used in insert |
|
|
|
|
* @return the KeyHolder containing keys generated by the insert |
|
|
|
|
*/ |
|
|
|
|
@ -413,7 +411,7 @@ public abstract class AbstractJdbcInsert {
@@ -413,7 +411,7 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Method to execute the insert generating single key |
|
|
|
|
* Delegate method to execute the insert, generating a single key. |
|
|
|
|
*/ |
|
|
|
|
private Number executeInsertAndReturnKeyInternal(final List<Object> values) { |
|
|
|
|
KeyHolder kh = executeInsertAndReturnKeyHolderInternal(values); |
|
|
|
|
@ -427,7 +425,7 @@ public abstract class AbstractJdbcInsert {
@@ -427,7 +425,7 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Method to execute the insert generating any number of keys |
|
|
|
|
* Delegate method to execute the insert, generating any number of keys. |
|
|
|
|
*/ |
|
|
|
|
private KeyHolder executeInsertAndReturnKeyHolderInternal(final List<Object> values) { |
|
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
|
@ -512,16 +510,14 @@ public abstract class AbstractJdbcInsert {
@@ -512,16 +510,14 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create the PreparedStatement to be used for insert that have generated keys |
|
|
|
|
* |
|
|
|
|
* @param con the connection used |
|
|
|
|
* @return PreparedStatement to use |
|
|
|
|
* @throws SQLException |
|
|
|
|
* Create a PreparedStatement to be used for an insert operation with generated keys. |
|
|
|
|
* @param con the Connection to use |
|
|
|
|
* @return the PreparedStatement |
|
|
|
|
*/ |
|
|
|
|
private PreparedStatement prepareStatementForGeneratedKeys(Connection con) throws SQLException { |
|
|
|
|
if (getGeneratedKeyNames().length < 1) { |
|
|
|
|
throw new InvalidDataAccessApiUsageException("Generated Key Name(s) not specificed. " + |
|
|
|
|
"Using the generated keys features requires specifying the name(s) of the generated column(s)"); |
|
|
|
|
throw new InvalidDataAccessApiUsageException("Generated Key Name(s) not specified. " + |
|
|
|
|
"Using the generated keys features requires specifying the name(s) of the generated column(s)."); |
|
|
|
|
} |
|
|
|
|
PreparedStatement ps; |
|
|
|
|
if (this.tableMetaDataContext.isGeneratedKeysColumnNameArraySupported()) { |
|
|
|
|
@ -540,11 +536,11 @@ public abstract class AbstractJdbcInsert {
@@ -540,11 +536,11 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Method that provides execution of a batch insert using the passed in Maps of parameters. |
|
|
|
|
* Delegate method that executes a batch insert using the passed-in Maps of parameters. |
|
|
|
|
* @param batch array of Maps with parameter names and values to be used in batch insert |
|
|
|
|
* @return array of number of rows affected |
|
|
|
|
*/ |
|
|
|
|
@SuppressWarnings({ "unchecked", "rawtypes" }) |
|
|
|
|
@SuppressWarnings({"unchecked", "rawtypes"}) |
|
|
|
|
protected int[] doExecuteBatch(Map<String, Object>[] batch) { |
|
|
|
|
checkCompiled(); |
|
|
|
|
List[] batchValues = new ArrayList[batch.length]; |
|
|
|
|
@ -557,11 +553,11 @@ public abstract class AbstractJdbcInsert {
@@ -557,11 +553,11 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Method that provides execution of a batch insert using the passed in array of {@link SqlParameterSource} |
|
|
|
|
* Delegate method that executes a batch insert using the passed-in {@link SqlParameterSource}s. |
|
|
|
|
* @param batch array of SqlParameterSource with parameter names and values to be used in insert |
|
|
|
|
* @return array of number of rows affected |
|
|
|
|
*/ |
|
|
|
|
@SuppressWarnings({ "unchecked", "rawtypes" }) |
|
|
|
|
@SuppressWarnings({"unchecked", "rawtypes"}) |
|
|
|
|
protected int[] doExecuteBatch(SqlParameterSource[] batch) { |
|
|
|
|
checkCompiled(); |
|
|
|
|
List[] batchValues = new ArrayList[batch.length]; |
|
|
|
|
@ -574,7 +570,7 @@ public abstract class AbstractJdbcInsert {
@@ -574,7 +570,7 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Method to execute the batch insert. |
|
|
|
|
* Delegate method to execute the batch insert. |
|
|
|
|
*/ |
|
|
|
|
private int[] executeBatchInternal(final List<Object>[] batchValues) { |
|
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
|
@ -613,8 +609,8 @@ public abstract class AbstractJdbcInsert {
@@ -613,8 +609,8 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Match the provided in parameter values with registered parameters and parameters defined |
|
|
|
|
* via metadata processing. |
|
|
|
|
* Match the provided in parameter values with registered parameters and parameters |
|
|
|
|
* defined via metadata processing. |
|
|
|
|
* @param parameterSource the parameter values provided as a {@link SqlParameterSource} |
|
|
|
|
* @return Map with parameter names and values |
|
|
|
|
*/ |
|
|
|
|
@ -623,8 +619,8 @@ public abstract class AbstractJdbcInsert {
@@ -623,8 +619,8 @@ public abstract class AbstractJdbcInsert {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Match the provided in parameter values with regitered parameters and parameters defined |
|
|
|
|
* via metadata processing. |
|
|
|
|
* Match the provided in parameter values with registered parameters and parameters |
|
|
|
|
* defined via metadata processing. |
|
|
|
|
* @param args the parameter values provided in a Map |
|
|
|
|
* @return Map with parameter names and values |
|
|
|
|
*/ |
|
|
|
|
|