net.toften.jlips.persist.db
Class DBAbstractStatement

java.lang.Object
  extended by net.toften.jlips.persist.db.DBAbstractStatement
Direct Known Subclasses:
DBDefaultStatement

public abstract class DBAbstractStatement
extends Object

SQL statement which direct implementation of the DBStatement interface can extend. The class implements a set of helper method designed to assist in generating the SQL statements for the database request

Author:
thomas

Field Summary
protected  List expressions
          Holds the expressions passed in by jLips
protected  Connection myCon
          Holds the database connection
protected  Object primaryKeyValue
          Holder for valued to be changed by the statement
protected  List returnColumns
          Holds the return columns requested by jLips
protected  List sourceTables
          Holds the source tables requested by jLips
 
Constructor Summary
DBAbstractStatement()
           
 
Method Summary
 void addEqualExpression(DBTableColumnInfo newColumn, Object value)
           
 void addReturnColumn(DBTableColumnInfo newReturnColumn)
           
 void addSourceTable(DBTableInfo newTable)
           
protected  void appendColumnNames(StringBuffer s, Iterator iter)
          Appends column names to a StringBuffer using ", " as delimeter The column names are taken from an Iterator that must iterate over a Collection containing DBTableColumnInfo objects
protected  void appendPrimaryKeyEquals(StringBuffer s)
          Will append a equal expression for the primary key for the first added source table This method will append an equal expression to the provided StringBuffer using the specified primary key value and the name of the primary key in the first source table added.
protected  void appendStrings(StringBuffer s, Iterator iter, String delimiter, String preString)
          Appends a list of strings to a StringBuffer using a defined delimiter.
protected  void appendTableNames(StringBuffer s, Iterator iter)
          Appends table names to a StringBuffer using ", " as delimeter The table names are taken from an Iterator that must iterate over a Collection containing DBTableInfo objects
protected  Statement prepareConnection()
          Will request a database connection from the database connection factory and create a statement
 void release()
           
 void setPrimaryKeyValue(Object pKey)
           
 String toString()
          Returns the provided data for the statement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

expressions

protected List expressions
Holds the expressions passed in by jLips

See Also:
addEqualExpression(DBTableColumnInfo, Object)

myCon

protected Connection myCon
Holds the database connection

See Also:
prepareConnection()

primaryKeyValue

protected Object primaryKeyValue
Holder for valued to be changed by the statement

See Also:
#addSetValue(DBTableColumnInfo, Object)

returnColumns

protected List returnColumns
Holds the return columns requested by jLips

See Also:
addReturnColumn(DBTableColumnInfo)

sourceTables

protected List sourceTables
Holds the source tables requested by jLips

See Also:
addSourceTable(DBTableInfo), addReturnColumn(DBTableColumnInfo)
Constructor Detail

DBAbstractStatement

public DBAbstractStatement()
Method Detail

addEqualExpression

public void addEqualExpression(DBTableColumnInfo newColumn,
                               Object value)
See Also:
DBStatement.addEqualExpression(DBTableColumnInfo, Object)

addReturnColumn

public void addReturnColumn(DBTableColumnInfo newReturnColumn)
See Also:
DBStatement.addReturnColumn(DBTableColumnInfo)

addSourceTable

public void addSourceTable(DBTableInfo newTable)
See Also:
DBStatement.addSourceTable(DBTableInfo)

setPrimaryKeyValue

public void setPrimaryKeyValue(Object pKey)
See Also:
DBStatement.setPrimaryKeyValue(Object)

appendColumnNames

protected void appendColumnNames(StringBuffer s,
                                 Iterator iter)
Appends column names to a StringBuffer using ", " as delimeter The column names are taken from an Iterator that must iterate over a Collection containing DBTableColumnInfo objects

Parameters:
s - StringBuffer to append column names to
iter - Iterator for Collection containing DBTableColumnInfo objects
See Also:
DBTableColumnInfo

appendStrings

protected void appendStrings(StringBuffer s,
                             Iterator iter,
                             String delimiter,
                             String preString)
Appends a list of strings to a StringBuffer using a defined delimiter. The strings are taken from an Iterator that must iterate over a Collection containing String objects The delimeter will be applied between the strings, but not in the end

Parameters:
s - StringBuffer to append strings to
iter - Iterator for Collection containing String objects
delimiter - The delimeter used between the strings
preString - String appended before every string

appendTableNames

protected void appendTableNames(StringBuffer s,
                                Iterator iter)
Appends table names to a StringBuffer using ", " as delimeter The table names are taken from an Iterator that must iterate over a Collection containing DBTableInfo objects

Parameters:
s - StringBuffer to append table names to
iter - Iterator for Collection containing DBTableInfo objects
See Also:
DBTableInfo

appendPrimaryKeyEquals

protected void appendPrimaryKeyEquals(StringBuffer s)
                               throws DBBadPropertiesException
Will append a equal expression for the primary key for the first added source table This method will append an equal expression to the provided StringBuffer using the specified primary key value and the name of the primary key in the first source table added. For example if the first source table added was person:
        dbs.addSourceTable(personTableInfo);
 
and the primary key name of the person table is id and the type of the primary key is Integer then the added expression is
        id = 1
 
This is of course if the provided primary key value is 1:
        dbs.setPrimaryKeyValue(new Integer(1));
 

Parameters:
s - StringBuffer to append the equal string to
Throws:
DBBadPropertiesException

release

public void release()
See Also:
DBStatement.release()

prepareConnection

protected Statement prepareConnection()
                               throws SQLException
Will request a database connection from the database connection factory and create a statement

Throws:
SQLException - passed from the connection factory
See Also:
DBConnectionFactory.getConnection(), #s

toString

public String toString()
Returns the provided data for the statement

Overrides:
toString in class Object
See Also:
Object.toString()