ch.elca.el4j.services.persistence.hibernate.dao
Interface ConvenienceGenericHibernateDao<T,ID extends Serializable>

Type Parameters:
T - the domain object type
ID - the id of the domain object to find
All Superinterfaces:
ConvenienceGenericDao<T,ID>, GenericDao<T>
All Known Implementing Classes:
GenericHibernateDao

public interface ConvenienceGenericHibernateDao<T,ID extends Serializable>
extends ConvenienceGenericDao<T,ID>

This interface extends ConvenienceGenericDao with query methods using DetachedCriterias.

Author:
Stefan Wismer (SWI)
File-location:
ConvenienceGenericHibernateDao
Last check-in date:
2009-12-11 09:38:50 +0100 (Fr, 11. Dez 2009) by swisswheel for revision 4028

Method Summary
 void deleteAllNoCascade()
          Deletes all available T using a HQL query.
 void deleteNoCascade(Collection<T> entities)
          Deletes the given domain objects using a HQL query.
 List<T> findByCriteria(DetachedCriteria hibernateCriteria)
          Retrieves all the domain objects matching the Hibernate criteria.
 List<T> findByCriteria(DetachedCriteria hibernateCriteria, DataExtent extent)
          Retrieves all the domain objects matching the Hibernate criteria.
 List<T> findByCriteria(DetachedCriteria hibernateCriteria, int firstResult, int maxResults)
          Retrieves a range of domain objects matching the Hibernate criteria.
 List<T> findByCriteria(DetachedCriteria hibernateCriteria, int firstResult, int maxResults, DataExtent extent)
          Retrieves a range of domain objects matching the Hibernate criteria.
 T findById(ID id, boolean lock, DataExtent extent)
          Retrieves a domain object by identifier, optionally obtaining a database lock for this operation.
 T findById(ID id, DataExtent extent)
          Retrieves a domain object by identifier.
 List<T> findByQuery(QueryObject q, DataExtent extent)
          Executes a query based on a given query object.
 int findCountByCriteria(DetachedCriteria hibernateCriteria)
          Retrieves the number of domain objects matching the Hibernate criteria.
 List<T> getAll(DataExtent extent)
          Retrieves all the domain objects of type T.
 Order[] getDefaultOrder()
           
 DetachedCriteria getOrderedCriteria()
          Create a DetachedCriteria what contains default ordering and distinct constraints.
 T refresh(T entity, DataExtent extent)
          Re-reads the state of the given domain object from the underlying store.
 T reload(T entity, DataExtent extent)
          Re-reads the state of the given domain object from the undermost store (eg. the database).
 T saveOrUpdateAndFlush(T entity)
          Convenience method: Executes saveOrUpdate() and flush() on that entity.
 void setDefaultOrder(Order... defaultOrder)
          Set default order of results returned by getAll and findByQuery (not findByCriteria!).
 
Methods inherited from interface ch.elca.el4j.services.persistence.generic.dao.ConvenienceGenericDao
delete, delete, deleteAll, deleteById, findById, findByIdLazy, flush, getAll
 
Methods inherited from interface ch.elca.el4j.services.persistence.generic.dao.GenericDao
delete, findByQuery, findCountByQuery, getPersistentClass, refresh, reload, saveOrUpdate, setPersistentClass
 

Method Detail

saveOrUpdateAndFlush

T saveOrUpdateAndFlush(T entity)
                       throws DataAccessException,
                              DataIntegrityViolationException,
                              OptimisticLockingFailureException
Convenience method: Executes saveOrUpdate() and flush() on that entity.

Parameters:
entity - The domain object to save or update
Returns:
The saved or updated object
Throws:
DataAccessException
DataIntegrityViolationException
OptimisticLockingFailureException

deleteAllNoCascade

void deleteAllNoCascade()
                        throws OptimisticLockingFailureException,
                               DataAccessException
Deletes all available T using a HQL query. This has the benefit of a significant performance improvement in comparison to deleteAll. The tradeoff is that this method does no cascade deletion.

Throws:
OptimisticLockingFailureException - If domain object has been modified/deleted in the meantime
DataAccessException - If general data access problem occurred

deleteNoCascade

void deleteNoCascade(Collection<T> entities)
                     throws DataAccessException,
                            DataIntegrityViolationException,
                            OptimisticLockingFailureException
Deletes the given domain objects using a HQL query. This has the benefit of a significant performance improvement in comparison to delete. The tradeoff is that this method does no cascade deletion.

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

findByCriteria

List<T> findByCriteria(DetachedCriteria hibernateCriteria)
                       throws DataAccessException
Retrieves all the domain objects matching the Hibernate criteria.

Parameters:
hibernateCriteria - the criteria that the result has to fulfill Note: Do not reuse criteria objects! They need to recreated (or cloned e.g. using SerializationUtils.clone()) per execution, due to the suboptimal design of Hibernate's criteria facility.
Returns:
all object that fulfill the criteria
Throws:
DataAccessException
See Also:
HibernateTemplate.findByCriteria(DetachedCriteria)

findByCriteria

List<T> findByCriteria(DetachedCriteria hibernateCriteria,
                       DataExtent extent)
                       throws DataAccessException
Retrieves all the domain objects matching the Hibernate criteria. Loads at least the given extent.

Parameters:
hibernateCriteria - the criteria that the result has to fulfill Note: Do not reuse criteria objects! They need to recreated (or cloned e.g. using SerializationUtils.clone()) per execution, due to the suboptimal design of Hibernate's criteria facility.
extent - the extent in which objects get loaded.
Returns:
all object that fulfill the criteria
Throws:
DataAccessException
See Also:
HibernateTemplate.findByCriteria(DetachedCriteria)

findByCriteria

List<T> findByCriteria(DetachedCriteria hibernateCriteria,
                       int firstResult,
                       int maxResults)
                       throws DataAccessException
Retrieves a range of domain objects matching the Hibernate criteria.

Parameters:
hibernateCriteria - the criteria that the result has to fulfill Note: Do not reuse criteria objects! They need to recreated (or cloned e.g. using SerializationUtils.clone()) per execution, due to the suboptimal design of Hibernate's criteria facility.
firstResult - the index of the first result to return
maxResults - the maximum number of results to return
Returns:
the specified subset of object that fulfill the criteria
Throws:
DataAccessException
See Also:
HibernateTemplate.findByCriteria(DetachedCriteria, int, int)

findByCriteria

List<T> findByCriteria(DetachedCriteria hibernateCriteria,
                       int firstResult,
                       int maxResults,
                       DataExtent extent)
                       throws DataAccessException
Retrieves a range of domain objects matching the Hibernate criteria. Loads at least the given extent.

Parameters:
hibernateCriteria - the criteria that the result has to fulfill Note: Do not reuse criteria objects! They need to recreated (or cloned e.g. using SerializationUtils.clone()) per execution, due to the suboptimal design of Hibernate's criteria facility.
firstResult - the index of the first result to return
maxResults - the maximum number of results to return
extent - the extent in which objects get loaded.
Returns:
the specified subset of object that fulfill the criteria
Throws:
DataAccessException
See Also:
HibernateTemplate.findByCriteria(DetachedCriteria, int, int)

findCountByCriteria

int findCountByCriteria(DetachedCriteria hibernateCriteria)
                        throws DataAccessException
Retrieves the number of domain objects matching the Hibernate criteria.

Parameters:
hibernateCriteria - the criteria that the result has to fulfill Note: Do not reuse criteria objects! They need to recreated (or cloned e.g. using SerializationUtils.clone()) per execution, due to the suboptimal design of Hibernate's criteria facility.
Returns:
the number of objects that fulfill the criteria
Throws:
DataAccessException
See Also:
ConvenienceHibernateTemplate.findCountByCriteria(DetachedCriteria)

findById

T findById(ID id,
           DataExtent extent)
           throws DataRetrievalFailureException,
                  DataAccessException
Retrieves a domain object by identifier. This method gets the object from the hibernate cache. It might be that you don't get the actual version that is in the database. If you want the actual version do a refresh() after this method call. Loads at least the given extent.

Parameters:
id - The id of the domain object to find
extent - the extent in which objects get loaded.
Returns:
Returns the found domain object.
Throws:
DataRetrievalFailureException - If no domain object could be found with given id.
DataAccessException - If general data access problem occurred

findById

T findById(ID id,
           boolean lock,
           DataExtent extent)
           throws DataAccessException,
                  DataRetrievalFailureException
Retrieves a domain object by identifier, optionally obtaining a database lock for this operation.
(For hibernate specialists: we do a "get()" in this method. In case you require only a "load()" (e.g. for lazy loading to work) we recommend that you write your own find method in the interface's subclass.) Loads at least the given extent.

Parameters:
id - The id of a domain object
lock - Indicates whether a database lock should be obtained for this operation
extent - the extent in which objects get loaded.
Returns:
The desired domain object
Throws:
DataAccessException - If general data access problem occurred
DataRetrievalFailureException - If domain object could not be retrieved

getAll

List<T> getAll(DataExtent extent)
               throws DataAccessException
Retrieves all the domain objects of type T. Loads at least the given extent.

Parameters:
extent - the extent in which objects get loaded.
Returns:
The list containing all the domain objects of type T; if no such domain objects exist, an empty list will be returned
Throws:
DataAccessException - If general data access problem occurred

findByQuery

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

Parameters:
q - The search query object
extent - the extent in which objects get loaded.
Returns:
A list containing 0 or more domain objects
Throws:
DataAccessException - If general data access problem occurred

refresh

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

Parameters:
entity - The domain object to re-read the state of
extent - the extent in which objects get loaded.
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,
         DataExtent extent)
         throws DataAccessException,
                DataRetrievalFailureException
Re-reads the state of the given domain object from the undermost store (eg. the database). Loads at least the given extent.

Parameters:
entity - The domain object to re-read the state of
extent - the extent in which objects get loaded.
Returns:
The refreshed entity
Throws:
DataAccessException - If general data access problem occurred
DataRetrievalFailureException - If domain object could not be re-read

getDefaultOrder

Order[] getDefaultOrder()
Returns:
the default Order to order the results

setDefaultOrder

void setDefaultOrder(Order... defaultOrder)
Set default order of results returned by getAll and findByQuery (not findByCriteria!). If defaultOrder is null then default ordering is deactivated.

Parameters:
defaultOrder - the default Order to order the results

getOrderedCriteria

DetachedCriteria getOrderedCriteria()
Create a DetachedCriteria what contains default ordering and distinct constraints.

Returns:
a DetachedCriteria


Copyright © 2005-2011 ELCA. All Rights Reserved.