Arch4J 1.1

org.arch4j.persistence.domainmapper
Class BaseDomainMapper

java.lang.Object
  |
  +--org.arch4j.persistence.domainmapper.BaseDomainMapper

public abstract class BaseDomainMapper
extends Object

Abstract super class for all domain mappers. Provides common create, find, update and delete functionality based on the template methods defined.

Subclasses should implement public find methods that use the base find methods, but return specific subclasses of BaseDomain.


Nested Class Summary
 class BaseDomainMapper.BaseDomainResultSetVisitor
          Database result set visitor used to retrieve a list of domain objects.
 
Field Summary
protected static String ID
          The constant representing the database field name for a primary identifier.
protected static String VERSION
          The constant representing the database field name for a version, which is used for concurrency.
 
Constructor Summary
BaseDomainMapper()
          Default constructor
 
Method Summary
protected abstract  void addFields(BaseDomain aDomainObject, UpdatableQuery updatableQuery)
          Add field names and values to the given query, which will be used when inserting or updating the given domain object.
 List baseFind(BaseDomain parent, String foreignKeyFieldName)
          Find a collection of domain objects for the given parent object.
 List baseFind(Condition where)
          Creates a select statement using the given condition and then executes the statement to return a list of domain objects.
protected  BaseDomain baseFind(Condition where, String orderByFieldName, boolean ascending)
          Finds a domain object ...
 List baseFind(Select select)
          Executes the select statement and returns a list of domain objects built from the result set.
protected  BaseDomain baseFind(Serializable anId)
          Read the domain object of the given Id.
protected abstract  BaseDomain build(Serializable id, long version, ResultSet resultSet)
          Build a domain object from the result set.
 BaseDomain create(BaseDomain aDomainObject)
          Map the domain to a new record.
 void delete(BaseDomain aDomainObject)
          Delete the domain objects contents from the database.
 void delete(Condition where)
          Delete domain objects from the database that match the given condition.
 void executeTransaction(AtomicOperationCommand aCommand)
          Use this method to bound multiple database operations which need to execute as one atomic operation.
 boolean exists(BaseDomain aDomainObject)
          Returns whether or not the given domain object exists in the database.
 List findAll()
          Returns a list containing all domain objects mapped by the receiver.
 List findAll(String orderByFieldName, boolean ascending)
          Returns a list containing all domain objects mapped by the receiver, and sorted according to the given field name.
protected  Serializable getId(BaseDomain aDomainObject)
          Return the given domain object's ID, or null if the domain object is null.
protected abstract  String getTableName()
          Returns the table name that subclassed mappers represent.
 void markTransactionForRollback()
          Marks the open transaction for rollback.
 BaseDomain save(BaseDomain aDomainObject)
          Test for database existence of the given domain object.
 BaseDomain update(BaseDomain aDomainObject)
          Update the domain objects contents in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID

protected static final String ID
The constant representing the database field name for a primary identifier.

See Also:
Constant Field Values

VERSION

protected static final String VERSION
The constant representing the database field name for a version, which is used for concurrency.

See Also:
Constant Field Values
Constructor Detail

BaseDomainMapper

public BaseDomainMapper()
Default constructor

Method Detail

getTableName

protected abstract String getTableName()
Returns the table name that subclassed mappers represent.

Returns:
The table name that subclassed mappers represent.

build

protected abstract BaseDomain build(Serializable id,
                                    long version,
                                    ResultSet resultSet)
                             throws DataAccessException,
                                    SQLException
Build a domain object from the result set. Implementors of this method will construct a new domain object and populate the domain specific fields.

Parameters:
id - The primary identifier for the domain object.
version - The concurrency version for the domain object.
resultSet - The rest of the data to use to build the domain object.
Returns:
An instance of BaseDomain, filled in with data from the given arguments.
Throws:
DataAccessException
SQLException

addFields

protected abstract void addFields(BaseDomain aDomainObject,
                                  UpdatableQuery updatableQuery)
Add field names and values to the given query, which will be used when inserting or updating the given domain object.

Parameters:
aDomainObject - The domain object to save.
updatableQuery - The query object that is collecting the domain object fields for saving.

getId

protected Serializable getId(BaseDomain aDomainObject)
Return the given domain object's ID, or null if the domain object is null.

Parameters:
aDomainObject - The domain object whose ID is needed.
Returns:
The ID or null.

create

public BaseDomain create(BaseDomain aDomainObject)
                  throws DataAccessException
Map the domain to a new record.

Parameters:
aDomainObject - The domain object to save.
Returns:
The domain object.
Throws:
DataAccessException

baseFind

public List baseFind(Select select)
              throws DataAccessException
Executes the select statement and returns a list of domain objects built from the result set.

Parameters:
select - The select statement to use to find the domain objects.
Returns:
A list of domain objects.
Throws:
DataAccessException

baseFind

public List baseFind(Condition where)
              throws DataAccessException
Creates a select statement using the given condition and then executes the statement to return a list of domain objects.

Parameters:
where - A where clause condition.
Returns:
A list of domain objects.
Throws:
DataAccessException
See Also:
baseFind(org.arch4j.dataaccess.common.Select)

baseFind

protected BaseDomain baseFind(Serializable anId)
                       throws DataAccessException
Read the domain object of the given Id.

Parameters:
anId - The primary key identifier for the domain object to find.
Returns:
The domain object of the given Id, or null if it does not exist.
DataAccessException

baseFind

public List baseFind(BaseDomain parent,
                     String foreignKeyFieldName)
              throws DataAccessException
Find a collection of domain objects for the given parent object. This satisfies the one-to-many relationship.

Parameters:
parent - The parent domain object.
foreignKeyFieldName - The name of the field that stores the parent's foreign key.
Returns:
A collection of domain objects.
Throws:
DataAccessException

baseFind

protected BaseDomain baseFind(Condition where,
                              String orderByFieldName,
                              boolean ascending)
                       throws DataAccessException
Finds a domain object ...

Parameters:
where -
orderByFieldName -
ascending -
Returns:
Throws:
DataAccessException

findAll

public List findAll()
             throws DataAccessException
Returns a list containing all domain objects mapped by the receiver.

Returns:
A list of domain objects.
Throws:
DataAccessException
See Also:
baseFind(org.arch4j.dataaccess.common.Select)

findAll

public List findAll(String orderByFieldName,
                    boolean ascending)
             throws DataAccessException
Returns a list containing all domain objects mapped by the receiver, and sorted according to the given field name.

Parameters:
orderByFieldName - The field by which to sort.
ascending - true, if the sort should be ascending.
Returns:
A list of domain objects.
Throws:
DataAccessException

update

public BaseDomain update(BaseDomain aDomainObject)
                  throws DataAccessException,
                         ConcurrencyException
Update the domain objects contents in the database. This method has the side effect of increasing the version number on a successful update.

DataAccessException
ConcurrencyException

delete

public void delete(BaseDomain aDomainObject)
            throws DataAccessException,
                   ConcurrencyException
Delete the domain objects contents from the database.

DataAccessException
ConcurrencyException

delete

public void delete(Condition where)
            throws DataAccessException,
                   ConcurrencyException
Delete domain objects from the database that match the given condition.

Parameters:
where - A where clause condition.
Throws:
DataAccessException
ConcurrencyException

save

public BaseDomain save(BaseDomain aDomainObject)
                throws DataAccessException
Test for database existence of the given domain object. If it exists, update it. Otherwise, insert it.

Parameters:
aDomainObject - The domain object to save.
Returns:
The domain object.
Throws:
DataAccessException

exists

public boolean exists(BaseDomain aDomainObject)
Returns whether or not the given domain object exists in the database. Currently, it checks to see if the version number is greater than zero. Override this method if a database roundtrip is needed.

Parameters:
aDomainObject - The domain object in question.
Returns:
true if the domain object exists in the database.

executeTransaction

public void executeTransaction(AtomicOperationCommand aCommand)
                        throws DataAccessException
Use this method to bound multiple database operations which need to execute as one atomic operation. Typical use is something like the following:

executeTransaction( new AtomicOperationCommand() { public void execute() throws DataAccessException { // do multiple database operations ... } } );

DataAccessException

markTransactionForRollback

public void markTransactionForRollback()
Marks the open transaction for rollback. Once this method is called, the transaction will never commit. It rolls back at the end of the transaction bound.


Arch4J 1.1

Copyright © 2000-2004 SpiderLogic, a service of Wipfli Ullrich Bertelson LLP.