ch.elca.el4j.services.persistence.generic.dao
Interface GenericDao<T>

Type Parameters:
T - The generic type of the domain class the DAO is responsible for
All Known Subinterfaces:
ConvenienceGenericDao<T,ID>, ConvenienceGenericHibernateDao<T,ID>, ConvenienceIdentityFixedDao<T,ID>, IdentityFixedDao<T>
All Known Implementing Classes:
GenericHibernateDao

public interface GenericDao<T>

Interface for generic DAOs. It is the interface that implements the DDD-Book's (http://www.domaindrivendesign.org/) Repository pattern. This interface is implemented generically and it can be extended in case you need more specific methods. Based on an idea from the Hibernate website. This is the canonical form of this interface. We recommend it when a generic DAO is used in tools (to make the contract minimal). For direct programmer-usage we recommend to use the convenience subclasses (@link ConvenienceGenericDao).

Author:
Philipp Oser (POS), Alex Mathey (AMA), Adrian Moos (AMS), Martin Zeltner (MZE)
File-location:
GenericDao
Last check-in date:
2009-08-17 14:34:48 +0200 (Mo, 17. Aug 2009) by swismer for revision 3902

Method Summary
 void delete(Collection<T> entities)
          Deletes the given domain objects.
 List<T> findByQuery(QueryObject q)
          Executes a query based on a given query object.
 int findCountByQuery(QueryObject query)
          Count number of results of a search.
 Class<T> getPersistentClass()
          Needed because the Java generics throw away this type information.
 T refresh(T entity)
          Re-reads the state of the given domain object from the underlying store.
 T reload(T entity)
          Re-reads the state of the given domain object from the undermost store (eg. the database).
 T saveOrUpdate(T entity)
          Saves or updates the given domain object.
 void setPersistentClass(Class<T> c)
          New: this callback is in general no longer required (the constructor should figure the type out itself).
 

Method Detail

getPersistentClass

Class<T> getPersistentClass()
Needed because the Java generics throw away this type information.

Returns:
Returns the domain class this DAO is responsible for.

setPersistentClass

void setPersistentClass(Class<T> c)
New: this callback is in general no longer required (the constructor should figure the type out itself).

Parameters:
c - Mandatory. The domain class this DAO is responsible for.

findByQuery

List<T> findByQuery(QueryObject q)
                    throws DataAccessException
Executes a query based on a given query object. This method may also support paging (see javadoc of implementing class).

Parameters:
q - The search query object
Returns:
A list containing 0 or more domain objects
Throws:
DataAccessException - If general data access problem occurred

findCountByQuery

int findCountByQuery(QueryObject query)
                     throws DataAccessException
Count number of results of a search.

Parameters:
query - The search query object
Returns:
the number of results that this query could at most return.
Throws:
DataAccessException

refresh

T refresh(T entity)
          throws DataAccessException,
                 DataRetrievalFailureException
Re-reads the state of the given domain object from the underlying store.

Parameters:
entity - The domain object to re-read the state of
Returns:
The refreshed entity
Throws:
DataAccessException - If general data access problem occurred
DataRetrievalFailureException - If domain object could not be re-read

reload

T reload(T entity)
         throws DataAccessException,
                DataRetrievalFailureException
Re-reads the state of the given domain object from the undermost store (eg. the database).

Parameters:
entity - The domain object to re-load the state of
Returns:
The reloaded entity
Throws:
DataAccessException - If general data access problem occurred
DataRetrievalFailureException - If domain object could not be re-loaded

saveOrUpdate

T saveOrUpdate(T entity)
               throws DataAccessException,
                      DataIntegrityViolationException,
                      OptimisticLockingFailureException
Saves or updates the given domain object.

Parameters:
entity - The domain object to save or update
Returns:
The saved or updated domain object
Throws:
DataAccessException - If general data access problem occurred
DataIntegrityViolationException - If domain object could not be inserted due to a data integrity violation
OptimisticLockingFailureException - If domain object has been modified/deleted in the meantime

delete

void delete(Collection<T> entities)
            throws OptimisticLockingFailureException,
                   DataAccessException
Deletes the given domain objects. This method executed in a single transaction (by default with the Required semantics).

Parameters:
entities - The domain objects to delete.
Throws:
DataAccessException - If general data access problem occurred
OptimisticLockingFailureException - If domain object has been modified/deleted in the meantime


Copyright © 2005-2011 ELCA. All Rights Reserved.