类 AbstractJdbcInsert
- java.lang.Object
- org.springframework.jdbc.core.simple.AbstractJdbcInsert
- 直接已知子类:
SimpleJdbcInsert
public abstract class AbstractJdbcInsert extends Object
Abstract class to provide base functionality for easy inserts based on configuration options and database meta-data.This class provides the base SPI for
SimpleJdbcInsert
.- 从以下版本开始:
- 2.5
- 作者:
- Thomas Risberg, Juergen Hoeller
构造器概要
构造器 限定符 构造器 说明 protected
AbstractJdbcInsert(DataSource dataSource)
Constructor to be used when initializing using aDataSource
.protected
AbstractJdbcInsert(JdbcTemplate jdbcTemplate)
Constructor to be used when initializing using aJdbcTemplate
.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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 allowed 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()
Delegate method to perform the actual compilation.protected int
doExecute(Map<String,?> args)
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-inSqlParameterSource
s.String
getCatalogName()
Get the name of the catalog for this insert.List<String>
getColumnNames()
Get the names of the columns used.String[]
getGeneratedKeyNames()
Get the names of any generated keys.String
getInsertString()
Get the insert string to be used.int[]
getInsertTypes()
Get the array ofTypes
to be used for insert.JdbcTemplate
getJdbcTemplate()
Get the configuredJdbcTemplate
.String
getSchemaName()
Get the name of the schema for this insert.String
getTableName()
Get the name of the table for this insert.boolean
isCompiled()
Is this operation "compiled"?protected List<Object>
matchInParameterValuesWithInsertColumns(Map<String,?> args)
Match the provided in parameter values with registered parameters and parameters defined via meta-data processing.protected List<Object>
matchInParameterValuesWithInsertColumns(SqlParameterSource parameterSource)
Match the provided in parameter values with registered parameters and parameters defined via meta-data processing.protected void
onCompileInternal()
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
setNativeJdbcExtractor(NativeJdbcExtractor nativeJdbcExtractor)
Set theNativeJdbcExtractor
to use to retrieve the native connection if necessaryvoid
setOverrideIncludeSynonymsDefault(boolean override)
Specify whether the default for including synonyms should be changed.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.
构造器详细资料
AbstractJdbcInsert
protected AbstractJdbcInsert(DataSource dataSource)
Constructor to be used when initializing using aDataSource
.- 参数:
dataSource
- the DataSource to be used
AbstractJdbcInsert
protected AbstractJdbcInsert(JdbcTemplate jdbcTemplate)
Constructor to be used when initializing using aJdbcTemplate
.- 参数:
jdbcTemplate
- the JdbcTemplate to use
方法详细资料
getJdbcTemplate
public JdbcTemplate getJdbcTemplate()
Get the configuredJdbcTemplate
.
setTableName
public void setTableName(String tableName)
Set the name of the table for this insert.
getTableName
public String getTableName()
Get the name of the table for this insert.
setSchemaName
public void setSchemaName(String schemaName)
Set the name of the schema for this insert.
getSchemaName
public String getSchemaName()
Get the name of the schema for this insert.
setCatalogName
public void setCatalogName(String catalogName)
Set the name of the catalog for this insert.
getCatalogName
public String getCatalogName()
Get the name of the catalog for this insert.
setColumnNames
public void setColumnNames(List<String> columnNames)
Set the names of the columns to be used.
getColumnNames
public List<String> getColumnNames()
Get the names of the columns used.
setGeneratedKeyName
public void setGeneratedKeyName(String generatedKeyName)
Specify the name of a single generated key column.
setGeneratedKeyNames
public void setGeneratedKeyNames(String... generatedKeyNames)
Set the names of any generated keys.
getGeneratedKeyNames
public String[] 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 istrue
.
setOverrideIncludeSynonymsDefault
public void setOverrideIncludeSynonymsDefault(boolean override)
Specify whether the default for including synonyms should be changed. The default isfalse
.
setNativeJdbcExtractor
public void setNativeJdbcExtractor(NativeJdbcExtractor nativeJdbcExtractor)
Set theNativeJdbcExtractor
to use to retrieve the native connection if necessary
getInsertString
public String getInsertString()
Get the insert string to be used.
getInsertTypes
public int[] getInsertTypes()
Get the array ofTypes
to be used for insert.
compile
public final void compile() throws InvalidDataAccessApiUsageException
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.- 抛出:
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"?- 返回:
- 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
validateParameters
.
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
protected int doExecute(Map<String,?> args)
Delegate method that executes the insert using the passed-in Map of parameters.- 参数:
args
- Map with parameter names and values to be used in insert- 返回:
- the number of rows affected
doExecute
protected int doExecute(SqlParameterSource parameterSource)
Delegate method that executes the insert using the passed-inSqlParameterSource
.- 参数:
parameterSource
- parameter names and values to be used in insert- 返回:
- the number of rows affected
doExecuteAndReturnKey
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.- 参数:
args
- Map with parameter names and values to be used in insert- 返回:
- the key generated by the insert
doExecuteAndReturnKey
protected Number doExecuteAndReturnKey(SqlParameterSource parameterSource)
Method that provides execution of the insert using the passed-inSqlParameterSource
and returning a generated key.- 参数:
parameterSource
- parameter names and values to be used in insert- 返回:
- the key generated by the insert
doExecuteAndReturnKeyHolder
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.- 参数:
args
- Map with parameter names and values to be used in insert- 返回:
- the KeyHolder containing keys generated by the insert
doExecuteAndReturnKeyHolder
protected KeyHolder doExecuteAndReturnKeyHolder(SqlParameterSource parameterSource)
Method that provides execution of the insert using the passed-inSqlParameterSource
and returning all generated keys.- 参数:
parameterSource
- parameter names and values to be used in insert- 返回:
- the KeyHolder containing keys generated by the insert
doExecuteBatch
protected int[] doExecuteBatch(Map<String,?>... batch)
Delegate method that executes a batch insert using the passed-in Maps of parameters.- 参数:
batch
- array of Maps with parameter names and values to be used in batch insert- 返回:
- array of number of rows affected
doExecuteBatch
protected int[] doExecuteBatch(SqlParameterSource... batch)
Delegate method that executes a batch insert using the passed-inSqlParameterSource
s.- 参数:
batch
- array of SqlParameterSource with parameter names and values to be used in insert- 返回:
- array of number of rows affected
matchInParameterValuesWithInsertColumns
protected List<Object> matchInParameterValuesWithInsertColumns(SqlParameterSource parameterSource)
Match the provided in parameter values with registered parameters and parameters defined via meta-data processing.- 参数:
parameterSource
- the parameter values provided as aSqlParameterSource
- 返回:
- Map with parameter names and values
matchInParameterValuesWithInsertColumns
protected List<Object> matchInParameterValuesWithInsertColumns(Map<String,?> args)
Match the provided in parameter values with registered parameters and parameters defined via meta-data processing.- 参数:
args
- the parameter values provided in a Map- 返回:
- Map with parameter names and values