com.objectwave.persist.sqlConstruction
Class SQLUpdate

java.lang.Object
  |
  +--com.objectwave.persist.sqlConstruction.SQLObject
        |
        +--com.objectwave.persist.sqlConstruction.SQLModifier
              |
              +--com.objectwave.persist.sqlConstruction.SQLUpdate
All Implemented Interfaces:
SQLAssembler

public class SQLUpdate
extends SQLModifier

A class that handles the creation of SQL Update statements. For example:

    SQLUpdate sql = new SQLUpdate();
	sql.setTableName("TABLENAME");
 

Version:
$Id: SQLUpdate.java,v 2.1 2002/03/09 17:13:47 dave_hoag Exp $
Author:
Dave Hoag
See Also:
com.objectwave.persist.SQLAssembler, com.objectwave.persist.RDBBroker

Field Summary
 
Fields inherited from class com.objectwave.persist.sqlConstruction.SQLModifier
columnList, sqlTypes, valueCount, valueList
 
Fields inherited from class com.objectwave.persist.sqlConstruction.SQLObject
availableForPool, table
 
Constructor Summary
SQLUpdate()
          Abstract the issues with an SQL update statement.
SQLUpdate(java.lang.String tableName)
           
 
Method Summary
 void bindValues(java.sql.PreparedStatement stmt, java.lang.Class persistenceClass, boolean verbose)
          Bind data to a prepared statement.
 void clean()
          We pool these objects for reuse.
 void copyValuesFrom(SQLModifier sql)
          We have one cached SQLModifier object for prepared statements.
protected  void formatColumnList(java.lang.StringBuffer buf)
           
protected  void formatTable(java.lang.StringBuffer buf)
          Simply place the table name upon the provided StringBuffer.
protected  void formatWhereClause(java.lang.StringBuffer buf)
          Add the required where clause elements for this update.
protected  void formatWhereClauseElement(Pair clause, java.lang.StringBuffer buf)
          Format the where clause to be like 'columnName = objectValue'.
 java.lang.String getPreparedString()
          As with the getSqlStatement() method, this method trusts that there's an ordered, 1-1 mapping between the columns list and the values list.
 java.lang.StringBuffer getSqlStatement()
          Gets the SqlStatement attribute of the SQLModifier object
 java.util.ArrayList getWhereClause()
           
 void insertWhereClause(java.lang.String column, java.lang.Object value)
           
 void setWhereClause(java.util.ArrayList v)
           
 
Methods inherited from class com.objectwave.persist.sqlConstruction.SQLModifier
addColumnList, addColumnValue, addValueList, bindValue, getBroker, getColumnList, getValueList, growLists, setBroker, setValues
 
Methods inherited from class com.objectwave.persist.sqlConstruction.SQLObject
formatValue, getDefaultFormatter, getObjectFormatter, isAvailableForPool, setAvailableForPool, setObjectFormatter, setTableName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLUpdate

public SQLUpdate()
Abstract the issues with an SQL update statement. If this constructor is used, the table name must be set with the setTableName method.

See Also:
SQLObject.setTableName(String )

SQLUpdate

public SQLUpdate(java.lang.String tableName)
Parameters:
tableName - String The table name for which this statement will insert values.
Method Detail

clean

public void clean()
Description copied from class: SQLModifier
We pool these objects for reuse. Before returning the object to the pool, clean it up by removing all old values.

Overrides:
clean in class SQLModifier

bindValues

public void bindValues(java.sql.PreparedStatement stmt,
                       java.lang.Class persistenceClass,
                       boolean verbose)
                throws java.sql.SQLException,
                       QueryException
Description copied from class: SQLModifier
Bind data to a prepared statement.

Overrides:
bindValues in class SQLModifier
Parameters:
stmt - java.sql.PreparedStatement The statement to which data values are to be bound.
persistenceClass - The persistent class we are updating. Used for a query to determine sql types.
verbose - boolean Should we be verbose about this effort?
Throws:
java.sql.SQLException - An unexcepted database exception.
QueryException - An exception generated by JGrinder.

copyValuesFrom

public void copyValuesFrom(SQLModifier sql)
We have one cached SQLModifier object for prepared statements. We need to copy the values from the newly created SQLModifier before doing the bindValues.

Overrides:
copyValuesFrom in class SQLModifier
Parameters:
sql - The source of the new data values.

formatColumnList

protected void formatColumnList(java.lang.StringBuffer buf)

formatTable

protected void formatTable(java.lang.StringBuffer buf)
Simply place the table name upon the provided StringBuffer.

Parameters:
buf - StringBuffer being built that will contain the full sql statement.
See Also:
The user of this method.

formatWhereClause

protected void formatWhereClause(java.lang.StringBuffer buf)
Add the required where clause elements for this update.

Parameters:
buf - StringBuffer being built that will contain the full sql statement.
See Also:
The user of this method.

formatWhereClauseElement

protected void formatWhereClauseElement(Pair clause,
                                        java.lang.StringBuffer buf)
Format the where clause to be like 'columnName = objectValue'.

Parameters:
clause - com.objectwave.utility.Pair The first element is the column name, the second is the where clause value.
buf - java.lang.StringBuffer
See Also:
The user of this method.

getPreparedString

public java.lang.String getPreparedString()
As with the getSqlStatement() method, this method trusts that there's an ordered, 1-1 mapping between the columns list and the values list.

Specified by:
getPreparedString in class SQLModifier
Returns:
java.lang.String, a string which will be appropriate for a SQL prepared statement, based on the columns and values contained by this SQLInsert instance.

getSqlStatement

public java.lang.StringBuffer getSqlStatement()
Description copied from class: SQLModifier
Gets the SqlStatement attribute of the SQLModifier object

Specified by:
getSqlStatement in interface SQLAssembler
Specified by:
getSqlStatement in class SQLModifier
Returns:
java.lang.StringBuffer A buffer containing the complete update statement.

getWhereClause

public java.util.ArrayList getWhereClause()

insertWhereClause

public void insertWhereClause(java.lang.String column,
                              java.lang.Object value)
Overrides:
insertWhereClause in class SQLObject
Parameters:
column -
value -

setWhereClause

public void setWhereClause(java.util.ArrayList v)