| java.lang.Object org.apache.torque.util.BasePeer
BasePeer | abstract public class BasePeer implements Serializable(Code) | | This is the base class for all Peer classes in the system. Peer
classes are responsible for isolating all of the database access
for a specific business object. They execute all of the SQL
against the database. Over time this class has grown to include
utility methods which ease execution of cross-database queries and
the implementation of concrete Peers.
author: Frank Y. Kim author: John D. McNally author: Brett McLaughlin author: Stephen Haberman author: Martin Poeschl author: Augustin Vidovic author: Henning P. Schmiedehausen version: $Id: BasePeer.java 591648 2007-11-03 16:34:00Z tfischer $ |
Inner Class :protected interface ProcessCallback | |
Field Summary | |
final public static String | IGNORE_CASE Constant criteria key to remove Case Information from
search/ordering criteria. | final public static String | ORDER_BY Constant criteria key to reference ORDER BY columns. | final public static String | TABLE_NAME Classes that implement this class should override this value. | final protected static Log | log |
Method Summary | |
public static void | correctBooleans(Criteria criteria, TableMap defaultTableMap) Checks all columns in the criteria to see whether
booleanchar and booleanint columns are queried with a boolean.
If yes, the query values are mapped onto values the database
does understand, i.e. | public static void | createPreparedStatement(Criteria criteria, StringBuffer queryString, List params) Create a new PreparedStatement. | static Query | createQuery(Criteria criteria) Method to create an SQL query based on values in a Criteria. | static String | createQueryDisplayString(Criteria criteria) Method to create an SQL query for display only based on values in a
Criteria.
Parameters: criteria - A Criteria. | public static String | createQueryString(Criteria criteria) Method to create an SQL query for actual execution based on values in a
Criteria.
Parameters: criteria - A Criteria. | public static void | deleteAll(Connection con, String table, String column, int value) Convenience method that uses straight JDBC to delete multiple
rows. | public static void | deleteAll(String table, String column, int value) Convenience method that uses straight JDBC to delete multiple
rows. | public static void | doDelete(Criteria criteria) Method to perform deletes based on values and keys in a
Criteria. | protected static void | doDelete(Criteria criteria, String tableName) Method to perform deletes based on values and keys in a
Criteria.
This method is protected because it may cause ambiguity between
doDelete(Criteria,Connection) and this method. | public static void | doDelete(Criteria criteria, Connection con) Method to perform deletes based on values and keys in a Criteria. | public static void | doDelete(Criteria criteria, String tableName, Connection con) Method to perform deletes based on values and keys in a Criteria. | public static ObjectKey | doInsert(Criteria criteria) Method to perform inserts based on values and keys in a
Criteria.
If the primary key is auto incremented the data in Criteria
will be inserted and the auto increment value will be returned.
If the primary key is included in Criteria then that value will
be used to insert the row.
If no primary key is included in Criteria then we will try to
figure out the primary key from the database map and insert the
row with the next available id using util.db.IDBroker.
If no primary key is defined for the table the values will be
inserted as specified in Criteria and -1 will be returned.
Parameters: criteria - Object containing values to insert. | public static ObjectKey | doInsert(Criteria criteria, Connection con) Method to perform inserts based on values and keys in a
Criteria.
If the primary key is auto incremented the data in Criteria
will be inserted and the auto increment value will be returned.
If the primary key is included in Criteria then that value will
be used to insert the row.
If no primary key is included in Criteria then we will try to
figure out the primary key from the database map and insert the
row with the next available id using util.db.IDBroker.
If no primary key is defined for the table the values will be
inserted as specified in Criteria and null will be returned.
Parameters: criteria - Object containing values to insert. Parameters: con - A Connection. | public static List | doPSSelect(Criteria criteria, Connection con) Performs a SQL select using a PreparedStatement. | public static List | doPSSelect(Criteria criteria) | public static List | doSelect(Criteria criteria) Returns all results.
Parameters: criteria - A Criteria. | public static List | doSelect(Criteria criteria, Connection con) Returns all results.
Parameters: criteria - A Criteria. Parameters: con - A Connection. | public static void | doUpdate(Criteria updateValues) Convenience method used to update rows in the DB. | public static void | doUpdate(Criteria updateValues, Connection con) Convenience method used to update rows in the DB. | public static void | doUpdate(Criteria selectCriteria, Criteria updateValues) Method used to update rows in the DB. | public static void | doUpdate(Criteria criteria, Criteria updateValues, Connection con) Method used to update rows in the DB. | public static List | executeQuery(String queryString) Utility method which executes a given sql statement. | public static List | executeQuery(String queryString, String dbName) Utility method which executes a given sql statement. | public static List | executeQuery(String queryString, String dbName, boolean singleRecord) Method for performing a SELECT. | public static List | executeQuery(String queryString, boolean singleRecord, Connection con) Method for performing a SELECT. | public static List | executeQuery(String queryString, int start, int numberOfResults, String dbName, boolean singleRecord) Method for performing a SELECT.
Parameters: queryString - A String with the sql statement to execute. Parameters: start - The first row to return. Parameters: numberOfResults - The number of rows to return. Parameters: dbName - The database to connect to. Parameters: singleRecord - Whether or not we want to select only asingle record. | public static List | executeQuery(String queryString, int start, int numberOfResults, boolean singleRecord, Connection con) Method for performing a SELECT. | public static int | executeStatement(String statementString) Utility method which executes a given sql statement. | public static int | executeStatement(String statementString, String dbName) Utility method which executes a given sql statement. | public static int | executeStatement(String statementString, Connection con) Utility method which executes a given sql statement. | public static MapBuilder | getMapBuilder(String name) This method returns the MapBuilder specified in the name
parameter. | public static List | getSelectResults(QueryDataSet qds) Returns all records in a QueryDataSet as a List of Record
objects. | public static List | getSelectResults(QueryDataSet qds, boolean singleRecord) Returns all records in a QueryDataSet as a List of Record
objects. | public static List | getSelectResults(QueryDataSet qds, int numberOfResults, boolean singleRecord) Returns numberOfResults records in a QueryDataSet as a List
of Record objects. | public static List | getSelectResults(QueryDataSet qds, int start, int numberOfResults, boolean singleRecord) Returns numberOfResults records in a QueryDataSet as a List
of Record objects. | protected static void | handleMultipleRecords(DataSet ds) If the user specified that (s)he only wants to retrieve a
single record and multiple records are retrieved, this method
is called to handle the situation. | public static String[] | initColumnNames(Column[] columns) Convenience method to create a String array of column names.
Parameters: columns - A Column[]. | public static String[] | initCriteriaKeys(String tableName, String[] columnNames) Convenience method to create a String array of criteria keys.
Parameters: tableName - Name of table. Parameters: columnNames - A String[]. | public static Column[] | initTableColumns(Schema schema) Creates a Column array for a table based on its Schema.
Parameters: schema - A Schema object. | public static Schema | initTableSchema(String tableName) Sets up a Schema for a table. | public static Schema | initTableSchema(String tableName, String dbName) Sets up a Schema for a table. |
IGNORE_CASE | final public static String IGNORE_CASE(Code) | | Constant criteria key to remove Case Information from
search/ordering criteria.
|
ORDER_BY | final public static String ORDER_BY(Code) | | Constant criteria key to reference ORDER BY columns.
|
TABLE_NAME | final public static String TABLE_NAME(Code) | | Classes that implement this class should override this value.
|
log | final protected static Log log(Code) | | the log
|
correctBooleans | public static void correctBooleans(Criteria criteria, TableMap defaultTableMap) throws TorqueException(Code) | | Checks all columns in the criteria to see whether
booleanchar and booleanint columns are queried with a boolean.
If yes, the query values are mapped onto values the database
does understand, i.e. 0 and 1 for booleanints and N and Y for
booleanchar columns.
Parameters: criteria - The criteria to be checked for booleanint and booleancharcolumns. Parameters: defaultTableMap - the table map to be used if the table name isnot given in a column. throws: TorqueException - if the database map for the criteria cannot beretrieved. |
createPreparedStatement | public static void createPreparedStatement(Criteria criteria, StringBuffer queryString, List params) throws TorqueException(Code) | | Create a new PreparedStatement. It builds a string representation
of a query and a list of PreparedStatement parameters.
Parameters: criteria - Parameters: queryString - Parameters: params - throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
createQuery | static Query createQuery(Criteria criteria) throws TorqueException(Code) | | Method to create an SQL query based on values in a Criteria. Note that
final manipulation of the limit and offset are performed when the query
is actually executed.
Parameters: criteria - A Criteria. the sql query exception: TorqueException - Trouble creating the query string. |
createQueryDisplayString | static String createQueryDisplayString(Criteria criteria) throws TorqueException(Code) | | Method to create an SQL query for display only based on values in a
Criteria.
Parameters: criteria - A Criteria. the SQL query for display exception: TorqueException - Trouble creating the query string. |
createQueryString | public static String createQueryString(Criteria criteria) throws TorqueException(Code) | | Method to create an SQL query for actual execution based on values in a
Criteria.
Parameters: criteria - A Criteria. the SQL query for actual execution exception: TorqueException - Trouble creating the query string. |
deleteAll | public static void deleteAll(Connection con, String table, String column, int value) throws TorqueException(Code) | | Convenience method that uses straight JDBC to delete multiple
rows. Village throws an Exception when multiple rows are
deleted.
Parameters: con - A Connection. Parameters: table - The table to delete records from. Parameters: column - The column in the where clause. Parameters: value - The value of the column. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
deleteAll | public static void deleteAll(String table, String column, int value) throws TorqueException(Code) | | Convenience method that uses straight JDBC to delete multiple
rows. Village throws an Exception when multiple rows are
deleted. This method attempts to get the default database from
the pool.
Parameters: table - The table to delete records from. Parameters: column - The column in the where clause. Parameters: value - The value of the column. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
doDelete | public static void doDelete(Criteria criteria) throws TorqueException(Code) | | Method to perform deletes based on values and keys in a
Criteria.
Parameters: criteria - The criteria to use. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
doDelete | protected static void doDelete(Criteria criteria, String tableName) throws TorqueException(Code) | | Method to perform deletes based on values and keys in a
Criteria.
This method is protected because it may cause ambiguity between
doDelete(Criteria,Connection) and this method. It will be made public
once doDelete(Criteria, Connection) is removed.
Parameters: criteria - The criteria to use. Parameters: tableName - the name of the table to delete records from.If set to null, the name of the table(s) can be extracted fromthe criteria, but this can cause unexpected results. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
doDelete | public static void doDelete(Criteria criteria, Connection con) throws TorqueException(Code) | | Method to perform deletes based on values and keys in a Criteria.
Parameters: criteria - The criteria to use. Parameters: con - A Connection. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
doDelete | public static void doDelete(Criteria criteria, String tableName, Connection con) throws TorqueException(Code) | | Method to perform deletes based on values and keys in a Criteria.
Parameters: criteria - The criteria to use. Parameters: tableName - the name of the table to delete records from.If set to null, the name of the table(s) can be extracted fromthe criteria, but this can cause unexpected results. Parameters: con - A Connection. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
doInsert | public static ObjectKey doInsert(Criteria criteria) throws TorqueException(Code) | | Method to perform inserts based on values and keys in a
Criteria.
If the primary key is auto incremented the data in Criteria
will be inserted and the auto increment value will be returned.
If the primary key is included in Criteria then that value will
be used to insert the row.
If no primary key is included in Criteria then we will try to
figure out the primary key from the database map and insert the
row with the next available id using util.db.IDBroker.
If no primary key is defined for the table the values will be
inserted as specified in Criteria and -1 will be returned.
Parameters: criteria - Object containing values to insert. An Object which is the id of the row that was inserted(if the table has a primary key) or null (if the table does nothave a primary key). throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
doInsert | public static ObjectKey doInsert(Criteria criteria, Connection con) throws TorqueException(Code) | | Method to perform inserts based on values and keys in a
Criteria.
If the primary key is auto incremented the data in Criteria
will be inserted and the auto increment value will be returned.
If the primary key is included in Criteria then that value will
be used to insert the row.
If no primary key is included in Criteria then we will try to
figure out the primary key from the database map and insert the
row with the next available id using util.db.IDBroker.
If no primary key is defined for the table the values will be
inserted as specified in Criteria and null will be returned.
Parameters: criteria - Object containing values to insert. Parameters: con - A Connection. An Object which is the id of the row that was inserted(if the table has a primary key) or null (if the table does nothave a primary key). throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
doPSSelect | public static List doPSSelect(Criteria criteria, Connection con) throws TorqueException(Code) | | Performs a SQL select using a PreparedStatement.
Note: this method does not handle null criteria values.
Parameters: criteria - Parameters: con - a List of Record objects. throws: TorqueException - Error performing database query. |
doPSSelect | public static List doPSSelect(Criteria criteria) throws TorqueException(Code) | | Do a Prepared Statement select according to the given criteria
Parameters: criteria - a List of Record objects. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
doSelect | public static List doSelect(Criteria criteria) throws TorqueException(Code) | | Returns all results.
Parameters: criteria - A Criteria. List of Record objects. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
doSelect | public static List doSelect(Criteria criteria, Connection con) throws TorqueException(Code) | | Returns all results.
Parameters: criteria - A Criteria. Parameters: con - A Connection. List of Record objects. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
doUpdate | public static void doUpdate(Criteria updateValues) throws TorqueException(Code) | | Convenience method used to update rows in the DB. Checks if a
single int primary key is specified in the Criteria
object and uses it to perform the udpate. If no primary key is
specified an Exception will be thrown.
Use this method for performing an update of the kind:
"WHERE primary_key_id = an int"
To perform an update with non-primary key fields in the WHERE
clause use doUpdate(criteria, criteria).
Parameters: updateValues - A Criteria object containing values used inset clause. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
doUpdate | public static void doUpdate(Criteria updateValues, Connection con) throws TorqueException(Code) | | Convenience method used to update rows in the DB. Checks if a
single int primary key is specified in the Criteria
object and uses it to perform the udpate. If no primary key is
specified an Exception will be thrown.
Use this method for performing an update of the kind:
"WHERE primary_key_id = an int"
To perform an update with non-primary key fields in the WHERE
clause use doUpdate(criteria, criteria).
Parameters: updateValues - A Criteria object containing values used inset clause. Parameters: con - A Connection. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
doUpdate | public static void doUpdate(Criteria selectCriteria, Criteria updateValues) throws TorqueException(Code) | | Method used to update rows in the DB. Rows are selected based
on selectCriteria and updated using values in updateValues.
Use this method for performing an update of the kind:
WHERE some_column = some value AND could_have_another_column =
another value AND so on...
Parameters: selectCriteria - A Criteria object containing values used in whereclause. Parameters: updateValues - A Criteria object containing values used in setclause. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
doUpdate | public static void doUpdate(Criteria criteria, Criteria updateValues, Connection con) throws TorqueException(Code) | | Method used to update rows in the DB. Rows are selected based
on criteria and updated using values in updateValues.
Use this method for performing an update of the kind:
WHERE some_column = some value AND could_have_another_column =
another value AND so on.
Parameters: criteria - A Criteria object containing values used in whereclause. Parameters: updateValues - A Criteria object containing values used in setclause. Parameters: con - A Connection. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
executeQuery | public static List executeQuery(String queryString) throws TorqueException(Code) | | Utility method which executes a given sql statement. This
method should be used for select statements only. Use
executeStatement for update, insert, and delete operations.
Parameters: queryString - A String with the sql statement to execute. List of Record objects. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
executeQuery | public static List executeQuery(String queryString, String dbName) throws TorqueException(Code) | | Utility method which executes a given sql statement. This
method should be used for select statements only. Use
executeStatement for update, insert, and delete operations.
Parameters: queryString - A String with the sql statement to execute. Parameters: dbName - The database to connect to. List of Record objects. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
executeQuery | public static List executeQuery(String queryString, String dbName, boolean singleRecord) throws TorqueException(Code) | | Method for performing a SELECT. Returns all results.
Parameters: queryString - A String with the sql statement to execute. Parameters: dbName - The database to connect to. Parameters: singleRecord - Whether or not we want to select only asingle record. List of Record objects. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
executeQuery | public static List executeQuery(String queryString, boolean singleRecord, Connection con) throws TorqueException(Code) | | Method for performing a SELECT. Returns all results.
Parameters: queryString - A String with the sql statement to execute. Parameters: singleRecord - Whether or not we want to select only asingle record. Parameters: con - A Connection. List of Record objects. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
executeQuery | public static List executeQuery(String queryString, int start, int numberOfResults, String dbName, boolean singleRecord) throws TorqueException(Code) | | Method for performing a SELECT.
Parameters: queryString - A String with the sql statement to execute. Parameters: start - The first row to return. Parameters: numberOfResults - The number of rows to return. Parameters: dbName - The database to connect to. Parameters: singleRecord - Whether or not we want to select only asingle record. List of Record objects. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
executeQuery | public static List executeQuery(String queryString, int start, int numberOfResults, boolean singleRecord, Connection con) throws TorqueException(Code) | | Method for performing a SELECT. Returns all results.
Parameters: queryString - A String with the sql statement to execute. Parameters: start - The first row to return. Parameters: numberOfResults - The number of rows to return. Parameters: singleRecord - Whether or not we want to select only asingle record. Parameters: con - A Connection. List of Record objects. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
executeStatement | public static int executeStatement(String statementString) throws TorqueException(Code) | | Utility method which executes a given sql statement. This
method should be used for update, insert, and delete
statements. Use executeQuery() for selects.
Parameters: statementString - A String with the sql statement to execute. The number of rows affected. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
executeStatement | public static int executeStatement(String statementString, String dbName) throws TorqueException(Code) | | Utility method which executes a given sql statement. This
method should be used for update, insert, and delete
statements. Use executeQuery() for selects.
Parameters: statementString - A String with the sql statement to execute. Parameters: dbName - Name of database to connect to. The number of rows affected. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
executeStatement | public static int executeStatement(String statementString, Connection con) throws TorqueException(Code) | | Utility method which executes a given sql statement. This
method should be used for update, insert, and delete
statements. Use executeQuery() for selects.
Parameters: statementString - A String with the sql statement to execute. Parameters: con - A Connection. The number of rows affected. throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
getMapBuilder | public static MapBuilder getMapBuilder(String name) throws TorqueException(Code) | | This method returns the MapBuilder specified in the name
parameter. You should pass in the full path to the class, ie:
org.apache.torque.util.db.map.TurbineMapBuilder. The
MapBuilder instances are cached in the TorqueInstance for speed.
Parameters: name - name of the MapBuilder A MapBuilder, not null throws: TorqueException - if the Map Builder cannot be instantiated |
getSelectResults | public static List getSelectResults(QueryDataSet qds, int numberOfResults, boolean singleRecord) throws TorqueException(Code) | | Returns numberOfResults records in a QueryDataSet as a List
of Record objects. Starting at record 0. Used for
functionality like util.LargeSelect.
See Also: BasePeer.getSelectResults(QueryDataSet,int,int,boolean) Parameters: qds - the QueryDataSet Parameters: numberOfResults - Parameters: singleRecord - a List of Record objects throws: TorqueException - Any exceptions caught during processing will berethrown wrapped into a TorqueException. |
getSelectResults | public static List getSelectResults(QueryDataSet qds, int start, int numberOfResults, boolean singleRecord) throws TorqueException(Code) | | Returns numberOfResults records in a QueryDataSet as a List
of Record objects. Starting at record start. Used for
functionality like util.LargeSelect.
Parameters: qds - The QueryDataSet to extract resultsfrom. Parameters: start - The index from which to start retrievingRecord objects from the data set. Parameters: numberOfResults - The number of results to return (or -1 for all results). Parameters: singleRecord - Whether or not we want to select only asingle record. A List of Record objects. exception: TorqueException - If any Exception occurs. |
handleMultipleRecords | protected static void handleMultipleRecords(DataSet ds) throws TorqueException(Code) | | If the user specified that (s)he only wants to retrieve a
single record and multiple records are retrieved, this method
is called to handle the situation. The default behavior is to
throw an exception, but subclasses can override this method as
needed.
Parameters: ds - The DataSet which contains multiple records. exception: TorqueException - Couldn't handle multiple records. |
initColumnNames | public static String[] initColumnNames(Column[] columns)(Code) | | Convenience method to create a String array of column names.
Parameters: columns - A Column[]. A String[]. |
initCriteriaKeys | public static String[] initCriteriaKeys(String tableName, String[] columnNames)(Code) | | Convenience method to create a String array of criteria keys.
Parameters: tableName - Name of table. Parameters: columnNames - A String[]. A String[]. |
initTableColumns | public static Column[] initTableColumns(Schema schema)(Code) | | Creates a Column array for a table based on its Schema.
Parameters: schema - A Schema object. A Column[]. |
initTableSchema | public static Schema initTableSchema(String tableName)(Code) | | Sets up a Schema for a table. This schema is then normally
used as the argument for initTableColumns().
Parameters: tableName - The name of the table. A Schema. |
initTableSchema | public static Schema initTableSchema(String tableName, String dbName)(Code) | | Sets up a Schema for a table. This schema is then normally
used as the argument for initTableColumns
Parameters: tableName - The propery name for the database in theconfiguration file. Parameters: dbName - The name of the database. A Schema. |
|
|