|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.torque.util.BasePeerImpl<T>
T
- The data object class for this Peer.public class BasePeerImpl<T>
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.
Constructor Summary | |
---|---|
BasePeerImpl()
Default constructor |
|
BasePeerImpl(RecordMapper<T> recordMapper,
TableMap tableMap,
String databaseName)
Constructor providing the objects to be injected as parameters. |
Method Summary | ||
---|---|---|
void |
addSelectColumns(Criteria criteria)
Add all the columns needed to create a new object. |
|
void |
addSelectColumns(Criteria criteria)
Deprecated. Please use addSelectColumns( org.apache.torque.criteria.Criteria). This method will be removed in a future version of Torque. |
|
void |
correctBooleans(ColumnValues columnValues)
Checks all columns in the criteria to see whether booleanchar and booleanint columns are queried with a boolean. |
|
void |
correctBooleans(Criteria criteria)
Deprecated. Please use correctBooleans( org.apache.torque.criteria.Criteria). This method will be removed in a future version of Torque. |
|
void |
correctBooleans(Criteria criteria)
Checks all columns in the criteria to see whether booleanchar and booleanint columns are queried with a boolean. |
|
int |
deleteAll(Connection con,
String table,
String column,
int value)
Deprecated. The value is not SQL escaped. Better use doDelete(Criteria, String, Connection) for automatic escaping and more flexibility. This method will be removed in a future version of Torque. |
|
int |
deleteAll(String table,
String column,
int value)
Deprecated. The value is not SQL escaped. Better use doDelete(Criteria, String) for automatic escaping and more flexibility. This method will be removed in a future version of Torque. |
|
int |
doDelete(Criteria criteria)
Deletes rows from a database table. |
|
protected int |
doDelete(Criteria criteria)
Deprecated. This method causes unexpected results when joins are used. Please use doDelete( org.apache.torque.criteria.Criteria, TableMap). This method will be removed in a future version of Torque. |
|
int |
doDelete(Criteria criteria,
Connection connection)
Deletes rows from a table. |
|
protected int |
doDelete(Criteria criteria,
Connection con)
Deprecated. This method causes unexpected results when joins are used. Please use doDelete( org.apache.torque.criteria.Criteria, TableMap, Connection). This method will be removed in a future version of Torque. |
|
ObjectKey |
doInsert(ColumnValues insertValues)
Inserts a record into a database table. |
|
ObjectKey |
doInsert(ColumnValues insertValues,
Connection connection)
Inserts a record into a database table. |
|
List<T> |
doSelect(Criteria criteria)
Deprecated. Please use doSelect(org.apache.torque.criteria.Criteria). This method will be removed in a future version of Torque. |
|
List<T> |
doSelect(Criteria criteria)
Selects objects from a database. |
|
List<T> |
doSelect(Criteria criteria,
Connection connection)
Deprecated. Please use doSelect(org.apache.torque.criteria.Criteria, Connection). This method will be removed in a future version of Torque. |
|
List<T> |
doSelect(Criteria criteria,
Connection connection)
Selects objects from a database within a transaction. |
|
|
doSelect(Criteria criteria,
RecordMapper<TT> mapper)
Deprecated. Please use doSelect(org.apache.torque.criteria.Criteria, RecordMapper). This method will be removed in a future version of Torque. |
|
|
doSelect(Criteria criteria,
RecordMapper<TT> mapper)
Selects rows from a database an maps them to objects. |
|
|
doSelect(Criteria criteria,
RecordMapper<TT> mapper,
Connection connection)
Deprecated. Please use doSelect(org.apache.torque.criteria.Criteria, RecordMapper, Connection). This method will be removed in a future version of Torque. |
|
|
doSelect(Criteria criteria,
RecordMapper<TT> mapper,
Connection connection)
Performs a SQL select using a PreparedStatement. |
|
List<T> |
doSelect(String query)
Selects rows from a database an maps them to objects. |
|
|
doSelect(String query,
RecordMapper<TT> mapper,
String dbName)
Selects rows from a database an maps them to objects. |
|
|
doSelect(String query,
RecordMapper<TT> mapper,
String dbName,
Connection connection)
Selects rows from a database an maps them to objects. |
|
List<T> |
doSelect(String query,
String dbName,
Connection connection)
Selects rows from a database an maps them to objects. |
|
T |
doSelectSingleRecord(Criteria criteria)
Selects at most one object from a database. |
|
T |
doSelectSingleRecord(Criteria criteria,
Connection connection)
Selects at most one object from a database within a transaction. |
|
|
doSelectSingleRecord(Criteria criteria,
RecordMapper<TT> mapper)
Selects at most a single row from a database an maps them to objects. |
|
|
doSelectSingleRecord(Criteria criteria,
RecordMapper<TT> mapper,
Connection connection)
Selects at most a single row from a database an maps them to objects. |
|
int |
doUpdate(ColumnValues updateValues)
Convenience method used to update rows in the DB. |
|
int |
doUpdate(ColumnValues updateValues,
Connection connection)
Convenience method used to update rows in the DB. |
|
int |
doUpdate(Criteria selectCriteria,
ColumnValues updateValues)
Deprecated. Please use doUpdate( org.apache.torque.criteria.Criteria, ColumnValues). This method will be removed in a future version of Torque. |
|
int |
doUpdate(Criteria selectCriteria,
ColumnValues updateValues)
Executes an update against the database. |
|
int |
doUpdate(Criteria criteria,
ColumnValues updateValues,
Connection connection)
Deprecated. Please use doUpdate(org.apache.torque.criteria.Criteria, ColumnValues, Connection). This method will be removed in a future version of Torque. |
|
int |
doUpdate(Criteria criteria,
ColumnValues updateValues,
Connection connection)
Executes an update against the database. |
|
int |
executeStatement(String statementString)
Utility method which executes a given sql statement. |
|
int |
executeStatement(String statementString,
String dbName)
Utility method which executes a given sql statement. |
|
int |
executeStatement(String statementString,
String dbName,
Connection con)
Utility method which executes a given sql statement. |
|
String |
getDatabaseName()
Get the database name for this instance. |
|
RecordMapper<T> |
getRecordMapper()
Get the record mapper for this instance. |
|
TableMap |
getTableMap()
Get the default table map for this instance. |
|
String[] |
initCriteriaKeys(String tableName,
String[] columnNames)
Deprecated. This method is not used any more and will be removed in a future version of Torque. |
|
List<T> |
resultSet2Objects(ResultSet resultSet,
Adapter adapter)
Get the list of objects from a ResultSet. |
|
void |
setDatabaseName(String databaseName)
Set the database name for this instance. |
|
protected void |
setDbName(Criteria crit)
Sets the database name in the passed criteria to the table's default, if it is not already set. |
|
protected void |
setDbName(Criteria crit)
Deprecated. Please use addSelectColumns( org.apache.torque.criteria.Criteria). This method will be removed in a future version of Torque. |
|
void |
setRecordMapper(RecordMapper<T> recordMapper)
Set the record mapper for this instance. |
|
void |
setTableMap(TableMap tableMap)
Set the default table map for this instance. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BasePeerImpl()
public BasePeerImpl(RecordMapper<T> recordMapper, TableMap tableMap, String databaseName)
recordMapper
- a record mapper to map JDBC result sets to objectstableMap
- the default table mapdatabaseName
- the name of the databaseMethod Detail |
---|
public void setRecordMapper(RecordMapper<T> recordMapper)
recordMapper
- the recordMapper to setpublic RecordMapper<T> getRecordMapper() throws TorqueException
TorqueException
public void setTableMap(TableMap tableMap)
tableMap
- the tableMap to setpublic TableMap getTableMap() throws TorqueException
TorqueException
public void setDatabaseName(String databaseName)
databaseName
- the databaseName to setpublic String getDatabaseName() throws TorqueException
TorqueException
public List<T> resultSet2Objects(ResultSet resultSet, Adapter adapter) throws TorqueException
resultSet
- the ResultSet to extract the objects from.the
- database adapter of the database for the result set,
or null if the adapter is unknown.
TorqueException
- If the mapping fails.@Deprecated public String[] initCriteriaKeys(String tableName, String[] columnNames)
tableName
- Name of table.columnNames
- A String[].
@Deprecated public int deleteAll(Connection con, String table, 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
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.@Deprecated public int deleteAll(String table, 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
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.public int doDelete(Criteria criteria) throws TorqueException
criteria
- defines the rows to be deleted, not null.
TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.public int doDelete(Criteria criteria, Connection connection) throws TorqueException
criteria
- defines the rows to be deleted, not null.connection
- the connection to use, not null.
TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.@Deprecated protected int doDelete(Criteria criteria) throws TorqueException
criteria
- The criteria to use.
TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.@Deprecated protected int doDelete(Criteria criteria, Connection con) throws TorqueException
criteria
- The criteria to use.con
- the Connection to be used for deleting.
TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.public ObjectKey doInsert(ColumnValues insertValues) throws TorqueException
If the primary key is included in Criteria, then that value will be used to insert the row.
Otherwise, if the primary key can be generated automatically, the generated key will be used for the insert and will be returned.
If no value is given for the primary key is defined and it cannot be generated automatically or the table has no primary key, the values will be inserted as specified and null will be returned.
insertValues
- Contains the values to insert, not null.
TorqueException
- if a database error occurs.public ObjectKey doInsert(ColumnValues insertValues, Connection connection) throws TorqueException
If the primary key is included in Criteria, then that value will be used to insert the row.
Otherwise, if the primary key can be generated automatically, the generated key will be used for the insert and will be returned.
If no value is given for the primary key is defined and it cannot be generated automatically or the table has no primary key, the values will be inserted as specified and null will be returned.
insertValues
- Contains the values to insert, not null.connection
- the connection to use for the insert, not null.
TorqueException
- if a database error occurs.public void addSelectColumns(Criteria criteria)
criteria
- the Criteria to which the select columns should
be added.@Deprecated public void addSelectColumns(Criteria criteria)
criteria
- the Criteria to which the select columns should
be added.@Deprecated public List<T> doSelect(Criteria criteria) throws TorqueException
criteria
- object used to create the SELECT statement.
TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.public List<T> doSelect(Criteria criteria) throws TorqueException
criteria
- object used to create the SELECT statement.
TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.@Deprecated public List<T> doSelect(Criteria criteria, Connection connection) throws TorqueException
criteria
- object used to create the SELECT statement.connection
- the connection to use, not null.
TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.public List<T> doSelect(Criteria criteria, Connection connection) throws TorqueException
criteria
- object used to create the SELECT statement.connection
- the connection to use, not null.
TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.public T doSelectSingleRecord(Criteria criteria) throws TorqueException
criteria
- object used to create the SELECT statement.
TorqueException
- If more than one record is selected or if
an error occurs when processing the query.public T doSelectSingleRecord(Criteria criteria, Connection connection) throws TorqueException
criteria
- object used to create the SELECT statement.connection
- the connection holding the transaction, not null.
TorqueException
- If more than one record is selected or if
an error occurs when processing the query.@Deprecated public <TT> List<TT> doSelect(Criteria criteria, RecordMapper<TT> mapper) throws TorqueException
criteria
- A Criteria specifying the records to select, not null.mapper
- The mapper creating the objects from the resultSet,
not null.
TorqueException
- if querying the database fails.public <TT> List<TT> doSelect(Criteria criteria, RecordMapper<TT> mapper) throws TorqueException
criteria
- A Criteria specifying the records to select, not null.mapper
- The mapper creating the objects from the resultSet,
not null.
TorqueException
- if querying the database fails.public List<T> doSelect(String query) throws TorqueException
query
- the sql query to execute, not null.
TorqueException
- if querying the database fails.public List<T> doSelect(String query, String dbName, Connection connection) throws TorqueException
query
- the SQL Query to execute, not null.dbName
- The name of the database to select from,
or null for the default DB.connection
- the database connection, not null.
TorqueException
- if querying the database fails.public <TT> List<TT> doSelect(String query, RecordMapper<TT> mapper, String dbName) throws TorqueException
query
- the sql query to execute, not null.mapper
- The mapper creating the objects from the resultSet,
not null.dbName
- The name of the database to create the connection for,
or null for the default DB.
TorqueException
- if querying the database fails.public <TT> List<TT> doSelect(String query, RecordMapper<TT> mapper, String dbName, Connection connection) throws TorqueException
query
- the SQL Query to execute, not null.mapper
- The mapper creating the objects from the resultSet,
not null.dbName
- The name of the database to create the connection for,
or null for the default DB.connection
- the database connection, not null.
TorqueException
- if querying the database fails.@Deprecated public <TT> List<TT> doSelect(Criteria criteria, RecordMapper<TT> mapper, Connection connection) throws TorqueException
select
using a PreparedStatement.
criteria
- A Criteria specifying the records to select, not null.mapper
- The mapper creating the objects from the resultSet,
not null.connection
- the database connection for selecting records,
not null.
TorqueException
- Error performing database query.public <TT> List<TT> doSelect(Criteria criteria, RecordMapper<TT> mapper, Connection connection) throws TorqueException
select
using a PreparedStatement.
criteria
- A Criteria specifying the records to select, not null.mapper
- The mapper creating the objects from the resultSet,
not null.connection
- the database connection for selecting records,
not null.
TorqueException
- Error performing database query.public <TT> TT doSelectSingleRecord(Criteria criteria, RecordMapper<TT> mapper) throws TorqueException
criteria
- A Criteria specifying the records to select, not null.mapper
- The mapper creating the objects from the resultSet,
not null.
TorqueException
- if querying the database fails.public <TT> TT doSelectSingleRecord(Criteria criteria, RecordMapper<TT> mapper, Connection connection) throws TorqueException
criteria
- A Criteria specifying the records to select, not null.mapper
- The mapper creating the objects from the resultSet,
not null.connection
- the database connection, not null.
TorqueException
- if querying the database fails.public int doUpdate(ColumnValues updateValues) throws TorqueException
Use this method for performing an update of the kind:
"WHERE primary_key_id = someValue"
To perform an update on a table with multiple primary keys or an update with non-primary key fields in the WHERE clause, use doUpdate(ColumnValues, Criteria).
updateValues
- Which columns to update with which values
for which primary key value, not null.
TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.public int doUpdate(ColumnValues updateValues, Connection connection) throws TorqueException
Use this method for performing an update of the kind:
"WHERE primary_key_id = someValue"
To perform an update on a table with multiple primary keys or an update with non-primary key fields in the WHERE clause, use doUpdate(ColumnValues, Criteria, Connection).
updateValues
- Which columns to update with which values
for which primary key value, not null.connection
- the database connection to use.
TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.@Deprecated public int doUpdate(Criteria selectCriteria, ColumnValues updateValues) throws TorqueException
criteria
and updated using the values
in updateValues
.
selectCriteria
- selects which rows of which table
should be updated, not null.updateValues
- Which columns to update with which values, not null.
TorqueException
- if updating fails.public int doUpdate(Criteria selectCriteria, ColumnValues updateValues) throws TorqueException
criteria
and updated using the values
in updateValues
.
selectCriteria
- selects which rows of which table
should be updated, not null.updateValues
- Which columns to update with which values, not null.
TorqueException
- if updating fails.@Deprecated public int doUpdate(Criteria criteria, ColumnValues updateValues, Connection connection) throws TorqueException
criteria
and updated using the values
in updateValues
.
criteria
- selects which rows of which table should be updated.updateValues
- Which columns to update with which values, not null.connection
- the database connection to use, not null.
TorqueException
- if updating fails.public int doUpdate(Criteria criteria, ColumnValues updateValues, Connection connection) throws TorqueException
criteria
and updated using the values
in updateValues
.
criteria
- selects which rows of which table should be updated.updateValues
- Which columns to update with which values, not null.connection
- the database connection to use, not null.
TorqueException
- if updating fails.public int executeStatement(String statementString) throws TorqueException
statementString
- A String with the sql statement to execute.
TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.public int executeStatement(String statementString, String dbName) throws TorqueException
statementString
- A String with the sql statement to execute.dbName
- The name of the database to execute the statement against,
or null for the default DB.
TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.public int executeStatement(String statementString, String dbName, Connection con) throws TorqueException
statementString
- A String with the sql statement to execute.dbName
- The name of the database to execute the statement against,
or null for the default DB.con
- The database connection to use.
TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.@Deprecated public void correctBooleans(Criteria criteria) throws TorqueException
criteria
- the criteria in which the boolean values should be
corrected.
TorqueException
- if the database map for the criteria cannot be
obtained.public void correctBooleans(Criteria criteria) throws TorqueException
criteria
- The criteria to be checked for booleanint and booleanchar
columns.
TorqueException
- if the database map for the criteria cannot be
retrieved.public void correctBooleans(ColumnValues columnValues) throws TorqueException
columnValues
- The value to be checked for booleanint
and booleanchar columns.
TorqueException
- if the database map for the criteria cannot be
retrieved.protected void setDbName(Criteria crit) throws TorqueException
crit
- the criteria to set the database name in, not null.
TorqueException
@Deprecated protected void setDbName(Criteria crit) throws TorqueException
crit
- the criteria to set the database name in, not null.
TorqueException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |