public interface NamedParameterJdbcOperations
This is an alternative to the classic
JdbcOperations
interface,
implemented by NamedParameterJdbcTemplate
. This interface is not
often used directly, but provides a useful option to enhance testability,
as it can easily be mocked or stubbed.
NamedParameterJdbcTemplate
,
JdbcOperations
Modifier and Type | Method and Description |
---|---|
int[] |
batchUpdate(java.lang.String sql,
java.util.Map<java.lang.String,?>[] batchValues)
Executes a batch using the supplied SQL statement with the batch of supplied arguments.
|
int[] |
batchUpdate(java.lang.String sql,
SqlParameterSource[] batchArgs)
Execute a batch using the supplied SQL statement with the batch of supplied arguments.
|
<T> T |
execute(java.lang.String sql,
java.util.Map<java.lang.String,?> paramMap,
PreparedStatementCallback<T> action)
Execute a JDBC data access operation, implemented as callback action
working on a JDBC PreparedStatement.
|
<T> T |
execute(java.lang.String sql,
PreparedStatementCallback<T> action)
Execute a JDBC data access operation, implemented as callback action
working on a JDBC PreparedStatement.
|
<T> T |
execute(java.lang.String sql,
SqlParameterSource paramSource,
PreparedStatementCallback<T> action)
Execute a JDBC data access operation, implemented as callback action
working on a JDBC PreparedStatement.
|
JdbcOperations |
getJdbcOperations()
Expose the classic Spring JdbcTemplate to allow invocation of
classic JDBC operations.
|
<T> T |
query(java.lang.String sql,
java.util.Map<java.lang.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(java.lang.String sql,
java.util.Map<java.lang.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> java.util.List<T> |
query(java.lang.String sql,
java.util.Map<java.lang.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(java.lang.String sql,
ResultSetExtractor<T> rse)
Query given SQL to create a prepared statement from SQL,
reading the ResultSet with a ResultSetExtractor.
|
void |
query(java.lang.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> java.util.List<T> |
query(java.lang.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(java.lang.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(java.lang.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> java.util.List<T> |
query(java.lang.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.
|
int |
queryForInt(java.lang.String sql,
java.util.Map<java.lang.String,?> paramMap)
Deprecated.
in favor of
queryForObject(String, Map, Class) |
int |
queryForInt(java.lang.String sql,
SqlParameterSource paramSource)
Deprecated.
|
java.util.List<java.util.Map<java.lang.String,java.lang.Object>> |
queryForList(java.lang.String sql,
java.util.Map<java.lang.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> java.util.List<T> |
queryForList(java.lang.String sql,
java.util.Map<java.lang.String,?> paramMap,
java.lang.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.
|
java.util.List<java.util.Map<java.lang.String,java.lang.Object>> |
queryForList(java.lang.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> java.util.List<T> |
queryForList(java.lang.String sql,
SqlParameterSource paramSource,
java.lang.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.
|
long |
queryForLong(java.lang.String sql,
java.util.Map<java.lang.String,?> paramMap)
Deprecated.
in favor of
queryForObject(String, Map, Class) |
long |
queryForLong(java.lang.String sql,
SqlParameterSource paramSource)
Deprecated.
|
java.util.Map<java.lang.String,java.lang.Object> |
queryForMap(java.lang.String sql,
java.util.Map<java.lang.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.
|
java.util.Map<java.lang.String,java.lang.Object> |
queryForMap(java.lang.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(java.lang.String sql,
java.util.Map<java.lang.String,?> paramMap,
java.lang.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(java.lang.String sql,
java.util.Map<java.lang.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(java.lang.String sql,
SqlParameterSource paramSource,
java.lang.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(java.lang.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(java.lang.String sql,
java.util.Map<java.lang.String,?> paramMap)
Query given SQL to create a prepared statement from SQL and a
list of arguments to bind to the query, expecting a SqlRowSet.
|
SqlRowSet |
queryForRowSet(java.lang.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 SqlRowSet.
|
int |
update(java.lang.String sql,
java.util.Map<java.lang.String,?> paramMap)
Issue an update via a prepared statement, binding the given arguments.
|
int |
update(java.lang.String sql,
SqlParameterSource paramSource)
Issue an update via a prepared statement, binding the given arguments.
|
int |
update(java.lang.String sql,
SqlParameterSource paramSource,
KeyHolder generatedKeyHolder)
Issue an update via a prepared statement, binding the given arguments,
returning generated keys.
|
int |
update(java.lang.String sql,
SqlParameterSource paramSource,
KeyHolder generatedKeyHolder,
java.lang.String[] keyColumnNames)
Issue an update via a prepared statement, binding the given arguments,
returning generated keys.
|
JdbcOperations getJdbcOperations()
<T> T execute(java.lang.String sql, SqlParameterSource paramSource, PreparedStatementCallback<T> action) throws DataAccessException
The callback action can return a result object, for example a domain object or a collection of domain objects.
sql
- SQL to executeparamSource
- container of arguments to bind to the queryaction
- callback object that specifies the actionnull
DataAccessException
- if there is any problem<T> T execute(java.lang.String sql, java.util.Map<java.lang.String,?> paramMap, PreparedStatementCallback<T> action) throws DataAccessException
The callback action can return a result object, for example a domain object or a collection of domain objects.
sql
- 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<T> T execute(java.lang.String sql, PreparedStatementCallback<T> action) throws DataAccessException
The callback action can return a result object, for example a domain object or a collection of domain objects.
sql
- SQL to executeaction
- callback object that specifies the actionnull
DataAccessException
- if there is any problem<T> T query(java.lang.String sql, SqlParameterSource paramSource, ResultSetExtractor<T> rse) throws DataAccessException
sql
- SQL query to executeparamSource
- container of arguments to bind to the queryrse
- object that will extract resultsDataAccessException
- if the query fails<T> T query(java.lang.String sql, java.util.Map<java.lang.String,?> paramMap, ResultSetExtractor<T> rse) throws DataAccessException
sql
- 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<T> T query(java.lang.String sql, ResultSetExtractor<T> rse) throws DataAccessException
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.
sql
- SQL query to executerse
- object that will extract resultsDataAccessException
- if the query failsvoid query(java.lang.String sql, SqlParameterSource paramSource, RowCallbackHandler rch) throws DataAccessException
sql
- 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 failsvoid query(java.lang.String sql, java.util.Map<java.lang.String,?> paramMap, RowCallbackHandler rch) throws DataAccessException
sql
- 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 failsvoid query(java.lang.String sql, RowCallbackHandler rch) throws DataAccessException
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.
sql
- SQL query to executerch
- object that will extract results, one row at a timeDataAccessException
- if the query fails<T> java.util.List<T> query(java.lang.String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper) throws DataAccessException
sql
- SQL query to executeparamSource
- container of arguments to bind to the queryrowMapper
- object that will map one object per rowDataAccessException
- if the query fails<T> java.util.List<T> query(java.lang.String sql, java.util.Map<java.lang.String,?> paramMap, RowMapper<T> rowMapper) throws DataAccessException
sql
- 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<T> java.util.List<T> query(java.lang.String sql, RowMapper<T> rowMapper) throws DataAccessException
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.
sql
- SQL query to executerowMapper
- object that will map one object per rowDataAccessException
- if the query fails<T> T queryForObject(java.lang.String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper) throws DataAccessException
sql
- SQL query to executeparamSource
- container of arguments to bind to the queryrowMapper
- object that will map one object per rowIncorrectResultSizeDataAccessException
- if the query does not return exactly one row, or does not return exactly
one column in that rowDataAccessException
- if the query fails<T> T queryForObject(java.lang.String sql, java.util.Map<java.lang.String,?> paramMap, RowMapper<T> rowMapper) throws DataAccessException
sql
- 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 rowIncorrectResultSizeDataAccessException
- if the query does not return exactly one row, or does not return exactly
one column in that rowDataAccessException
- if the query fails<T> T queryForObject(java.lang.String sql, SqlParameterSource paramSource, java.lang.Class<T> requiredType) throws DataAccessException
The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.
sql
- 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 row, or does not return exactly
one column in that rowDataAccessException
- if the query failsJdbcTemplate.queryForObject(String, Class)
<T> T queryForObject(java.lang.String sql, java.util.Map<java.lang.String,?> paramMap, java.lang.Class<T> requiredType) throws DataAccessException
The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.
sql
- 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 row, or does not return exactly
one column in that rowDataAccessException
- if the query failsJdbcTemplate.queryForObject(String, Class)
java.util.Map<java.lang.String,java.lang.Object> queryForMap(java.lang.String sql, SqlParameterSource paramSource) throws DataAccessException
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).
sql
- 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
java.util.Map<java.lang.String,java.lang.Object> queryForMap(java.lang.String sql, java.util.Map<java.lang.String,?> paramMap) throws DataAccessException
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).
sql
- 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
@Deprecated long queryForLong(java.lang.String sql, SqlParameterSource paramSource) throws DataAccessException
queryForObject(String, SqlParameterSource, Class)
The query is expected to be a single row/single column query that results in a long value.
sql
- SQL query to executeparamSource
- container of arguments to bind to the queryIncorrectResultSizeDataAccessException
- if the query does not return exactly one row, or does not return exactly
one column in that rowDataAccessException
- if the query failsJdbcTemplate.queryForLong(String)
@Deprecated long queryForLong(java.lang.String sql, java.util.Map<java.lang.String,?> paramMap) throws DataAccessException
queryForObject(String, Map, Class)
The query is expected to be a single row/single column query that results in a long value.
sql
- 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 row, or does not return exactly
one column in that rowDataAccessException
- if the query failsJdbcTemplate.queryForLong(String)
@Deprecated int queryForInt(java.lang.String sql, SqlParameterSource paramSource) throws DataAccessException
queryForObject(String, SqlParameterSource, Class)
The query is expected to be a single row/single column query that results in an int value.
sql
- SQL query to executeparamSource
- container of arguments to bind to the queryIncorrectResultSizeDataAccessException
- if the query does not return
exactly one row, or does not return exactly one column in that rowDataAccessException
- if the query failsJdbcTemplate.queryForInt(String)
@Deprecated int queryForInt(java.lang.String sql, java.util.Map<java.lang.String,?> paramMap) throws DataAccessException
queryForObject(String, Map, Class)
The query is expected to be a single row/single column query that results in an int value.
sql
- 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 row, or does not return exactly one column in that rowDataAccessException
- if the query failsJdbcTemplate.queryForInt(String)
<T> java.util.List<T> queryForList(java.lang.String sql, SqlParameterSource paramSource, java.lang.Class<T> elementType) throws DataAccessException
The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.
sql
- 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
<T> java.util.List<T> queryForList(java.lang.String sql, java.util.Map<java.lang.String,?> paramMap, java.lang.Class<T> elementType) throws DataAccessException
The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.
sql
- 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
java.util.List<java.util.Map<java.lang.String,java.lang.Object>> queryForList(java.lang.String sql, SqlParameterSource paramSource) throws DataAccessException
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.
sql
- SQL query to executeparamSource
- container of arguments to bind to the queryDataAccessException
- if the query failsJdbcTemplate.queryForList(String)
java.util.List<java.util.Map<java.lang.String,java.lang.Object>> queryForList(java.lang.String sql, java.util.Map<java.lang.String,?> paramMap) throws DataAccessException
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.
sql
- 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)
SqlRowSet queryForRowSet(java.lang.String sql, SqlParameterSource paramSource) throws DataAccessException
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 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).
sql
- 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
SqlRowSet queryForRowSet(java.lang.String sql, java.util.Map<java.lang.String,?> paramMap) throws DataAccessException
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 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).
sql
- 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
int update(java.lang.String sql, SqlParameterSource paramSource) throws DataAccessException
sql
- SQL containing named parametersparamSource
- container of arguments and SQL types to bind to the queryDataAccessException
- if there is any problem issuing the updateint update(java.lang.String sql, java.util.Map<java.lang.String,?> paramMap) throws DataAccessException
sql
- 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 updateint update(java.lang.String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder) throws DataAccessException
sql
- SQL containing named parametersparamSource
- container of arguments and SQL types to bind to the querygeneratedKeyHolder
- KeyHolder that will hold the generated keysDataAccessException
- if there is any problem issuing the updateMapSqlParameterSource
,
GeneratedKeyHolder
int update(java.lang.String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, java.lang.String[] keyColumnNames) throws DataAccessException
sql
- SQL containing named parametersparamSource
- container of arguments and SQL types to bind to the querygeneratedKeyHolder
- 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
int[] batchUpdate(java.lang.String sql, java.util.Map<java.lang.String,?>[] batchValues)
sql
- the SQL statement to executebatchValues
- the array of Maps containing the batch of arguments for the queryint[] batchUpdate(java.lang.String sql, SqlParameterSource[] batchArgs)
sql
- the SQL statement to executebatchArgs
- the array of SqlParameterSource
containing the batch of arguments for the query