|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.torque.util.BasePeer
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.
Field Summary | |
protected static org.apache.log4j.Category |
category
|
static java.lang.String |
DEFAULT_MAP_BUILDER
The Turbine default MapBuilder. |
static java.lang.String |
IGNORE_CASE
Constant criteria key to remove Case Information from search/ordering criteria. |
private static java.util.Hashtable |
mapBuilders
Hashtable that contains the cached mapBuilders. |
static java.lang.String |
ORDER_BY
Constant criteria key to reference ORDER BY columns. |
static java.lang.String |
TABLE_NAME
Classes that implement this class should override this value. |
Constructor Summary | |
BasePeer()
|
Method Summary | |
static void |
createPreparedStatement(Criteria criteria,
java.lang.StringBuffer queryString,
java.util.List params)
Create a new PreparedStatement. |
(package private) static Query |
createQuery(Criteria criteria)
Method to create an SQL query based on values in a Criteria. |
(package private) static java.lang.String |
createQueryDisplayString(Criteria criteria)
Method to create an SQL query for display only based on values in a Criteria. |
static java.lang.String |
createQueryString(Criteria criteria)
Method to create an SQL query for actual execution based on values in a Criteria. |
static void |
deleteAll(java.sql.Connection con,
java.lang.String table,
java.lang.String column,
int value)
Convenience method that uses straight JDBC to delete multiple rows. |
static void |
deleteAll(java.lang.String table,
java.lang.String column,
int value)
Convenience method that uses straight JDBC to delete multiple rows. |
static void |
doDelete(Criteria criteria)
Method to perform deletes based on values and keys in a Criteria. |
static void |
doDelete(Criteria criteria,
java.sql.Connection con)
Method to perform deletes based on values and keys in a Criteria. |
static ObjectKey |
doInsert(Criteria criteria)
Method to perform inserts based on values and keys in a Criteria. |
static ObjectKey |
doInsert(Criteria criteria,
java.sql.Connection con)
Method to perform inserts based on values and keys in a Criteria. |
static java.util.List |
doPSSelect(Criteria criteria)
Do a Prepared Statement select according to the given criteria |
static java.util.List |
doPSSelect(Criteria criteria,
java.sql.Connection con)
Performs a SQL select using a PreparedStatement. |
static java.util.List |
doSelect(Criteria criteria)
Returns all results. |
static java.util.List |
doSelect(Criteria criteria,
java.sql.Connection con)
Returns all results. |
static void |
doUpdate(Criteria updateValues)
Convenience method used to update rows in the DB. |
static void |
doUpdate(Criteria updateValues,
java.sql.Connection con)
Convenience method used to update rows in the DB. |
static void |
doUpdate(Criteria selectCriteria,
Criteria updateValues)
Method used to update rows in the DB. |
static void |
doUpdate(Criteria selectCriteria,
Criteria updateValues,
java.sql.Connection con)
Method used to update rows in the DB. |
static java.util.List |
executeQuery(java.lang.String queryString)
Utility method which executes a given sql statement. |
static java.util.List |
executeQuery(java.lang.String queryString,
boolean singleRecord,
java.sql.Connection con)
Method for performing a SELECT. |
static java.util.List |
executeQuery(java.lang.String queryString,
int start,
int numberOfResults,
boolean singleRecord,
java.sql.Connection con)
Method for performing a SELECT. |
static java.util.List |
executeQuery(java.lang.String queryString,
int start,
int numberOfResults,
java.lang.String dbName,
boolean singleRecord)
Method for performing a SELECT. |
static java.util.List |
executeQuery(java.lang.String queryString,
java.lang.String dbName)
Utility method which executes a given sql statement. |
static java.util.List |
executeQuery(java.lang.String queryString,
java.lang.String dbName,
boolean singleRecord)
Method for performing a SELECT. |
static int |
executeStatement(java.lang.String stmt)
Utility method which executes a given sql statement. |
static int |
executeStatement(java.lang.String stmt,
java.sql.Connection con)
Utility method which executes a given sql statement. |
static int |
executeStatement(java.lang.String stmt,
java.lang.String dbName)
Utility method which executes a given sql statement. |
static MapBuilder |
getMapBuilder()
This method returns the MapBuilder specified in the TurbineResources.properties file. |
static MapBuilder |
getMapBuilder(java.lang.String name)
This method returns the MapBuilder specified in the name parameter. |
private static ColumnMap |
getPrimaryKey(Criteria criteria)
Helper method which returns the primary key contained in the given Criteria object. |
static java.util.List |
getSelectResults(com.workingdogs.village.QueryDataSet qds)
Returns all records in a QueryDataSet as a List of Record objects. |
static java.util.List |
getSelectResults(com.workingdogs.village.QueryDataSet qds,
boolean singleRecord)
Returns all records in a QueryDataSet as a List of Record objects. |
static java.util.List |
getSelectResults(com.workingdogs.village.QueryDataSet qds,
int numberOfResults,
boolean singleRecord)
Returns numberOfResults records in a QueryDataSet as a List of Record objects. |
static java.util.List |
getSelectResults(com.workingdogs.village.QueryDataSet qds,
int start,
int numberOfResults,
boolean singleRecord)
Returns numberOfResults records in a QueryDataSet as a List of Record objects. |
protected static void |
handleMultiple(com.workingdogs.village.DataSet ds)
Deprecated. Use the better-named handleMultipleRecords() instead. |
protected static void |
handleMultipleRecords(com.workingdogs.village.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. |
static byte[] |
hashtableToByteArray(java.util.Hashtable hash)
Converts a hashtable to a byte array for storage/serialization. |
static java.lang.String[] |
initColumnNames(com.workingdogs.village.Column[] columns)
Convenience method to create a String array of column names. |
static java.lang.String[] |
initCriteriaKeys(java.lang.String tableName,
java.lang.String[] columnNames)
Convenience method to create a String array of criteria keys. |
static com.workingdogs.village.Column[] |
initTableColumns(com.workingdogs.village.Schema schema)
Creates a Column array for a table based on its Schema. |
static com.workingdogs.village.Schema |
initTableSchema(java.lang.String tableName)
Sets up a Schema for a table. |
static com.workingdogs.village.Schema |
initTableSchema(java.lang.String tableName,
java.lang.String dbName)
Sets up a Schema for a table. |
private static void |
insertOrUpdateRecord(com.workingdogs.village.Record rec,
java.lang.String tableName,
Criteria criteria)
Grouping of code used in both doInsert() and doUpdate() methods. |
private static void |
throwMalformedColumnNameException(java.lang.String criteriaPhrase,
java.lang.String columnName)
Throws a TorqueException with the malformed column name error message. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String ORDER_BY
public static final java.lang.String IGNORE_CASE
public static final java.lang.String TABLE_NAME
public static final java.lang.String DEFAULT_MAP_BUILDER
private static java.util.Hashtable mapBuilders
protected static org.apache.log4j.Category category
Constructor Detail |
public BasePeer()
Method Detail |
public static byte[] hashtableToByteArray(java.util.Hashtable hash) throws TorqueException
hash
- The Hashtable to convert.
TorqueException
public static com.workingdogs.village.Schema initTableSchema(java.lang.String tableName)
tableName
- The name of the table.
public static com.workingdogs.village.Schema initTableSchema(java.lang.String tableName, java.lang.String dbName)
tableName
- The propery name for the database in the
Turbineresources file.dbName
- The name of the database.
public static com.workingdogs.village.Column[] initTableColumns(com.workingdogs.village.Schema schema)
schema
- A Schema object.
public static java.lang.String[] initColumnNames(com.workingdogs.village.Column[] columns)
columns
- A Column[].
public static java.lang.String[] initCriteriaKeys(java.lang.String tableName, java.lang.String[] columnNames)
tableName
- Name of table.columnNames
- A String[].
public static void deleteAll(java.sql.Connection con, java.lang.String table, java.lang.String column, int value) throws TorqueException
con
- A Connection.table
- The table to delete records from.column
- The column in the where clause.value
- The value of the column.
TorqueException
public static void deleteAll(java.lang.String table, java.lang.String column, int value) throws TorqueException
table
- The table to delete records from.column
- The column in the where clause.value
- The value of the column.
TorqueException
public static void doDelete(Criteria criteria) throws TorqueException
criteria
- The criteria to use.
TorqueException
public static void doDelete(Criteria criteria, java.sql.Connection con) throws TorqueException
criteria
- The criteria to use.con
- A Connection.
TorqueException
public static ObjectKey doInsert(Criteria criteria) throws TorqueException
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.
criteria
- Object containing values to insert.
TorqueException
public static ObjectKey doInsert(Criteria criteria, java.sql.Connection con) throws TorqueException
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.
criteria
- Object containing values to insert.con
- A Connection.
TorqueException
private static void insertOrUpdateRecord(com.workingdogs.village.Record rec, java.lang.String tableName, Criteria criteria) throws TorqueException
rec
- A Record.tableName
- Name of table.criteria
- A Criteria.
TorqueException
static java.lang.String createQueryDisplayString(Criteria criteria) throws TorqueException
criteria
- A Criteria.
TorqueException
- Trouble creating the query string.public static java.lang.String createQueryString(Criteria criteria) throws TorqueException
criteria
- A Criteria.
TorqueException
- Trouble creating the query string.static Query createQuery(Criteria criteria) throws TorqueException
criteria
- A Criteria.
TorqueException
- Trouble creating the query string.public static java.util.List doSelect(Criteria criteria) throws TorqueException
criteria
- A Criteria.
TorqueException
public static java.util.List doSelect(Criteria criteria, java.sql.Connection con) throws TorqueException
criteria
- A Criteria.con
- A Connection.
TorqueException
public static java.util.List executeQuery(java.lang.String queryString) throws TorqueException
queryString
- A String with the sql statement to execute.
TorqueException
public static java.util.List executeQuery(java.lang.String queryString, java.lang.String dbName) throws TorqueException
queryString
- A String with the sql statement to execute.dbName
- The database to connect to.
TorqueException
public static java.util.List executeQuery(java.lang.String queryString, java.lang.String dbName, boolean singleRecord) throws TorqueException
queryString
- A String with the sql statement to execute.dbName
- The database to connect to.singleRecord
- Whether or not we want to select only a
single record.
TorqueException
public static java.util.List executeQuery(java.lang.String queryString, boolean singleRecord, java.sql.Connection con) throws TorqueException
queryString
- A String with the sql statement to execute.singleRecord
- Whether or not we want to select only a
single record.con
- A Connection.
TorqueException
public static java.util.List executeQuery(java.lang.String queryString, int start, int numberOfResults, java.lang.String dbName, boolean singleRecord) throws TorqueException
queryString
- A String with the sql statement to execute.start
- The first row to return.numberOfResults
- The number of rows to return.dbName
- The database to connect to.singleRecord
- Whether or not we want to select only a
single record.
TorqueException
public static java.util.List executeQuery(java.lang.String queryString, int start, int numberOfResults, boolean singleRecord, java.sql.Connection con) throws TorqueException
queryString
- A String with the sql statement to execute.start
- The first row to return.numberOfResults
- The number of rows to return.singleRecord
- Whether or not we want to select only a
single record.con
- A Connection.
TorqueException
public static java.util.List getSelectResults(com.workingdogs.village.QueryDataSet qds) throws TorqueException
TorqueException
getSelectResults(QueryDataSet, int, int, boolean)
public static java.util.List getSelectResults(com.workingdogs.village.QueryDataSet qds, boolean singleRecord) throws TorqueException
TorqueException
getSelectResults(QueryDataSet, int, int, boolean)
public static java.util.List getSelectResults(com.workingdogs.village.QueryDataSet qds, int numberOfResults, boolean singleRecord) throws TorqueException
TorqueException
getSelectResults(QueryDataSet, int, int, boolean)
public static java.util.List getSelectResults(com.workingdogs.village.QueryDataSet qds, int start, int numberOfResults, boolean singleRecord) throws TorqueException
qds
- The QueryDataSet
to extract results
from.start
- The index from which to start retrieving
Record
objects from the data set.numberOfResults
- The number of results to return (or
-1
for all results).singleRecord
- Whether or not we want to select only a
single record.
List
of Record
objects.
TorqueException
- If any Exception
occurs.private static ColumnMap getPrimaryKey(Criteria criteria) throws TorqueException
criteria
- A Criteria.
TorqueException
public static void doUpdate(Criteria updateValues) throws TorqueException
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).
updateValues
- A Criteria object containing values used in
set clause.
TorqueException
public static void doUpdate(Criteria updateValues, java.sql.Connection con) throws TorqueException
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).
updateValues
- A Criteria object containing values used in
set clause.con
- A Connection.
TorqueException
public static void doUpdate(Criteria selectCriteria, Criteria updateValues) throws TorqueException
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...
selectCriteria
- A Criteria object containing values used in where
clause.updateValues
- A Criteria object containing values used in set
clause.
TorqueException
public static void doUpdate(Criteria selectCriteria, Criteria updateValues, java.sql.Connection con) throws TorqueException
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.
selectCriteria
- A Criteria object containing values used in where
clause.updateValues
- A Criteria object containing values used in set
clause.con
- A Connection.
TorqueException
public static int executeStatement(java.lang.String stmt) throws TorqueException
stmt
- A String with the sql statement to execute.
TorqueException
public static int executeStatement(java.lang.String stmt, java.lang.String dbName) throws TorqueException
stmt
- A String with the sql statement to execute.dbName
- Name of database to connect to.
TorqueException
- a generic exception.public static int executeStatement(java.lang.String stmt, java.sql.Connection con) throws TorqueException
stmt
- A String with the sql statement to execute.con
- A Connection.
TorqueException
protected static void handleMultipleRecords(com.workingdogs.village.DataSet ds) throws TorqueException
ds
- The DataSet which contains multiple records.
TorqueException
- Couldn't handle multiple records.protected static void handleMultiple(com.workingdogs.village.DataSet ds) throws TorqueException
TorqueException
public static MapBuilder getMapBuilder() throws TorqueException
TorqueException
public static MapBuilder getMapBuilder(java.lang.String name)
public static java.util.List doPSSelect(Criteria criteria, java.sql.Connection con) throws TorqueException
select
using a PreparedStatement.
Note: this method does not handle null criteria values.
TorqueException
- Error performing database query.public static java.util.List doPSSelect(Criteria criteria) throws TorqueException
TorqueException
public static void createPreparedStatement(Criteria criteria, java.lang.StringBuffer queryString, java.util.List params) throws TorqueException
TorqueException
private static void throwMalformedColumnNameException(java.lang.String criteriaPhrase, java.lang.String columnName) throws TorqueException
Malformed column name in Criteria [criteriaPhrase]:
'[columnName]' is not of the form 'table.column'
criteriaPhrase
- a String, one of "select", "join", or "order by"columnName
- a String containing the offending column name
TorqueException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |