Package org.apache.torque.util
Class AbstractPeerImpl<T extends ObjectModel>
- java.lang.Object
-
- org.apache.torque.util.BasePeerImpl<T>
-
- org.apache.torque.util.AbstractPeerImpl<T>
-
- Type Parameters:
T
- The data object class for this Peer.
- All Implemented Interfaces:
Serializable
public abstract class AbstractPeerImpl<T extends ObjectModel> extends BasePeerImpl<T>
This is an abstract layer for all generated peer classes that implements several convenience methods that otherwise would have to be generated.- Version:
- $Id: BasePeerImpl.java 1701342 2015-09-05 02:18:04Z tfischer $
- Author:
- Thomas Vandahl
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractPeerImpl()
Default constructorAbstractPeerImpl(RecordMapper<T> recordMapper, TableMap tableMap, String databaseName)
Constructor providing the objects to be injected as parameters.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract ColumnValues
buildColumnValues(T obj)
Returns the contents of the object as ColumnValues object.Criteria
buildCriteria(ObjectKey<?> pk)
Build a Criteria object which selects all objects which have a given primary key.abstract Criteria
buildCriteria(T obj)
Build a Criteria object from the data object for this peer.abstract Criteria
buildSelectCriteria(T obj)
Build a Criteria object from the data object for this peer, skipping all binary columns.int
doDelete(ObjectKey<?> pk)
Deletes a row in the database.int
doDelete(ObjectKey<?> pk, Connection con)
Deletes a row in the database.ObjectKey<?>
doInsert(ColumnValues columnValues, Connection con)
Method to do inserts.void
doInsert(T obj)
Method to do insertsvoid
doInsert(T obj, Connection con)
Method to do inserts.List<T>
doSelect(T obj)
Selects objects from the database which have the same content as the passed object.T
doSelectSingleRecord(T obj)
Selects at most one object from the database which has the same content as the passed object.int
doUpdate(T obj)
Updates an object in the database.int
doUpdate(T obj, Connection con)
Updates an object in the database.-
Methods inherited from class org.apache.torque.util.BasePeerImpl
addSelectColumns, correctBooleans, correctBooleans, doDelete, doDelete, doInsert, doInsert, doInsert, doInsert, doInsert, doSelect, doSelect, doSelect, doSelect, doSelect, doSelect, doSelect, doSelect, doSelectAsStream, doSelectAsStream, doSelectAsStream, doSelectAsStream, doSelectSingleRecord, doSelectSingleRecord, doSelectSingleRecord, doSelectSingleRecord, doUpdate, doUpdate, doUpdate, doUpdate, executeStatement, executeStatement, executeStatement, executeStatement, executeStatement, executeStatement, executeStatement, getDatabaseName, getRecordMapper, getTableMap, setDatabaseName, setDbName, setRecordMapper, setTableMap
-
-
-
-
Constructor Detail
-
AbstractPeerImpl
public AbstractPeerImpl()
Default constructor
-
AbstractPeerImpl
public AbstractPeerImpl(RecordMapper<T> recordMapper, TableMap tableMap, String databaseName)
Constructor providing the objects to be injected as parameters.- Parameters:
recordMapper
- a record mapper to map JDBC result sets to objectstableMap
- the default table mapdatabaseName
- the name of the database
-
-
Method Detail
-
buildCriteria
public abstract Criteria buildCriteria(T obj)
Build a Criteria object from the data object for this peer.- Parameters:
obj
- the object to build the criteria from, not null.- Returns:
- Criteria object
-
buildSelectCriteria
public abstract Criteria buildSelectCriteria(T obj)
Build a Criteria object from the data object for this peer, skipping all binary columns.- Parameters:
obj
- the object to build the criteria from, not null.- Returns:
- Criteria object
-
buildCriteria
public Criteria buildCriteria(ObjectKey<?> pk)
Build a Criteria object which selects all objects which have a given primary key. This method should never be called because if the table has a primary key, it must be overridden in the generated code.- Parameters:
pk
- the primary key value to build the criteria from, not null.- Returns:
- Criteria object
-
buildColumnValues
public abstract ColumnValues buildColumnValues(T obj) throws TorqueException
Returns the contents of the object as ColumnValues object. Primary key columns which are generated on insertion are not added to the returned object if they still have their initial value. Also, columns which have the useDatabaseDefaultValue flag set to true are also not added to the returned object if they still have their initial value.- Parameters:
obj
- the object to build the column values from- Returns:
- ColumnValues object
- Throws:
TorqueException
- if the table map cannot be retrieved (should not happen).
-
doSelect
public List<T> doSelect(T obj) throws TorqueException
Selects objects from the database which have the same content as the passed object.- Parameters:
obj
- the data object- Returns:
- The list of selected objects, not null.
- Throws:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
doSelectSingleRecord
public T doSelectSingleRecord(T obj) throws TorqueException
Selects at most one object from the database which has the same content as the passed object.- Parameters:
obj
- the data object- Returns:
- the selected Object, or null if no object was selected.
- Throws:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
doInsert
public ObjectKey<?> doInsert(ColumnValues columnValues, Connection con) throws TorqueException
Method to do inserts. This method is to be used during a transaction, otherwise use the doInsert(Criteria) method.- Overrides:
doInsert
in classBasePeerImpl<T extends ObjectModel>
- Parameters:
columnValues
- the values to insert.con
- the connection to use, not null.- Returns:
- the primary key of the inserted row or null if the table has no primary key
- Throws:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
doInsert
public void doInsert(T obj) throws TorqueException
Method to do inserts- Parameters:
obj
- the data object- Throws:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
doInsert
public void doInsert(T obj, Connection con) throws TorqueException
Method to do inserts. This method is to be used during a transaction, otherwise use the doInsert(T) method. It will take care of the connection details internally.- Parameters:
obj
- the data object to insert into the database.con
- the connection to use- Throws:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
doUpdate
public int doUpdate(T obj) throws TorqueException
Updates an object in the database. The primary key is used to identify the object to update.- Parameters:
obj
- the data object to update in the database.- Returns:
- the number of affected rows.
- Throws:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
doUpdate
public int doUpdate(T obj, Connection con) throws TorqueException
Updates an object in the database. The primary key is used to identify the object to update. This method is to be used during a transaction, otherwise the doUpdate(T) method can be used.- Parameters:
obj
- the data object to update in the database.con
- the connection to use, not null.- Returns:
- the number of affected rows.
- Throws:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
doDelete
public int doDelete(ObjectKey<?> pk) throws TorqueException
Deletes a row in the database.- Parameters:
pk
- the ObjectKey that identifies the row to delete.- Returns:
- the number of deleted rows.
- Throws:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
doDelete
public int doDelete(ObjectKey<?> pk, Connection con) throws TorqueException
Deletes a row in the database. This method is to be used during a transaction, otherwise use the doDelete(ObjectKey) method.- Parameters:
pk
- the ObjectKey that identifies the row to delete.con
- the connection to use for deleting, not null.- Returns:
- the number of deleted rows.
- Throws:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
-