Class AbstractPeerImpl<T extends ObjectModel>

  • 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 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 objects
        tableMap - the default table map
        databaseName - 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 class BasePeerImpl<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.