public class NamedParameterJdbcTemplate extends Object implements NamedParameterJdbcOperations
This class delegates to a wrapped JdbcTemplate
once the substitution from named parameters to JDBC style '?' placeholders is
done at execution time. It also allows for expanding a List
of values to the appropriate number of placeholders.
The underlying JdbcTemplate
is
exposed to allow for convenient access to the traditional
JdbcTemplate
methods.
NOTE: An instance of this class is thread-safe once configured.
NamedParameterJdbcOperations
,
JdbcTemplate
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_CACHE_LIMIT
Default maximum number of entries for this template's SQL cache: 256.
|
Constructor and Description |
---|
NamedParameterJdbcTemplate(DataSource dataSource)
Create a new NamedParameterJdbcTemplate for the given
DataSource . |
NamedParameterJdbcTemplate(JdbcOperations classicJdbcTemplate)
Create a new NamedParameterJdbcTemplate for the given classic
Spring
JdbcTemplate . |
Modifier and Type | Method and Description |
---|---|
int[] |
batchUpdate(String sql,
Map<String,?>[] batchValues)
Executes a batch using the supplied SQL statement with the batch of supplied arguments.
|
int[] |
batchUpdate(String sql,
SqlParameterSource[] batchArgs)
Execute a batch using the supplied SQL statement with the batch of supplied arguments.
|
<T> T |
execute(String sql,
Map<String,?> paramMap,
PreparedStatementCallback<T> action)
Execute a JDBC data access operation, implemented as callback action
working on a JDBC PreparedStatement.
|
<T> T |
execute(String sql,
PreparedStatementCallback<T> action)
Execute a JDBC data access operation, implemented as callback action
working on a JDBC PreparedStatement.
|
<T> T |
execute(String sql,
SqlParameterSource paramSource,
PreparedStatementCallback<T> action)
Execute a JDBC data access operation, implemented as callback action
working on a JDBC PreparedStatement.
|
int |
getCacheLimit()
Return the maximum number of entries for this template's SQL cache.
|
JdbcOperations |
getJdbcOperations()
Expose the classic Spring JdbcTemplate operations to allow invocation
of less commonly used methods.
|
JdbcTemplate |
getJdbcTemplate()
Expose the classic Spring
JdbcTemplate itself, if available,
in particular for passing it on to other JdbcTemplate consumers. |
protected ParsedSql |
getParsedSql(String sql)
Obtain a parsed representation of the given SQL statement.
|
protected PreparedStatementCreator |
getPreparedStatementCreator(String sql,
SqlParameterSource paramSource)
Build a
PreparedStatementCreator based on the given SQL and named parameters. |
protected PreparedStatementCreator |
getPreparedStatementCreator(String sql,
SqlParameterSource paramSource,
Consumer<PreparedStatementCreatorFactory> customizer)
Build a
PreparedStatementCreator based on the given SQL and named parameters. |
protected PreparedStatementCreatorFactory |
getPreparedStatementCreatorFactory(ParsedSql parsedSql,
SqlParameterSource paramSource)
Build a
PreparedStatementCreatorFactory based on the given SQL and named parameters. |
<T> T |
query(String sql,
Map<String,?> paramMap,
ResultSetExtractor<T> rse)
Query given SQL to create a prepared statement from SQL and a list
of arguments to bind to the query, reading the ResultSet with a
ResultSetExtractor.
|
void |
query(String sql,
Map<String,?> paramMap,
RowCallbackHandler rch)
Query given SQL to create a prepared statement from SQL and a list of
arguments to bind to the query, reading the ResultSet on a per-row basis
with a RowCallbackHandler.
|
<T> List<T> |
query(String sql,
Map<String,?> paramMap,
RowMapper<T> rowMapper)
Query given SQL to create a prepared statement from SQL and a list
of arguments to bind to the query, mapping each row to a Java object
via a RowMapper.
|
<T> T |
query(String sql,
ResultSetExtractor<T> rse)
Query given SQL to create a prepared statement from SQL,
reading the ResultSet with a ResultSetExtractor.
|
void |
query(String sql,
RowCallbackHandler rch)
Query given SQL to create a prepared statement from SQL,
reading the ResultSet on a per-row basis with a RowCallbackHandler.
|
<T> List<T> |
query(String sql,
RowMapper<T> rowMapper)
Query given SQL to create a prepared statement from SQL,
mapping each row to a Java object via a RowMapper.
|
<T> T |
query(String sql,
SqlParameterSource paramSource,
ResultSetExtractor<T> rse)
Query given SQL to create a prepared statement from SQL and a list
of arguments to bind to the query, reading the ResultSet with a
ResultSetExtractor.
|
void |
query(String sql,
SqlParameterSource paramSource,
RowCallbackHandler rch)
Query given SQL to create a prepared statement from SQL and a list of
arguments to bind to the query, reading the ResultSet on a per-row basis
with a RowCallbackHandler.
|
<T> List<T> |
query(String sql,
SqlParameterSource paramSource,
RowMapper<T> rowMapper)
Query given SQL to create a prepared statement from SQL and a list
of arguments to bind to the query, mapping each row to a Java object
via a RowMapper.
|
List<Map<String,Object>> |
queryForList(String sql,
Map<String,?> paramMap)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result list.
|
<T> List<T> |
queryForList(String sql,
Map<String,?> paramMap,
Class<T> elementType)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result list.
|
List<Map<String,Object>> |
queryForList(String sql,
SqlParameterSource paramSource)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result list.
|
<T> List<T> |
queryForList(String sql,
SqlParameterSource paramSource,
Class<T> elementType)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result list.
|
Map<String,Object> |
queryForMap(String sql,
Map<String,?> paramMap)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result Map.
|
Map<String,Object> |
queryForMap(String sql,
SqlParameterSource paramSource)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result Map.
|
<T> T |
queryForObject(String sql,
Map<String,?> paramMap,
Class<T> requiredType)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result object.
|
<T> T |
queryForObject(String sql,
Map<String,?> paramMap,
RowMapper<T> rowMapper)
Query given SQL to create a prepared statement from SQL and a list
of arguments to bind to the query, mapping a single result row to a
Java object via a RowMapper.
|
<T> T |
queryForObject(String sql,
SqlParameterSource paramSource,
Class<T> requiredType)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a result object.
|
<T> T |
queryForObject(String sql,
SqlParameterSource paramSource,
RowMapper<T> rowMapper)
Query given SQL to create a prepared statement from SQL and a list
of arguments to bind to the query, mapping a single result row to a
Java object via a RowMapper.
|
SqlRowSet |
queryForRowSet(String sql,
Map<String,?> paramMap)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting an SqlRowSet.
|
SqlRowSet |
queryForRowSet(String sql,
SqlParameterSource paramSource)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting an SqlRowSet.
|
<T> Stream<T> |
queryForStream(String sql,
Map<String,?> paramMap,
RowMapper<T> rowMapper)
Query given SQL to create a prepared statement from SQL and a list
of arguments to bind to the query, mapping each row to a Java object
via a RowMapper, and turning it into an iterable and closeable Stream.
|
<T> Stream<T> |
queryForStream(String sql,
SqlParameterSource paramSource,
RowMapper<T> rowMapper)
Query given SQL to create a prepared statement from SQL and a list
of arguments to bind to the query, mapping each row to a Java object
via a RowMapper, and turning it into an iterable and closeable Stream.
|
void |
setCacheLimit(int cacheLimit)
Specify the maximum number of entries for this template's SQL cache.
|
int |
update(String sql,
Map<String,?> paramMap)
Issue an update via a prepared statement, binding the given arguments.
|
int |
update(String sql,
SqlParameterSource paramSource)
Issue an update via a prepared statement, binding the given arguments.
|
int |
update(String sql,
SqlParameterSource paramSource,
KeyHolder generatedKeyHolder)
Issue an update via a prepared statement, binding the given arguments,
returning generated keys.
|
int |
update(String sql,
SqlParameterSource paramSource,
KeyHolder generatedKeyHolder,
String[] keyColumnNames)
Issue an update via a prepared statement, binding the given arguments,
returning generated keys.
|
public static final int DEFAULT_CACHE_LIMIT
public NamedParameterJdbcTemplate(DataSource dataSource)
DataSource
.
Creates a classic Spring JdbcTemplate
and wraps it.
dataSource
- the JDBC DataSource to accesspublic NamedParameterJdbcTemplate(JdbcOperations classicJdbcTemplate)
JdbcTemplate
.classicJdbcTemplate
- the classic Spring JdbcTemplate to wrappublic JdbcOperations getJdbcOperations()
getJdbcOperations
in interface NamedParameterJdbcOperations
public JdbcTemplate getJdbcTemplate()
JdbcTemplate
itself, if available,
in particular for passing it on to other JdbcTemplate
consumers.
If sufficient for the purposes at hand, getJdbcOperations()
is recommended over this variant.
public void setCacheLimit(int cacheLimit)
public int getCacheLimit()
@Nullable public <T> T execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback<T> action) throws DataAccessException
NamedParameterJdbcOperations
The callback action can return a result object, for example a domain object or a collection of domain objects.
execute
in interface NamedParameterJdbcOperations
sql
- the SQL to executeparamSource
- container of arguments to bind to the queryaction
- callback object that specifies the actionnull
DataAccessException
- if there is any problem@Nullable public <T> T execute(String sql, Map<String,?> paramMap, PreparedStatementCallback<T> action) throws DataAccessException
NamedParameterJdbcOperations
The callback action can return a result object, for example a domain object or a collection of domain objects.
execute
in interface NamedParameterJdbcOperations
sql
- the SQL to executeparamMap
- map of parameters to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type)action
- callback object that specifies the actionnull
DataAccessException
- if there is any problem@Nullable public <T> T execute(String sql, PreparedStatementCallback<T> action) throws DataAccessException
NamedParameterJdbcOperations
The callback action can return a result object, for example a domain object or a collection of domain objects.
execute
in interface NamedParameterJdbcOperations
sql
- the SQL to executeaction
- callback object that specifies the actionnull
DataAccessException
- if there is any problem@Nullable public <T> T query(String sql, SqlParameterSource paramSource, ResultSetExtractor<T> rse) throws DataAccessException
NamedParameterJdbcOperations
query
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamSource
- container of arguments to bind to the queryrse
- object that will extract resultsDataAccessException
- if the query fails@Nullable public <T> T query(String sql, Map<String,?> paramMap, ResultSetExtractor<T> rse) throws DataAccessException
NamedParameterJdbcOperations
query
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamMap
- map of parameters to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type)rse
- object that will extract resultsDataAccessException
- if the query fails@Nullable public <T> T query(String sql, ResultSetExtractor<T> rse) throws DataAccessException
NamedParameterJdbcOperations
Note: In contrast to the JdbcOperations method with the same signature, this query variant always uses a PreparedStatement. It is effectively equivalent to a query call with an empty parameter Map.
query
in interface NamedParameterJdbcOperations
sql
- the SQL query to executerse
- object that will extract resultsDataAccessException
- if the query failspublic void query(String sql, SqlParameterSource paramSource, RowCallbackHandler rch) throws DataAccessException
NamedParameterJdbcOperations
query
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamSource
- container of arguments to bind to the queryrch
- object that will extract results, one row at a timeDataAccessException
- if the query failspublic void query(String sql, Map<String,?> paramMap, RowCallbackHandler rch) throws DataAccessException
NamedParameterJdbcOperations
query
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamMap
- map of parameters to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type)rch
- object that will extract results, one row at a timeDataAccessException
- if the query failspublic void query(String sql, RowCallbackHandler rch) throws DataAccessException
NamedParameterJdbcOperations
Note: In contrast to the JdbcOperations method with the same signature, this query variant always uses a PreparedStatement. It is effectively equivalent to a query call with an empty parameter Map.
query
in interface NamedParameterJdbcOperations
sql
- the SQL query to executerch
- object that will extract results, one row at a timeDataAccessException
- if the query failspublic <T> List<T> query(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper) throws DataAccessException
NamedParameterJdbcOperations
query
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamSource
- container of arguments to bind to the queryrowMapper
- object that will map one object per rowDataAccessException
- if the query failspublic <T> List<T> query(String sql, Map<String,?> paramMap, RowMapper<T> rowMapper) throws DataAccessException
NamedParameterJdbcOperations
query
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamMap
- map of parameters to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type)rowMapper
- object that will map one object per rowDataAccessException
- if the query failspublic <T> List<T> query(String sql, RowMapper<T> rowMapper) throws DataAccessException
NamedParameterJdbcOperations
Note: In contrast to the JdbcOperations method with the same signature, this query variant always uses a PreparedStatement. It is effectively equivalent to a query call with an empty parameter Map.
query
in interface NamedParameterJdbcOperations
sql
- the SQL query to executerowMapper
- object that will map one object per rowDataAccessException
- if the query failspublic <T> Stream<T> queryForStream(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper) throws DataAccessException
NamedParameterJdbcOperations
queryForStream
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamSource
- container of arguments to bind to the queryrowMapper
- object that will map one object per rowDataAccessException
- if the query failspublic <T> Stream<T> queryForStream(String sql, Map<String,?> paramMap, RowMapper<T> rowMapper) throws DataAccessException
NamedParameterJdbcOperations
queryForStream
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamMap
- map of parameters to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type)rowMapper
- object that will map one object per rowDataAccessException
- if the query fails@Nullable public <T> T queryForObject(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper) throws DataAccessException
NamedParameterJdbcOperations
queryForObject
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamSource
- container of arguments to bind to the queryrowMapper
- object that will map one object per rownull
if the given
RowMapper
returned null)IncorrectResultSizeDataAccessException
- if the query does not return exactly one rowDataAccessException
- if the query fails@Nullable public <T> T queryForObject(String sql, Map<String,?> paramMap, RowMapper<T> rowMapper) throws DataAccessException
NamedParameterJdbcOperations
queryForObject
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamMap
- map of parameters to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type)rowMapper
- object that will map one object per rownull
if the given
RowMapper
returned null)IncorrectResultSizeDataAccessException
- if the query does not return exactly one rowDataAccessException
- if the query fails@Nullable public <T> T queryForObject(String sql, SqlParameterSource paramSource, Class<T> requiredType) throws DataAccessException
NamedParameterJdbcOperations
The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.
queryForObject
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamSource
- container of arguments to bind to the queryrequiredType
- the type that the result object is expected to matchnull
in case of SQL NULLIncorrectResultSizeDataAccessException
- if the query does not return exactly one rowIncorrectResultSetColumnCountException
- if the query does not return a row containing a single columnDataAccessException
- if the query failsJdbcTemplate.queryForObject(String, Class)
,
SingleColumnRowMapper
@Nullable public <T> T queryForObject(String sql, Map<String,?> paramMap, Class<T> requiredType) throws DataAccessException
NamedParameterJdbcOperations
The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.
queryForObject
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamMap
- map of parameters to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type)requiredType
- the type that the result object is expected to matchnull
in case of SQL NULLIncorrectResultSizeDataAccessException
- if the query does not return exactly one rowIncorrectResultSetColumnCountException
- if the query does not return a row containing a single columnDataAccessException
- if the query failsJdbcTemplate.queryForObject(String, Class)
public Map<String,Object> queryForMap(String sql, SqlParameterSource paramSource) throws DataAccessException
NamedParameterJdbcOperations
The query is expected to be a single row query; the result row will be mapped to a Map (one entry for each column, using the column name as the key).
queryForMap
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamSource
- container of arguments to bind to the queryIncorrectResultSizeDataAccessException
- if the query does not return exactly one rowDataAccessException
- if the query failsJdbcTemplate.queryForMap(String)
,
ColumnMapRowMapper
public Map<String,Object> queryForMap(String sql, Map<String,?> paramMap) throws DataAccessException
NamedParameterJdbcOperations
The query is expected to be a single row query; the result row will be mapped to a Map (one entry for each column, using the column name as the key).
queryForMap
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamMap
- map of parameters to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type)IncorrectResultSizeDataAccessException
- if the query does not return exactly one rowDataAccessException
- if the query failsJdbcTemplate.queryForMap(String)
,
ColumnMapRowMapper
public <T> List<T> queryForList(String sql, SqlParameterSource paramSource, Class<T> elementType) throws DataAccessException
NamedParameterJdbcOperations
The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.
queryForList
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamSource
- container of arguments to bind to the queryelementType
- the required type of element in the result list
(for example, Integer.class
)DataAccessException
- if the query failsJdbcTemplate.queryForList(String, Class)
,
SingleColumnRowMapper
public <T> List<T> queryForList(String sql, Map<String,?> paramMap, Class<T> elementType) throws DataAccessException
NamedParameterJdbcOperations
The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.
queryForList
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamMap
- map of parameters to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type)elementType
- the required type of element in the result list
(for example, Integer.class
)DataAccessException
- if the query failsJdbcTemplate.queryForList(String, Class)
,
SingleColumnRowMapper
public List<Map<String,Object>> queryForList(String sql, SqlParameterSource paramSource) throws DataAccessException
NamedParameterJdbcOperations
The results will be mapped to a List (one entry for each row) of
Maps (one entry for each column, using the column name as the key).
Each element in the list will be of the form returned by this interface's
queryForMap
methods.
queryForList
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamSource
- container of arguments to bind to the queryDataAccessException
- if the query failsJdbcTemplate.queryForList(String)
public List<Map<String,Object>> queryForList(String sql, Map<String,?> paramMap) throws DataAccessException
NamedParameterJdbcOperations
The results will be mapped to a List (one entry for each row) of
Maps (one entry for each column, using the column name as the key).
Each element in the list will be of the form returned by this interface's
queryForMap
methods.
queryForList
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamMap
- map of parameters to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type)DataAccessException
- if the query failsJdbcTemplate.queryForList(String)
public SqlRowSet queryForRowSet(String sql, SqlParameterSource paramSource) throws DataAccessException
NamedParameterJdbcOperations
The results will be mapped to an SqlRowSet which holds the data in a disconnected fashion. This wrapper will translate any SQLExceptions thrown.
Note that, for the default implementation, JDBC RowSet support needs to
be available at runtime: by default, Sun's com.sun.rowset.CachedRowSetImpl
class is used, which is part of JDK 1.5+ and also available separately as part of
Sun's JDBC RowSet Implementations download (rowset.jar).
queryForRowSet
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamSource
- container of arguments to bind to the queryjavax.sql.rowset.CachedRowSet
)DataAccessException
- if there is any problem executing the queryJdbcTemplate.queryForRowSet(String)
,
SqlRowSetResultSetExtractor
,
CachedRowSet
public SqlRowSet queryForRowSet(String sql, Map<String,?> paramMap) throws DataAccessException
NamedParameterJdbcOperations
The results will be mapped to an SqlRowSet which holds the data in a disconnected fashion. This wrapper will translate any SQLExceptions thrown.
Note that, for the default implementation, JDBC RowSet support needs to
be available at runtime: by default, Sun's com.sun.rowset.CachedRowSetImpl
class is used, which is part of JDK 1.5+ and also available separately as part of
Sun's JDBC RowSet Implementations download (rowset.jar).
queryForRowSet
in interface NamedParameterJdbcOperations
sql
- the SQL query to executeparamMap
- map of parameters to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type)javax.sql.rowset.CachedRowSet
)DataAccessException
- if there is any problem executing the queryJdbcTemplate.queryForRowSet(String)
,
SqlRowSetResultSetExtractor
,
CachedRowSet
public int update(String sql, SqlParameterSource paramSource) throws DataAccessException
NamedParameterJdbcOperations
update
in interface NamedParameterJdbcOperations
sql
- the SQL containing named parametersparamSource
- container of arguments and SQL types to bind to the queryDataAccessException
- if there is any problem issuing the updatepublic int update(String sql, Map<String,?> paramMap) throws DataAccessException
NamedParameterJdbcOperations
update
in interface NamedParameterJdbcOperations
sql
- the SQL containing named parametersparamMap
- map of parameters to bind to the query
(leaving it to the PreparedStatement to guess the corresponding SQL type)DataAccessException
- if there is any problem issuing the updatepublic int update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder) throws DataAccessException
NamedParameterJdbcOperations
update
in interface NamedParameterJdbcOperations
sql
- the SQL containing named parametersparamSource
- container of arguments and SQL types to bind to the querygeneratedKeyHolder
- a KeyHolder
that will hold the generated keysDataAccessException
- if there is any problem issuing the updateMapSqlParameterSource
,
GeneratedKeyHolder
public int update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, @Nullable String[] keyColumnNames) throws DataAccessException
NamedParameterJdbcOperations
update
in interface NamedParameterJdbcOperations
sql
- the SQL containing named parametersparamSource
- container of arguments and SQL types to bind to the querygeneratedKeyHolder
- a KeyHolder
that will hold the generated keyskeyColumnNames
- names of the columns that will have keys generated for themDataAccessException
- if there is any problem issuing the updateMapSqlParameterSource
,
GeneratedKeyHolder
public int[] batchUpdate(String sql, Map<String,?>[] batchValues)
NamedParameterJdbcOperations
batchUpdate
in interface NamedParameterJdbcOperations
sql
- the SQL statement to executebatchValues
- the array of Maps containing the batch of arguments for the queryStatement.SUCCESS_NO_INFO
/Statement.EXECUTE_FAILED
)public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs)
NamedParameterJdbcOperations
batchUpdate
in interface NamedParameterJdbcOperations
sql
- the SQL statement to executebatchArgs
- the array of SqlParameterSource
containing the batch of
arguments for the queryStatement.SUCCESS_NO_INFO
/Statement.EXECUTE_FAILED
)protected PreparedStatementCreator getPreparedStatementCreator(String sql, SqlParameterSource paramSource)
PreparedStatementCreator
based on the given SQL and named parameters.
Note: Directly called from all query
variants. Delegates to the common
getPreparedStatementCreator(String, SqlParameterSource, Consumer)
method.
sql
- the SQL statement to executeparamSource
- container of arguments to bindPreparedStatementCreator
getPreparedStatementCreator(String, SqlParameterSource, Consumer)
protected PreparedStatementCreator getPreparedStatementCreator(String sql, SqlParameterSource paramSource, @Nullable Consumer<PreparedStatementCreatorFactory> customizer)
PreparedStatementCreator
based on the given SQL and named parameters.
Note: Used for the update
variant with generated key handling, and also
delegated from getPreparedStatementCreator(String, SqlParameterSource)
.
sql
- the SQL statement to executeparamSource
- container of arguments to bindcustomizer
- callback for setting further properties on the
PreparedStatementCreatorFactory
in use), applied before the
actual newPreparedStatementCreator
callPreparedStatementCreator
getParsedSql(String)
,
PreparedStatementCreatorFactory(String, List)
,
PreparedStatementCreatorFactory.newPreparedStatementCreator(Object[])
protected ParsedSql getParsedSql(String sql)
The default implementation uses an LRU cache with an upper limit of 256 entries.
sql
- the original SQL statementprotected PreparedStatementCreatorFactory getPreparedStatementCreatorFactory(ParsedSql parsedSql, SqlParameterSource paramSource)
PreparedStatementCreatorFactory
based on the given SQL and named parameters.parsedSql
- parsed representation of the given SQL statementparamSource
- container of arguments to bindPreparedStatementCreatorFactory
getPreparedStatementCreator(String, SqlParameterSource, Consumer)
,
getParsedSql(String)