public class SqlUpdate extends SqlOperation
This class provides a number of update
methods,
analogous to the execute
methods of query objects.
This class is concrete. Although it can be subclassed (for example to add a custom update method) it can easily be parameterized by setting SQL and declaring parameters.
Like all RdbmsOperation
classes that ship with the Spring
Framework, SqlQuery
instances are thread-safe after their
initialization is complete. That is, after they are constructed and configured
via their setter methods, they can be used safely from multiple threads.
SqlQuery
logger
Constructor and Description |
---|
SqlUpdate()
Constructor to allow use as a JavaBean.
|
SqlUpdate(javax.sql.DataSource ds,
java.lang.String sql)
Constructs an update object with a given DataSource and SQL.
|
SqlUpdate(javax.sql.DataSource ds,
java.lang.String sql,
int[] types)
Construct an update object with a given DataSource, SQL
and anonymous parameters.
|
SqlUpdate(javax.sql.DataSource ds,
java.lang.String sql,
int[] types,
int maxRowsAffected)
Construct an update object with a given DataSource, SQL,
anonymous parameters and specifying the maximum number of rows
that may be affected.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkRowsAffected(int rowsAffected)
Check the given number of affected rows against the
specified maximum number or required number.
|
void |
setMaxRowsAffected(int maxRowsAffected)
Set the maximum number of rows that may be affected by this update.
|
void |
setRequiredRowsAffected(int requiredRowsAffected)
Set the exact number of rows that must be affected by this update.
|
int |
update()
Convenience method to execute an update with no parameters.
|
int |
update(int p1)
Convenient method to execute an update given one int arg.
|
int |
update(int p1,
int p2)
Convenient method to execute an update given two int args.
|
int |
update(long p1)
Convenient method to execute an update given one long arg.
|
int |
update(long p1,
long p2)
Convenient method to execute an update given two long args.
|
int |
update(java.lang.Object... params)
Generic method to execute the update given parameters.
|
int |
update(java.lang.Object[] params,
KeyHolder generatedKeyHolder)
Method to execute the update given arguments and
retrieve the generated keys using a KeyHolder.
|
int |
update(java.lang.String p)
Convenient method to execute an update given one String arg.
|
int |
update(java.lang.String p1,
java.lang.String p2)
Convenient method to execute an update given two String args.
|
int |
updateByNamedParam(java.util.Map<java.lang.String,?> paramMap)
Generic method to execute the update given named parameters.
|
int |
updateByNamedParam(java.util.Map<java.lang.String,?> paramMap,
KeyHolder generatedKeyHolder)
Method to execute the update given arguments and
retrieve the generated keys using a KeyHolder.
|
compileInternal, getParsedSql, newPreparedStatementCreator, newPreparedStatementCreator, newPreparedStatementSetter, onCompileInternal
afterPropertiesSet, allowsUnusedParameters, checkCompiled, compile, declareParameter, getDeclaredParameters, getGeneratedKeysColumnNames, getJdbcTemplate, getResultSetType, getSql, isCompiled, isReturnGeneratedKeys, isUpdatableResults, setDataSource, setFetchSize, setGeneratedKeysColumnNames, setJdbcTemplate, setMaxRows, setParameters, setQueryTimeout, setResultSetType, setReturnGeneratedKeys, setSql, setTypes, setUpdatableResults, supportsLobParameters, validateNamedParameters, validateParameters
public SqlUpdate()
public SqlUpdate(javax.sql.DataSource ds, java.lang.String sql)
ds
- DataSource to use to obtain connectionssql
- SQL statement to executepublic SqlUpdate(javax.sql.DataSource ds, java.lang.String sql, int[] types)
ds
- DataSource to use to obtain connectionssql
- SQL statement to executetypes
- SQL types of the parameters, as defined in the
java.sql.Types
classTypes
public SqlUpdate(javax.sql.DataSource ds, java.lang.String sql, int[] types, int maxRowsAffected)
ds
- DataSource to use to obtain connectionssql
- SQL statement to executetypes
- SQL types of the parameters, as defined in the
java.sql.Types
classmaxRowsAffected
- the maximum number of rows that may
be affected by the updateTypes
public void setMaxRowsAffected(int maxRowsAffected)
maxRowsAffected
- the maximum number of rows that can be affected by
this update without this class's update method considering it an errorpublic void setRequiredRowsAffected(int requiredRowsAffected)
This is an alternative to setting the maximum number of rows that may be affected.
requiredRowsAffected
- the exact number of rows that must be affected
by this update without this class's update method considering it an errorprotected void checkRowsAffected(int rowsAffected) throws JdbcUpdateAffectedIncorrectNumberOfRowsException
rowsAffected
- the number of affected rowsJdbcUpdateAffectedIncorrectNumberOfRowsException
- if the actually affected rows are out of boundssetMaxRowsAffected(int)
,
setRequiredRowsAffected(int)
public int update(java.lang.Object... params) throws DataAccessException
params
- array of parameters objectsDataAccessException
public int update(java.lang.Object[] params, KeyHolder generatedKeyHolder) throws DataAccessException
params
- array of parameter objectsgeneratedKeyHolder
- KeyHolder that will hold the generated keysDataAccessException
public int update() throws DataAccessException
DataAccessException
public int update(int p1) throws DataAccessException
DataAccessException
public int update(int p1, int p2) throws DataAccessException
DataAccessException
public int update(long p1) throws DataAccessException
DataAccessException
public int update(long p1, long p2) throws DataAccessException
DataAccessException
public int update(java.lang.String p) throws DataAccessException
DataAccessException
public int update(java.lang.String p1, java.lang.String p2) throws DataAccessException
DataAccessException
public int updateByNamedParam(java.util.Map<java.lang.String,?> paramMap) throws DataAccessException
paramMap
- Map of parameter name to parameter object,
matching named parameters specified in the SQL statementDataAccessException
public int updateByNamedParam(java.util.Map<java.lang.String,?> paramMap, KeyHolder generatedKeyHolder) throws DataAccessException
paramMap
- Map of parameter name to parameter object,
matching named parameters specified in the SQL statementgeneratedKeyHolder
- KeyHolder that will hold the generated keysDataAccessException