public abstract class AbstractJdbcInsert
extends java.lang.Object
SimpleJdbcInsert
.Modifier and Type | Field and Description |
---|---|
private boolean |
compiled
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.
|
private java.util.List<java.lang.String> |
declaredColumns
List of columns objects to be used in insert statement
|
private java.lang.String[] |
generatedKeyNames
The names of the columns holding the generated key
|
private java.lang.String |
insertString
The generated string used for insert statement
|
private int[] |
insertTypes
The SQL type information for the insert columns
|
private JdbcTemplate |
jdbcTemplate
Lower-level class used to execute SQL
|
protected Log |
logger
Logger available to subclasses
|
private TableMetaDataContext |
tableMetaDataContext
Context used to retrieve and manage database metadata
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractJdbcInsert(javax.sql.DataSource dataSource)
Constructor for sublasses to delegate to for setting the DataSource.
|
protected |
AbstractJdbcInsert(JdbcTemplate jdbcTemplate)
Constructor for sublasses to delegate to for setting the JdbcTemplate.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkCompiled()
Check whether this operation has been compiled already;
lazily compile it if not already compiled.
|
protected void |
checkIfConfigurationModificationIsAllowed()
Method to check whether we are allowd to make any configuration changes at this time.
|
void |
compile()
Compile this JdbcInsert using provided parameters and meta data plus other settings.
|
protected void |
compileInternal()
Method to perform the actual compilation.
|
protected int |
doExecute(java.util.Map<java.lang.String,java.lang.Object> args)
Method that provides execution of the insert using the passed in Map of parameters
|
protected int |
doExecute(SqlParameterSource parameterSource)
Method that provides execution of the insert using the passed in
SqlParameterSource |
protected java.lang.Number |
doExecuteAndReturnKey(java.util.Map<java.lang.String,java.lang.Object> args)
Method that provides execution of the insert using the passed in Map of parameters
and returning a generated key
|
protected java.lang.Number |
doExecuteAndReturnKey(SqlParameterSource parameterSource)
Method that provides execution of the insert using the passed in
SqlParameterSource
and returning a generated key |
protected KeyHolder |
doExecuteAndReturnKeyHolder(java.util.Map<java.lang.String,java.lang.Object> args)
Method that provides execution of the insert using the passed in Map of parameters
and returning all generated keys
|
protected KeyHolder |
doExecuteAndReturnKeyHolder(SqlParameterSource parameterSource)
Method that provides execution of the insert using the passed in
SqlParameterSource
and returning all generated keys |
protected int[] |
doExecuteBatch(java.util.Map<java.lang.String,java.lang.Object>[] batch)
Method that provides execution of a batch insert using the passed in Maps of parameters.
|
protected int[] |
doExecuteBatch(SqlParameterSource[] batch)
Method that provides execution of a batch insert using the passed in array of
SqlParameterSource |
private int[] |
executeBatchInternal(java.util.List<java.lang.Object>[] batchValues)
Method to execute the batch insert.
|
private KeyHolder |
executeInsertAndReturnKeyHolderInternal(java.util.List<java.lang.Object> values)
Method to execute the insert generating any number of keys
|
private java.lang.Number |
executeInsertAndReturnKeyInternal(java.util.List<java.lang.Object> values)
Method to execute the insert generating single key
|
private int |
executeInsertInternal(java.util.List<java.lang.Object> values)
Method to execute the insert.
|
java.lang.String |
getCatalogName()
Get the name of the catalog for this insert
|
java.util.List<java.lang.String> |
getColumnNames()
Get the names of the columns used
|
java.lang.String[] |
getGeneratedKeyNames()
Get the names of any generated keys
|
java.lang.String |
getInsertString()
Get the insert string to be used
|
int[] |
getInsertTypes()
Get the array of
Types to be used for insert |
JdbcTemplate |
getJdbcTemplate()
Get the
JdbcTemplate that is configured to be used. |
java.lang.String |
getSchemaName()
Get the name of the schema for this insert
|
java.lang.String |
getTableName()
Get the name of the table for this insert
|
boolean |
isCompiled()
Is this operation "compiled"?
|
protected java.util.List<java.lang.Object> |
matchInParameterValuesWithInsertColumns(java.util.Map<java.lang.String,java.lang.Object> args)
Match the provided in parameter values with regitered parameters and parameters defined
via metadata processing.
|
protected java.util.List<java.lang.Object> |
matchInParameterValuesWithInsertColumns(SqlParameterSource parameterSource)
Match the provided in parameter values with regitered parameters and parameters defined
via metadata processing.
|
protected void |
onCompileInternal()
Hook method that subclasses may override to react to compilation.
|
private java.sql.PreparedStatement |
prepareStatementForGeneratedKeys(java.sql.Connection con)
Create the PreparedStatement to be used for insert that have generated keys
|
void |
setAccessTableColumnMetaData(boolean accessTableColumnMetaData)
Specify whether the parameter metadata for the call should be used.
|
void |
setCatalogName(java.lang.String catalogName)
Set the name of the catalog for this insert
|
void |
setColumnNames(java.util.List<java.lang.String> columnNames)
Set the names of the columns to be used
|
void |
setGeneratedKeyName(java.lang.String generatedKeyName)
Specify the name of a single generated key column
|
void |
setGeneratedKeyNames(java.lang.String[] generatedKeyNames)
Set the names of any generated keys
|
void |
setNativeJdbcExtractor(NativeJdbcExtractor nativeJdbcExtractor)
Set the
NativeJdbcExtractor to use to retrieve the native connection if necessary |
void |
setOverrideIncludeSynonymsDefault(boolean override)
Specify whether the default for including synonyms should be changed.
|
private void |
setParameterValues(java.sql.PreparedStatement preparedStatement,
java.util.List<java.lang.Object> values,
int[] columnTypes)
Internal implementation for setting parameter values
|
void |
setSchemaName(java.lang.String schemaName)
Set the name of the schema for this insert
|
void |
setTableName(java.lang.String tableName)
Set the name of the table for this insert
|
protected final Log logger
private final JdbcTemplate jdbcTemplate
private final TableMetaDataContext tableMetaDataContext
private final java.util.List<java.lang.String> declaredColumns
private boolean compiled
private java.lang.String insertString
private int[] insertTypes
private java.lang.String[] generatedKeyNames
protected AbstractJdbcInsert(javax.sql.DataSource dataSource)
protected AbstractJdbcInsert(JdbcTemplate jdbcTemplate)
public JdbcTemplate getJdbcTemplate()
JdbcTemplate
that is configured to be used.public void setTableName(java.lang.String tableName)
public java.lang.String getTableName()
public void setSchemaName(java.lang.String schemaName)
public java.lang.String getSchemaName()
public void setCatalogName(java.lang.String catalogName)
public java.lang.String getCatalogName()
public void setColumnNames(java.util.List<java.lang.String> columnNames)
public java.util.List<java.lang.String> getColumnNames()
public java.lang.String[] getGeneratedKeyNames()
public void setGeneratedKeyNames(java.lang.String[] generatedKeyNames)
public void setGeneratedKeyName(java.lang.String generatedKeyName)
public void setAccessTableColumnMetaData(boolean accessTableColumnMetaData)
public void setOverrideIncludeSynonymsDefault(boolean override)
public void setNativeJdbcExtractor(NativeJdbcExtractor nativeJdbcExtractor)
NativeJdbcExtractor
to use to retrieve the native connection if necessarypublic java.lang.String getInsertString()
public int[] getInsertTypes()
Types
to be used for insertpublic final void compile() throws InvalidDataAccessApiUsageException
InvalidDataAccessApiUsageException
- if the object hasn't been correctly initialized,
for example if no DataSource has been providedprotected void compileInternal()
protected void onCompileInternal()
public boolean isCompiled()
protected void checkCompiled()
Automatically called by validateParameters
.
protected void checkIfConfigurationModificationIsAllowed()
protected int doExecute(java.util.Map<java.lang.String,java.lang.Object> args)
args
- Map with parameter names and values to be used in insertprotected int doExecute(SqlParameterSource parameterSource)
SqlParameterSource
parameterSource
- parameter names and values to be used in insertprivate int executeInsertInternal(java.util.List<java.lang.Object> values)
protected java.lang.Number doExecuteAndReturnKey(java.util.Map<java.lang.String,java.lang.Object> args)
args
- Map with parameter names and values to be used in insertprotected java.lang.Number doExecuteAndReturnKey(SqlParameterSource parameterSource)
SqlParameterSource
and returning a generated keyparameterSource
- parameter names and values to be used in insertprotected KeyHolder doExecuteAndReturnKeyHolder(java.util.Map<java.lang.String,java.lang.Object> args)
args
- Map with parameter names and values to be used in insertprotected KeyHolder doExecuteAndReturnKeyHolder(SqlParameterSource parameterSource)
SqlParameterSource
and returning all generated keysparameterSource
- parameter names and values to be used in insertprivate java.lang.Number executeInsertAndReturnKeyInternal(java.util.List<java.lang.Object> values)
private KeyHolder executeInsertAndReturnKeyHolderInternal(java.util.List<java.lang.Object> values)
private java.sql.PreparedStatement prepareStatementForGeneratedKeys(java.sql.Connection con) throws java.sql.SQLException
con
- the connection usedjava.sql.SQLException
protected int[] doExecuteBatch(java.util.Map<java.lang.String,java.lang.Object>[] batch)
batch
- array of Maps with parameter names and values to be used in batch insertprotected int[] doExecuteBatch(SqlParameterSource[] batch)
SqlParameterSource
batch
- array of SqlParameterSource with parameter names and values to be used in insertprivate int[] executeBatchInternal(java.util.List<java.lang.Object>[] batchValues)
private void setParameterValues(java.sql.PreparedStatement preparedStatement, java.util.List<java.lang.Object> values, int[] columnTypes) throws java.sql.SQLException
preparedStatement
- the PreparedStatementvalues
- the values to be setjava.sql.SQLException
protected java.util.List<java.lang.Object> matchInParameterValuesWithInsertColumns(SqlParameterSource parameterSource)
parameterSource
- the parameter vakues provided as a SqlParameterSource
protected java.util.List<java.lang.Object> matchInParameterValuesWithInsertColumns(java.util.Map<java.lang.String,java.lang.Object> args)
args
- the parameter values provided in a Map