2004.04.29


com.jdc.rdb.sql.dml.update
Class Update

java.lang.Object
  |
  +--com.jdc.lang.Object
        |
        +--com.jdc.rdb.sql.SQL
              |
              +--com.jdc.rdb.sql.dml.DML
                    |
                    +--com.jdc.rdb.sql.dml.update.Update
All Implemented Interfaces:
Serializable, Statement

public class Update
extends DML

Update represents a Data Manipulation Language Update SQL statement. The Update statement updates the values of specified columns in rows of a Table table or View. Updating a row of a View updates a row of its base Table.

There are two (2) forms of this statement:

Currently, only Update by a search condition is supported.
Invocation:
This statement can be embedded in an application program or issued through the use of dynamic SQL statements. It is an executable statement that can be dynamically prepared.
Authorization:
To execute this statement, the privileges held by the authorization ID of the statement must include at least one of the following (for IBM® DB2 Universal Database™):

Additionally, to execute a searched Update statement, the privileges held by the authorization ID of the statement must also include at least one of the following for each table or view referenced by a subquery (for IBM® DB2 Universal Database™):
Example:
        Update update = new Update(table);

        update.setWhere(column 1 , 123       );  
        update.setWhere(column 2 , "Key"     );  
        . . .

        update.setValue(column 3 , true      );  // boolean Column
        update.setValue(column 4 , 456       );  // int Column
        update.setValue(column 5 , "String"  );  // String Column
        update.setValue(column 6 , new Date());  // Date Column
        . . .

        UpdateStatus status = update.execute();
 
        if (status.isSuccessful())
        {
            // Update success
        }
        else
        {
            // Update failed!
        }
Reference:
IBM® DB2 Universal Database™ SQL Reference Volume 2 Version 8, Pages 738 thru 749.
Note:
Update of a View is not currently supported.

Version:
2.0
Author:
Jay Damon
See Also:
Target, Correlation, Set, Where, With, Serialized Form

Field Summary
static String COMMAND
          The Update statement command keyword.
 
Fields inherited from class com.jdc.rdb.sql.dml.DML
sql
 
Fields inherited from class com.jdc.lang.Object
string
 
Constructor Summary
Update()
          Constructs a new Update statement object.
Update(String statement)
          Constructs a new Update statement object for the specified Update statement.
Update(Table table)
          Constructs a new Update statement object for the specified Database Table.
 
Method Summary
 UpdateStatus execute()
          Executes the Update statement and returns an UpdateStatus object.
 Set getSet()
          Returns the Set clause for this Update statement.
 Target getTarget()
          Returns the com.jdc.rdb.sql.dml.Target clause for this Update statement.
 Where getWhere()
          Returns the Where clause for this Update statement.
protected  boolean isValid()
          Returns true if the Update statement is valid.
 Update set(UpdateClause clause)
          Sets an UpdateClause for this Update statement.
 Update setValue(Column column, boolean value)
          Sets a boolean value for the specified Column.
 Update setValue(Column column, int value)
          Sets an int value for the specified Column.
 Update setValue(Column column, Object value)
          Sets an Object value for the specified Column.
 Update setWhere(Column column, int value)
          Sets a search condition for the specified table Column and int value.
 Update setWhere(Column column, Object value)
          Sets a search condition for the specified table Column and Object value.
 
Methods inherited from class com.jdc.rdb.sql.dml.DML
finalize, getColumn, getConnection, getTable, setTable
 
Methods inherited from class com.jdc.rdb.sql.SQL
addClause, execute, getClause, getCommand, getStatement, setCommand, setConnection, setStatement, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

COMMAND

public static final String COMMAND
The Update statement command keyword.

See Also:
Constant Field Values
Constructor Detail

Update

public Update()
Constructs a new Update statement object.


Update

public Update(Table table)
Constructs a new Update statement object for the specified Database Table.

Throws:
SQLInvalidException - No table definition is specified.

Update

public Update(String statement)
Constructs a new Update statement object for the specified Update statement.

Throws:
SQLInvalidException - No DELETE statement is specified.
Method Detail

execute

public UpdateStatus execute()
Executes the Update statement and returns an UpdateStatus object.

Returns:
The Update statement status.

getTarget

public Target getTarget()
Returns the com.jdc.rdb.sql.dml.Target clause for this Update statement.

Returns:
The Update statement Target clause.

getSet

public Set getSet()
Returns the Set clause for this Update statement.

Returns:
The Update statement Set clause.

getWhere

public Where getWhere()
Returns the Where clause for this Update statement.

Returns:
The Update statement Where clause.

isValid

protected boolean isValid()
Returns true if the Update statement is valid.

Overrides:
isValid in class SQL
Returns:
True if the SQL statement is valid.
False if the SQL statement is not valid

set

public Update set(UpdateClause clause)
Sets an UpdateClause for this Update statement. Use this method to specify a custom Update clause.

Returns:
This Update statement object.
Throws:
SQLInvalidException - No UPDATE statement clause is specified.

setValue

public Update setValue(Column column,
                       boolean value)
Sets a boolean value for the specified Column. The Column alias is used to create the Columns clause and the boolean value is used to create the Values clause for this Update statement.

Returns:
This Update statement object.
Throws:
SQLInvalidException - No column is specified, an invalid column is specified, or a column for which a value has already been set is specified.

setValue

public Update setValue(Column column,
                       int value)
Sets an int value for the specified Column. The Column alias is used to create the Columns clause and the int value is used to create the Values clause for this Update statement.

Returns:
This Update statement object.
Throws:
SQLInvalidException - No column is specified, an invalid column is specified, or a column for which a value has already been set is specified.

setValue

public Update setValue(Column column,
                       Object value)
Sets an Object value for the specified Column. The Column alias is used to create the Columns clause and the Object value is used to create the Values clause for this Update statement.

Returns:
This Update statement object.
Throws:
SQLInvalidException - No column is specified, an invalid column is specified, or a column for which a value has already been set is specified.

setWhere

public Update setWhere(Column column,
                       int value)
Sets a search condition for the specified table Column and int value. These values are used to create the com.jdc.rdb.sql.dml.Where clause for this statement. A com.jdc.rdb.sql.dml.Comparison operator of EQUAL, i.e. "=", is implied.

Returns:
This Update statement object.
Throws:
SQLInvalidException - No column is specified or an invalid table column is specified.

setWhere

public Update setWhere(Column column,
                       Object value)
Sets a search condition for the specified table Column and Object value. These values are used to create the com.jdc.rdb.sql.dml.Where clause for this statement. A com.jdc.rdb.sql.dml.Comparison operator of EQUAL, i.e. "=", is implied.

Returns:
This Update statement object.
Throws:
SQLInvalidException - No column is specified or an invalid table column is specified.

2004.04.29



Copyright © 2004 J. Damon & Co.; All Rights Reserved WorldWide.