|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.springframework.dao.support.DaoSupport
org.springframework.orm.hibernate3.support.HibernateDaoSupport
ch.elca.el4j.services.persistence.hibernate.dao.ConvenienceHibernateDaoSupport
ch.elca.el4j.services.persistence.hibernate.dao.GenericHibernateDao<T,ID>
T - The domain class the DAO is responsible forID - The type of the domain class' identifierpublic class GenericHibernateDao<T,ID extends Serializable>
This class is a Hibernate-specific implementation of the ConvenienceGenericDao interface.
| Field Summary |
|---|
| Fields inherited from class org.springframework.dao.support.DaoSupport |
|---|
logger |
| Constructor Summary | |
|---|---|
GenericHibernateDao()
Set up the Generic Dao. |
|
| Method Summary | |
|---|---|
protected DetachedCriteria |
addOrder(DetachedCriteria criteria)
|
void |
delete(Collection<T> entities)
Deletes the given domain objects. |
void |
delete(ID id)
Deprecated. |
void |
delete(T entity)
Deletes the given domain object. |
void |
deleteAll()
Deletes all available T. |
void |
deleteAllNoCascade()
Deletes all available T using a HQL query. |
void |
deleteById(ID id)
Deletes the domain object with the given id, disregarding any concurrent modifications that may have occurred. |
void |
deleteNoCascade(Collection<T> entities)
Deletes the given domain objects using a HQL query. |
protected List<T> |
fetchExtent(List<T> objects,
DataExtent extent)
Prototype of Extent-based fetching, steps through all the retrieved objects and calls the methods of the extent to ensure loading from db. |
protected T |
fetchExtent(T object,
DataExtent extent)
Prototype of Extent-based fetching, steps through all the retrieved objects and calls the methods of the extent to ensure loading from db. |
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)
Retrieves a domain object by identifier. |
T |
findById(ID id,
boolean lock)
Retrieves a domain object by identifier, optionally obtaining a database lock for this operation. |
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. |
T |
findByIdLazy(ID id)
Retrieves a domain object by identifier lazily. |
List<T> |
findByQuery(QueryObject q)
Executes a query based on a given query object. |
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. |
int |
findCountByQuery(QueryObject q)
Count number of results of a search. |
void |
flush()
Sometimes, the way Hibernate handles all the actions in a session is very unbelievable. |
List<T> |
getAll()
Retrieves all the domain objects of type T. |
List<T> |
getAll(DataExtent extent)
Retrieves all the domain objects of type T. |
protected DetachedCriteria |
getCriteria(QueryObject queryObject)
|
Order[] |
getDefaultOrder()
|
DetachedCriteria |
getOrderedCriteria()
Create a DetachedCriteria what contains default ordering and distinct constraints. |
Class<T> |
getPersistentClass()
Needed because the Java generics throw away this type information. |
protected String |
getPersistentClassName()
Returns the simple name of the persistent class this DAO is responsible for. |
protected DetachedCriteria |
makeDistinct(DetachedCriteria criteria)
|
T |
refresh(T entity)
Re-reads the state of the given domain object from the underlying store. |
T |
refresh(T entity,
DataExtent extent)
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 |
reload(T entity,
DataExtent extent)
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. |
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!). |
void |
setPersistentClass(Class<T> c)
New: this callback is in general no longer required (the constructor figures the type out itself). |
| Methods inherited from class ch.elca.el4j.services.persistence.hibernate.dao.ConvenienceHibernateDaoSupport |
|---|
createHibernateTemplate, getConvenienceHibernateTemplate, setConvenienceHibernateTemplate |
| Methods inherited from class org.springframework.orm.hibernate3.support.HibernateDaoSupport |
|---|
checkDaoConfig, convertHibernateAccessException, getHibernateTemplate, getSession, getSession, getSessionFactory, releaseSession, setHibernateTemplate, setSessionFactory |
| Methods inherited from class org.springframework.dao.support.DaoSupport |
|---|
afterPropertiesSet, initDao |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.springframework.beans.factory.InitializingBean |
|---|
afterPropertiesSet |
| Constructor Detail |
|---|
public GenericHibernateDao()
| Method Detail |
|---|
public void setPersistentClass(Class<T> c)
setPersistentClass in interface GenericDao<T>c - Mandatory. The domain class this DAO is responsible for.public Class<T> getPersistentClass()
GenericDao
getPersistentClass in interface GenericDao<T>public Order[] getDefaultOrder()
getDefaultOrder in interface ConvenienceGenericHibernateDao<T,ID extends Serializable>Order to order the resultspublic void setDefaultOrder(Order... defaultOrder)
null then default ordering is deactivated.
setDefaultOrder in interface ConvenienceGenericHibernateDao<T,ID extends Serializable>defaultOrder - the default Order to order the results
@Transactional(propagation=SUPPORTS,
readOnly=true)
public T findById(ID id,
boolean lock)
throws DataAccessException,
DataRetrievalFailureException
id - The id of a domain objectlock - Indicates whether a database lock should be obtained for this
operation
DataAccessException - If general data access problem occurred
DataRetrievalFailureException - If domain object could not be retrieved
@Transactional(propagation=REQUIRED,
readOnly=true)
public T findById(ID id,
boolean lock,
DataExtent extent)
throws DataAccessException,
DataRetrievalFailureException
findById in interface ConvenienceGenericHibernateDao<T,ID extends Serializable>id - The id of a domain objectlock - Indicates whether a database lock should be obtained for this
operationextent - the extent in which objects get loaded.
DataAccessException - If general data access problem occurred
DataRetrievalFailureException - If domain object could not be retrieved
@Transactional(propagation=SUPPORTS,
readOnly=true)
public T findById(ID id)
throws DataAccessException,
DataRetrievalFailureException
findById in interface ConvenienceGenericDao<T,ID extends Serializable>id - The id of the domain object to find
DataRetrievalFailureException - If no domain object could be found with given id.
DataAccessException - If general data access problem occurred
@Transactional(propagation=REQUIRED,
readOnly=true)
public T findById(ID id,
DataExtent extent)
throws DataAccessException,
DataRetrievalFailureException
findById in interface ConvenienceGenericHibernateDao<T,ID extends Serializable>id - The id of the domain object to findextent - the extent in which objects get loaded.
DataRetrievalFailureException - If no domain object could be found with given id.
DataAccessException - If general data access problem occurred
@Transactional(propagation=SUPPORTS,
readOnly=true)
public T findByIdLazy(ID id)
throws DataAccessException,
DataRetrievalFailureException
findByIdLazy in interface ConvenienceGenericDao<T,ID extends Serializable>DataAccessException
DataRetrievalFailureExceptionfindById
@Transactional(propagation=SUPPORTS,
readOnly=true)
public List<T> getAll()
throws DataAccessException
getAll in interface ConvenienceGenericDao<T,ID extends Serializable>DataAccessException - If general data access problem occurred
@Transactional(propagation=REQUIRED,
readOnly=true)
public List<T> getAll(DataExtent extent)
throws DataAccessException
getAll in interface ConvenienceGenericHibernateDao<T,ID extends Serializable>extent - the extent in which objects get loaded.
DataAccessException - If general data access problem occurred
@Transactional(propagation=SUPPORTS,
readOnly=true)
public List<T> findByQuery(QueryObject q)
throws DataAccessException
findByQuery in interface GenericDao<T>q - The search query object
DataAccessException - If general data access problem occurred
@Transactional(propagation=REQUIRED,
readOnly=true)
public List<T> findByQuery(QueryObject q,
DataExtent extent)
throws DataAccessException
findByQuery in interface ConvenienceGenericHibernateDao<T,ID extends Serializable>q - The search query objectextent - the extent in which objects get loaded.
DataAccessException - If general data access problem occurred
@Transactional(propagation=SUPPORTS,
readOnly=true)
public int findCountByQuery(QueryObject q)
throws DataAccessException
findCountByQuery in interface GenericDao<T>q - The search query object
DataAccessException
@Transactional(propagation=SUPPORTS,
readOnly=true)
public List<T> findByCriteria(DetachedCriteria hibernateCriteria)
throws DataAccessException
findByCriteria in interface ConvenienceGenericHibernateDao<T,ID extends Serializable>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.
DataAccessExceptionHibernateTemplate.findByCriteria(DetachedCriteria)
@Transactional(propagation=REQUIRED,
readOnly=true)
public List<T> findByCriteria(DetachedCriteria hibernateCriteria,
DataExtent extent)
throws DataAccessException
findByCriteria in interface ConvenienceGenericHibernateDao<T,ID extends Serializable>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.
DataAccessExceptionHibernateTemplate.findByCriteria(DetachedCriteria)
@Transactional(propagation=SUPPORTS,
readOnly=true)
public List<T> findByCriteria(DetachedCriteria hibernateCriteria,
int firstResult,
int maxResults)
throws DataAccessException
findByCriteria in interface ConvenienceGenericHibernateDao<T,ID extends Serializable>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 returnmaxResults - the maximum number of results to return
DataAccessExceptionHibernateTemplate.findByCriteria(DetachedCriteria, int, int)
@Transactional(propagation=REQUIRED,
readOnly=true)
public List<T> findByCriteria(DetachedCriteria hibernateCriteria,
int firstResult,
int maxResults,
DataExtent extent)
throws DataAccessException
findByCriteria in interface ConvenienceGenericHibernateDao<T,ID extends Serializable>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 returnmaxResults - the maximum number of results to returnextent - the extent in which objects get loaded.
DataAccessExceptionHibernateTemplate.findByCriteria(DetachedCriteria, int, int)
@Transactional(propagation=SUPPORTS,
readOnly=true)
public int findCountByCriteria(DetachedCriteria hibernateCriteria)
throws DataAccessException
findCountByCriteria in interface ConvenienceGenericHibernateDao<T,ID extends Serializable>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.
DataAccessExceptionConvenienceHibernateTemplate.findCountByCriteria(DetachedCriteria)
@Transactional(propagation=REQUIRED)
public T saveOrUpdate(T entity)
throws DataAccessException,
DataIntegrityViolationException,
OptimisticLockingFailureException
saveOrUpdate in interface GenericDao<T>entity - The domain object to save or update
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
@Transactional(propagation=REQUIRED)
public T saveOrUpdateAndFlush(T entity)
throws DataAccessException,
DataIntegrityViolationException,
OptimisticLockingFailureException
saveOrUpdateAndFlush in interface ConvenienceGenericHibernateDao<T,ID extends Serializable>entity - The domain object to save or update
DataAccessException
DataIntegrityViolationException
OptimisticLockingFailureException
@Transactional(propagation=REQUIRED)
public void delete(T entity)
throws DataAccessException
delete in interface ConvenienceGenericDao<T,ID extends Serializable>entity - The domain object to delete
OptimisticLockingFailureException - If domain object has been modified/deleted in the meantime
DataAccessException - If general data access problem occurred
@Transactional(propagation=SUPPORTS,
readOnly=true)
public T refresh(T entity)
throws DataAccessException,
DataRetrievalFailureException
refresh in interface GenericDao<T>entity - The domain object to re-read the state of
DataAccessException - If general data access problem occurred
DataRetrievalFailureException - If domain object could not be re-read
@Transactional(propagation=REQUIRED,
readOnly=true)
public T refresh(T entity,
DataExtent extent)
throws DataAccessException,
DataRetrievalFailureException
refresh in interface ConvenienceGenericHibernateDao<T,ID extends Serializable>entity - The domain object to re-read the state ofextent - the extent in which objects get loaded.
DataAccessException - If general data access problem occurred
DataRetrievalFailureException - If domain object could not be re-read
@Transactional(propagation=SUPPORTS,
readOnly=true)
public T reload(T entity)
throws DataAccessException,
DataRetrievalFailureException
reload in interface GenericDao<T>entity - The domain object to re-load the state of
DataAccessException - If general data access problem occurred
DataRetrievalFailureException - If domain object could not be re-loaded
@Transactional(propagation=REQUIRED,
readOnly=true)
public T reload(T entity,
DataExtent extent)
throws DataAccessException,
DataRetrievalFailureException
reload in interface ConvenienceGenericHibernateDao<T,ID extends Serializable>entity - The domain object to re-read the state ofextent - the extent in which objects get loaded.
DataAccessException - If general data access problem occurred
DataRetrievalFailureException - If domain object could not be re-read
@Deprecated
@Transactional(propagation=REQUIRED)
public void delete(ID id)
throws DataAccessException
delete in interface ConvenienceGenericDao<T,ID extends Serializable>id - The id of the domain object to delete
OptimisticLockingFailureException - If domain object has been deleted in the meantime
DataAccessException - If general data access problem occurred
@Transactional(propagation=REQUIRED)
public void deleteById(ID id)
throws DataAccessException
deleteById in interface ConvenienceGenericDao<T,ID extends Serializable>id - The id of the domain object to delete
OptimisticLockingFailureException - If domain object has been deleted in the meantime
DataAccessException - If general data access problem occurred
public void delete(Collection<T> entities)
throws DataAccessException,
DataIntegrityViolationException,
OptimisticLockingFailureException
delete in interface GenericDao<T>entities - The domain objects to delete.
DataAccessException - If general data access problem occurred
OptimisticLockingFailureException - If domain object has been modified/deleted in the meantime
DataIntegrityViolationException
public void deleteNoCascade(Collection<T> entities)
throws DataAccessException,
DataIntegrityViolationException,
OptimisticLockingFailureException
delete. The tradeoff is that this
method does no cascade deletion.
deleteNoCascade in interface ConvenienceGenericHibernateDao<T,ID extends Serializable>entities - The domain objects to delete.
OptimisticLockingFailureException - If domain object has been modified/deleted in the meantime
DataAccessException - If general data access problem occurred
DataIntegrityViolationException
public void deleteAll()
throws OptimisticLockingFailureException,
DataAccessException
T.
deleteAll in interface ConvenienceGenericDao<T,ID extends Serializable>OptimisticLockingFailureException - If domain object has been modified/deleted in the meantime
DataAccessException - If general data access problem occurred
public void deleteAllNoCascade()
throws OptimisticLockingFailureException,
DataAccessException
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.
deleteAllNoCascade in interface ConvenienceGenericHibernateDao<T,ID extends Serializable>OptimisticLockingFailureException - If domain object has been modified/deleted in the meantime
DataAccessException - If general data access problem occurred@Transactional(propagation=REQUIRED) public void flush()
delete(project);
project.setId(null) <= to insert new one
insert(project);
It could cause java.sql.BatchUpdateException:
ORA-00001: unique constraint BECAUSE Hibernate doesn't flush
the previous action first.
This method provides a way to flush manually some action.
Note that this method is only used in an extremely rare case.
flush in interface ConvenienceGenericDao<T,ID extends Serializable>public DetachedCriteria getOrderedCriteria()
DetachedCriteria what contains default ordering and distinct constraints.
getOrderedCriteria in interface ConvenienceGenericHibernateDao<T,ID extends Serializable>DetachedCriteria
protected List<T> fetchExtent(List<T> objects,
DataExtent extent)
throws DataAccessException
objects - list of objects to load in given extentextent - the fetch-extent
DataAccessException
protected T fetchExtent(T object,
DataExtent extent)
throws DataAccessException
object - object to load in given extentextent - the fetch-extent
DataAccessExceptionprotected String getPersistentClassName()
protected DetachedCriteria getCriteria(QueryObject queryObject)
queryObject - an EL4J QueryObject that should be converted to a DetachedCriteria
DetachedCriteriaprotected DetachedCriteria addOrder(DetachedCriteria criteria)
criteria - the criteria to modify
protected DetachedCriteria makeDistinct(DetachedCriteria criteria)
criteria - the criteria to modify
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||