org.springframework.jdbc.object
Class SqlUpdate

java.lang.Object
  extended byorg.springframework.jdbc.object.RdbmsOperation
      extended byorg.springframework.jdbc.object.SqlOperation
          extended byorg.springframework.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.

Version:
$Id: SqlUpdate.java,v 1.5 2004/03/18 02:46:13 trisberg Exp $
Author:
Rod Johnson, Isabelle Muszynski

Field Summary
 
Fields inherited from class org.springframework.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.
 int update(java.lang.String p1, java.lang.String p2)
          Convenient method to execute an update given two String args.
 
Methods inherited from class org.springframework.jdbc.object.SqlOperation
compileInternal, getResultSetType, isUpdatableResults, newPreparedStatementCreator, onCompileInternal, setResultSetType, setUpdatableResults
 
Methods inherited from class org.springframework.jdbc.object.RdbmsOperation
afterPropertiesSet, compile, declareParameter, getDeclaredParameters, getJdbcTemplate, getSql, isCompiled, setDataSource, setJdbcTemplate, 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

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
Throws:
InvalidDataAccessApiUsageException

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.


update

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



Copyright (C) 2003-2004 The Spring Framework Project.