com.objectwave.persist.sqlConstruction
Class SQLInsert

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

public class SQLInsert
extends SQLModifier

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

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

Version:
$Id: SQLInsert.java,v 2.0 2001/06/11 16:00:04 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
SQLInsert()
          Abstract the issues with an SQL insert statement.
SQLInsert(java.lang.String tableName)
           
 
Method Summary
 void bindValues(java.sql.PreparedStatement stmt, java.lang.Class persistenceClass, boolean verbose)
          No value add other than specifying it is an INSERT statement.
protected  void formatColumnList(java.lang.StringBuffer buf)
          The column portion of an insert statement.
protected  void formatTable(java.lang.StringBuffer buf)
          Simply add "INTO tableName" to the provided StringBuffer.
protected  void formatValueList(java.lang.StringBuffer buf)
          The values portion of an insert statement.
 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()
          Assemble all of the information that has been gathered into a valid sql statement.
 
Methods inherited from class com.objectwave.persist.sqlConstruction.SQLModifier
addColumnList, addColumnValue, addValueList, bindValue, clean, copyValuesFrom, getBroker, getColumnList, getValueList, growLists, setBroker, setValues
 
Methods inherited from class com.objectwave.persist.sqlConstruction.SQLObject
formatValue, getDefaultFormatter, getObjectFormatter, insertWhereClause, isAvailableForPool, setAvailableForPool, setObjectFormatter, setTableName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLInsert

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

See Also:
SQLObject.setTableName(String )

SQLInsert

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

bindValues

public void bindValues(java.sql.PreparedStatement stmt,
                       java.lang.Class persistenceClass,
                       boolean verbose)
                throws java.sql.SQLException,
                       QueryException
No value add other than specifying it is an INSERT statement.

Overrides:
bindValues in class SQLModifier
Parameters:
stmt - java.sql.PreparedStatement
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.

formatColumnList

protected void formatColumnList(java.lang.StringBuffer buf)
The column portion of an insert statement.

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

formatTable

protected void formatTable(java.lang.StringBuffer buf)
Simply add "INTO tableName" to the provided StringBuffer.

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

formatValueList

protected void formatValueList(java.lang.StringBuffer buf)
The values portion of an insert statement.

Parameters:
buf - StringBuffer being built that will contain the full sql statement.
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()
Assemble all of the information that has been gathered into a valid sql statement. ex. "insert INTO myTable (columnName1, columnName2) values (value1, 'value2')"

Specified by:
getSqlStatement in interface SQLAssembler
Specified by:
getSqlStatement in class SQLModifier
Returns:
StringBuffer That is the full sql statement.