Class AbstractJdbcInsert
java.lang.Object
org.springframework.jdbc.core.simple.AbstractJdbcInsert
- Direct Known Subclasses:
SimpleJdbcInsert
Abstract class to provide base functionality for easy (batch) inserts
based on configuration options and database meta-data.
This class provides the processing arrangement for SimpleJdbcInsert
.
- Since:
- 2.5
- Author:
- Thomas Risberg, Juergen Hoeller, Sam Brannen
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractJdbcInsert
(DataSource dataSource) Constructor to be used when initializing using aDataSource
.protected
AbstractJdbcInsert
(JdbcTemplate jdbcTemplate) Constructor to be used when initializing using aJdbcTemplate
. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Check whether this operation has been compiled already; lazily compile it if not already compiled.protected void
Method to check whether we are allowed to make any configuration changes at this time.final void
compile()
Compile this JdbcInsert using provided parameters and meta-data plus other settings.protected void
Delegate method to perform the actual compilation.protected int
Delegate method that executes the insert using the passed-in Map of parameters.protected int
doExecute
(SqlParameterSource parameterSource) Delegate method that executes the insert using the passed-inSqlParameterSource
.protected Number
doExecuteAndReturnKey
(Map<String, ?> args) Method that provides execution of the insert using the passed-in Map of parameters and returning a generated key.protected Number
doExecuteAndReturnKey
(SqlParameterSource parameterSource) Method that provides execution of the insert using the passed-inSqlParameterSource
and returning a generated key.protected KeyHolder
doExecuteAndReturnKeyHolder
(Map<String, ?> 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-inSqlParameterSource
and returning all generated keys.protected int[]
doExecuteBatch
(Map<String, ?>... batch) Delegate method that executes a batch insert using the passed-in Maps of parameters.protected int[]
doExecuteBatch
(SqlParameterSource... batch) Delegate method that executes a batch insert using the passed-inSqlParameterSources
.Get the name of the catalog for this insert.Get the names of the columns used.String[]
Get the names of any generated keys.Get the insert string to be used.int[]
Get the array ofTypes
to be used for insert.Get the configuredJdbcTemplate
.Get the name of the schema for this insert.Get the name of the table for this insert.boolean
Is this operation "compiled"?boolean
Get thequoteIdentifiers
flag.Match the provided in parameter values with registered parameters and parameters defined via meta-data processing.matchInParameterValuesWithInsertColumns
(SqlParameterSource parameterSource) Match the provided in parameter values with registered parameters and parameters defined via meta-data processing.protected void
Hook method that subclasses may override to react to compilation.void
setAccessTableColumnMetaData
(boolean accessTableColumnMetaData) Specify whether the parameter meta-data for the call should be used.void
setCatalogName
(String catalogName) Set the name of the catalog for this insert.void
setColumnNames
(List<String> columnNames) Set the names of the columns to be used.void
setGeneratedKeyName
(String generatedKeyName) Specify the name of a single generated key column.void
setGeneratedKeyNames
(String... generatedKeyNames) Set the names of any generated keys.void
setOverrideIncludeSynonymsDefault
(boolean override) Specify whether the default for including synonyms should be changed.void
setQuoteIdentifiers
(boolean quoteIdentifiers) Specify whether SQL identifiers should be quoted.void
setSchemaName
(String schemaName) Set the name of the schema for this insert.void
setTableName
(String tableName) Set the name of the table for this insert.
-
Field Details
-
logger
Logger available to subclasses.
-
-
Constructor Details
-
AbstractJdbcInsert
Constructor to be used when initializing using aDataSource
.- Parameters:
dataSource
- theDataSource
to be used
-
AbstractJdbcInsert
Constructor to be used when initializing using aJdbcTemplate
.- Parameters:
jdbcTemplate
- theJdbcTemplate
to use
-
-
Method Details
-
getJdbcTemplate
Get the configuredJdbcTemplate
. -
setTableName
Set the name of the table for this insert. -
getTableName
Get the name of the table for this insert. -
setSchemaName
Set the name of the schema for this insert. -
getSchemaName
Get the name of the schema for this insert. -
setCatalogName
Set the name of the catalog for this insert. -
getCatalogName
Get the name of the catalog for this insert. -
setColumnNames
Set the names of the columns to be used. -
getColumnNames
Get the names of the columns used. -
setGeneratedKeyName
Specify the name of a single generated key column. -
setGeneratedKeyNames
Set the names of any generated keys. -
getGeneratedKeyNames
Get the names of any generated keys. -
setAccessTableColumnMetaData
public void setAccessTableColumnMetaData(boolean accessTableColumnMetaData) Specify whether the parameter meta-data for the call should be used.The default is
true
. -
setOverrideIncludeSynonymsDefault
public void setOverrideIncludeSynonymsDefault(boolean override) Specify whether the default for including synonyms should be changed.The default is
false
. -
getInsertString
Get the insert string to be used. -
getInsertTypes
public int[] getInsertTypes()Get the array ofTypes
to be used for insert. -
setQuoteIdentifiers
public void setQuoteIdentifiers(boolean quoteIdentifiers) Specify whether SQL identifiers should be quoted.Defaults to
false
. If set totrue
, the identifier quote string for the underlying database will be used to quote SQL identifiers in generated SQL statements.- Parameters:
quoteIdentifiers
- whether identifiers should be quoted- Since:
- 6.1
- See Also:
-
isQuoteIdentifiers
public boolean isQuoteIdentifiers()Get thequoteIdentifiers
flag.- Since:
- 6.1
- See Also:
-
compile
Compile this JdbcInsert using provided parameters and meta-data plus other settings. This finalizes the configuration for this object and subsequent attempts to compile are ignored. This will be implicitly called the first time an un-compiled insert is executed.- Throws:
InvalidDataAccessApiUsageException
- if the object hasn't been correctly initialized, for example if no DataSource has been provided
-
compileInternal
protected void compileInternal()Delegate 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.
-
onCompileInternal
protected void onCompileInternal()Hook method that subclasses may override to react to compilation.This implementation is empty.
-
isCompiled
public boolean isCompiled()Is this operation "compiled"?- Returns:
- whether this operation is compiled and ready to use
-
checkCompiled
protected void checkCompiled()Check whether this operation has been compiled already; lazily compile it if not already compiled.Automatically called by all
doExecute*(...)
methods. -
checkIfConfigurationModificationIsAllowed
protected void checkIfConfigurationModificationIsAllowed()Method to check whether we are allowed to make any configuration changes at this time.If the class has been compiled, then no further changes to the configuration are allowed.
-
doExecute
Delegate method that executes the insert using the passed-in Map of parameters.- Parameters:
args
- a Map with parameter names and values to be used in insert- Returns:
- the number of rows affected
-
doExecute
Delegate method that executes the insert using the passed-inSqlParameterSource
.- Parameters:
parameterSource
- parameter names and values to be used in insert- Returns:
- the number of rows affected
-
doExecuteAndReturnKey
Method that provides execution of the insert using the passed-in Map of parameters and returning a generated key.- Parameters:
args
- a Map with parameter names and values to be used in insert- Returns:
- the key generated by the insert
-
doExecuteAndReturnKey
Method that provides execution of the insert using the passed-inSqlParameterSource
and returning a generated key.- Parameters:
parameterSource
- parameter names and values to be used in insert- Returns:
- the key generated by the insert
-
doExecuteAndReturnKeyHolder
Method that provides execution of the insert using the passed-in Map of parameters and returning all generated keys.- Parameters:
args
- a Map with parameter names and values to be used in insert- Returns:
- the KeyHolder containing keys generated by the insert
-
doExecuteAndReturnKeyHolder
Method that provides execution of the insert using the passed-inSqlParameterSource
and returning all generated keys.- Parameters:
parameterSource
- parameter names and values to be used in insert- Returns:
- the KeyHolder containing keys generated by the insert
-
doExecuteBatch
Delegate method that executes a batch insert using the passed-in Maps of parameters.- Parameters:
batch
- maps with parameter names and values to be used in the batch insert- Returns:
- an array of number of rows affected
-
doExecuteBatch
Delegate method that executes a batch insert using the passed-inSqlParameterSources
.- Parameters:
batch
- parameter sources with names and values to be used in the batch insert- Returns:
- an array of number of rows affected
-
matchInParameterValuesWithInsertColumns
Match the provided in parameter values with registered parameters and parameters defined via meta-data processing.- Parameters:
parameterSource
- the parameter values provided as aSqlParameterSource
- Returns:
- a List of values
-
matchInParameterValuesWithInsertColumns
Match the provided in parameter values with registered parameters and parameters defined via meta-data processing.- Parameters:
args
- the parameter values provided as a Map- Returns:
- a List of values
-