com.interface21.jdbc.object
Class SqlUpdate

java.lang.Object
  |
  +--com.interface21.jdbc.object.RdbmsOperation
        |
        +--com.interface21.jdbc.object.SqlOperation
              |
              +--com.interface21.jdbc.object.SqlUpdate
All Implemented Interfaces:
InitializingBean

public class SqlUpdate
extends SqlOperation

RdbmsOperation subclass representing a SQL update. Like a query, an update object is reusable. Like all RdbmsOperation objects, an update can have parameters and is defined in SQL.
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.

Author:
Rod Johnson, Isabelle Muszynski

Fields inherited from class com.interface21.jdbc.object.RdbmsOperation
logger
 
Constructor Summary
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 to keep consistent with the
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.
 
Method Summary
 void setMaxRowsAffected(int max)
          Set the maximum number of rows that may be affected by this update.
 void setRequiredRowsAffected(int rowsAffected)
          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(java.lang.Object[] args)
          Generic method to execute the update given arguments.
 int update(java.lang.String p)
          Convenient method to execute an update given one String arg
 
Methods inherited from class com.interface21.jdbc.object.SqlOperation
compileInternal, getJdbcTemplate, newPreparedStatementCreator, onCompileInternal
 
Methods inherited from class com.interface21.jdbc.object.RdbmsOperation
afterPropertiesSet, compile, declareParameter, getDataSource, getDeclaredParameters, getSql, isCompiled, setDataSource, setSql, setTypes, validateParameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SqlUpdate

public SqlUpdate()
Constructor to allow use as a JavaBean. DataSource, SQL and any parameter declarations must be supplied before compilation and use.

SqlUpdate

public SqlUpdate(javax.sql.DataSource ds,
                 java.lang.String sql)
Constructs an update object with a given DataSource and SQL to keep consistent with the
Parameters:
ds - DataSource to use to obtain connections
sql - SQL
types - anonymous parameter declarations.

SqlUpdate

public SqlUpdate(javax.sql.DataSource ds,
                 java.lang.String sql,
                 int[] types)
Construct an update object with a given DataSource, SQL and anonymous parameters
Parameters:
ds - DataSource to use to obtain connections
sql - SQL
types - anonymous parameter declarations.

SqlUpdate

public 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.
Parameters:
ds - DataSource to use to obtain connections
sql - SQL
types - anonymous parameter declarations.
maxRowsAffected - the maximum number of rows that may be affected by the update.
Method Detail

setMaxRowsAffected

public void setMaxRowsAffected(int max)
Set the maximum number of rows that may be affected by this update. The default value is 0, which does not limit the number of rows affected.
Parameters:
max - the maximum number of rows that can be affected by this update without this class's update() method considering it an error.

setRequiredRowsAffected

public void setRequiredRowsAffected(int rowsAffected)
Set the exact number of rows that must be affected by this update. The default value is 0, which allows any number of rows to be affected. An alternative to setting the maximum number of rows that may be affected.
Parameters:
rowsAffected - the exact number of rows that must be affected by this update.

update

public int update(java.lang.Object[] args)
           throws InvalidDataAccessApiUsageException
Generic method to execute the update given arguments. All other update() methods invoke this method.
Parameters:
args - array of object arguments
Returns:
the number of rows affected by the update

update

public int update()
Convenience method to execute an update with no parameters

update

public int update(int p1)
Convenient method to execute an update given one int arg

update

public int update(int p1,
                  int p2)
Convenient method to execute an update given two int args

update

public int update(java.lang.String p)
Convenient method to execute an update given one String arg


Rod Johnson and Spring contributors 2001-2003.