net.toften.jlips.persist.db
Interface DBStatement

All Known Implementing Classes:
DBDefaultStatement

public interface DBStatement

This interface defines the methods for building a SQL statement. The interface provides a set of methods used to build up a SQL statement. The mehods use other jLips database description objects as parameters. The different parts of the statement are first set up:

After the statement parts are set up, the type if request is chosen:

Implmenting the interface

The interface can be implemented by the application. When the application needs a connection the the database, the DBConnectionFactory.getConnection() method is used.

Selecting the implmentation jLips uses

When jLips is initialised using the EntityFactory.init(Properties, Map) method, passing in the name of the DBStatement implementing class. The class is passed in the database properties parameter using the EntityFactory.EF_DB_STM_HAND

Implementations in jLips

jLips provides a default implementation as well as an abstract class, that the application can extend for it's own implementation of the SQL statement

Author:
thomas
See Also:
DBDefaultStatement

Field Summary
static String DBS_DELETE_STM
           
static String DBS_INSERT_STM
           
static String DBS_SELECT_STM
           
static String DBS_UPDATE_STM
           
 
Method Summary
 void addEqualExpression(DBTableColumnInfo newColumn, Object value)
          Adds an equal expresion to the statement This applies to: Select statement (the values to be searched for) Update statement (the values to be changed) Delete statement (the values to be searched for)
 void addReturnColumn(DBTableColumnInfo newReturnColumn)
          Adds a column from which data must be returned This applies to: Select statement If the table of the column has not been added as a source table, this method must add the table.
 void addSourceTable(DBTableInfo newTable)
          Add a table to the statement This applies to: Select statement (data is returned from the table) Update statement (data is updated in the table) Insert statement (a record is inserted in the table) Delete statement (data is removed from the table)
 ResultSet doDelete()
           
 ResultSet doInsert()
           
 ResultSet doSelect()
          Must execute a select statement on the database.
 ResultSet doUpdate()
           
 void printStatement(String type)
           
 void release()
          When jLips is done with the statement, this method is called.
 void setPrimaryKeyValue(Object pKey)
          Adds a primary key value to be used to locate a specific record This applies to: Update statement (record to be updated) Insert statement (primary key value of new record) Delete statement (record to be removed)
 String toString()
           
 

Field Detail

DBS_SELECT_STM

static final String DBS_SELECT_STM
See Also:
Constant Field Values

DBS_UPDATE_STM

static final String DBS_UPDATE_STM
See Also:
Constant Field Values

DBS_INSERT_STM

static final String DBS_INSERT_STM
See Also:
Constant Field Values

DBS_DELETE_STM

static final String DBS_DELETE_STM
See Also:
Constant Field Values
Method Detail

addSourceTable

void addSourceTable(DBTableInfo newTable)
Add a table to the statement This applies to:

Parameters:
newTable - The table to add

addEqualExpression

void addEqualExpression(DBTableColumnInfo newColumn,
                        Object value)
Adds an equal expresion to the statement This applies to:

Parameters:
newColumn - The column to be tested
value - The value the column must be equal to

addReturnColumn

void addReturnColumn(DBTableColumnInfo newReturnColumn)
Adds a column from which data must be returned This applies to: If the table of the column has not been added as a source table, this method must add the table. If no return columns are added, all data from all source tables must be returned.

Parameters:
newReturnColumn - The column to return data from

setPrimaryKeyValue

void setPrimaryKeyValue(Object pKey)
Adds a primary key value to be used to locate a specific record This applies to:
  • Update statement (record to be updated)
  • Insert statement (primary key value of new record)
  • Delete statement (record to be removed)
  • Parameters:
    newColumn - The column to be tested
    value - The value the column must be equal to

    release

    void release()
    When jLips is done with the statement, this method is called. The statement implementation can use this method to do any cleanup after the statement has been used. After this method is called, jLips will not use the statement object any more.


    doSelect

    ResultSet doSelect()
                       throws SQLException,
                              DBBadPropertiesException
    Must execute a select statement on the database. The implementation should build a select statement with the provided data and return the ResultSet

    Using doSelect

    DOCUMENT ME!

    Returns:
    ResultSet with the data returned from the database
    Throws:
    SQLException - Exception thrown by the database driver
    DBBadPropertiesException - if the properties are not correct or sufficent to execute a select statement

    doUpdate

    ResultSet doUpdate()
                       throws SQLException,
                              DBBadPropertiesException
    Throws:
    SQLException
    DBBadPropertiesException

    doInsert

    ResultSet doInsert()
                       throws SQLException,
                              DBBadPropertiesException
    Throws:
    SQLException
    DBBadPropertiesException

    doDelete

    ResultSet doDelete()
                       throws SQLException,
                              DBBadPropertiesException
    Throws:
    SQLException
    DBBadPropertiesException

    toString

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

    printStatement

    void printStatement(String type)
                        throws DBBadPropertiesException
    Throws:
    DBBadPropertiesException