ch.elca.el4j.services.persistence.jpa.dao
Interface ConvenienceGenericJpaDao<T,ID extends Serializable>

Type Parameters:
T - the domain object type
ID - the id of the domain object to find
All Known Implementing Classes:
GenericJpaDao

public interface ConvenienceGenericJpaDao<T,ID extends Serializable>

This interface extends ConvenienceGenericDao with query methods using CriteriaQuerys.

Author:
Simon Stelling (SST)
File-location:
ConvenienceGenericJpaDao
Last check-in date:
2010-12-21 11:08:04 +0100 (Di, 21. Dez 2010) by swismer for revision 4253

Method Summary
 void delete(Collection<T> entities)
          Deletes the given domain objects.
 void delete(T entity)
          Deletes the given domain object.
 void deleteAll()
          Deletes all available T.
 void deleteById(ID id)
          Deletes the domain object with the given id, disregarding any concurrent modifications that may have occurred.
 T findById(ID id)
          Retrieves a domain object by identifier.
 T findById(ID id, DataExtent extent)
          Retrieves a domain object by identifier.
 List<T> findByQuery(QueryBuilder criteria)
          Retrieves all the domain objects matching the JPA criteria.
 List<T> findByQuery(QueryBuilder criteria, DataExtent extent)
          Retrieves all the domain objects matching the JPA criteria.
 List<T> findByQuery(QueryBuilder criteria, int firstResult, int maxResults)
          Retrieves a range of domain objects matching the JPA criteria.
 List<T> findByQuery(QueryBuilder criteria, int firstResult, int maxResults, DataExtent extent)
          Retrieves a range of domain objects matching the JPA criteria.
 int findCountByQuery(QueryBuilder criteria)
          Retrieves the number of domain objects matching the JPA criteria.
 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.
 Class<T> getPersistentClass()
          Needed because the Java generics throw away this type information.
 T merge(T entity)
          merge the given entity.
 T persist(T entity)
          persist the given entity.
 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)
          Deprecated. 
 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.

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

findById

T findById(ID id)
           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.

Parameters:
id - The id of the domain object to find
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

deleteById

void deleteById(ID id)
                throws OptimisticLockingFailureException,
                       DataAccessException
Deletes the domain object with the given id, disregarding any concurrent modifications that may have occurred.

Parameters:
id - The id of the domain object to delete
Throws:
OptimisticLockingFailureException - If domain object has been deleted in the meantime
DataAccessException - If general data access problem occurred

getAll

List<T> getAll()
               throws DataAccessException
Retrieves all the domain objects of type T.

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

delete

void delete(T entity)
            throws OptimisticLockingFailureException,
                   DataAccessException
Deletes the given domain object.

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

deleteAll

void deleteAll()
               throws OptimisticLockingFailureException,
                      DataAccessException
Deletes all available T.

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

flush

void flush()
Sometimes, the way Hibernate handles all the actions in a session is very unbelievable. For example, we call 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.


saveOrUpdateAndFlush

@Deprecated
T saveOrUpdateAndFlush(T entity)
                       throws DataAccessException,
                              DataIntegrityViolationException,
                              OptimisticLockingFailureException
Deprecated. 

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

merge

T merge(T entity)
        throws DataAccessException,
               DataIntegrityViolationException,
               OptimisticLockingFailureException
merge the given entity.

Parameters:
entity - the entity to merge.
Returns:
the merged entity
Throws:
DataAccessException
DataIntegrityViolationException
OptimisticLockingFailureException

persist

T persist(T entity)
          throws DataAccessException,
                 DataIntegrityViolationException,
                 OptimisticLockingFailureException
persist the given entity.

Parameters:
entity - the entity to persist.
Returns:
the persisted entity
Throws:
DataAccessException
DataIntegrityViolationException
OptimisticLockingFailureException

findByQuery

List<T> findByQuery(QueryBuilder criteria)
                    throws DataAccessException
Retrieves all the domain objects matching the JPA criteria.

Parameters:
criteria - the criteria that the result has to fulfill
Returns:
all object that fulfill the criteria
Throws:
DataAccessException
See Also:
ConvenienceJpaTemplate#findByCriteria(DetachedCriteria)

findByQuery

List<T> findByQuery(QueryBuilder criteria,
                    DataExtent extent)
                    throws DataAccessException
Retrieves all the domain objects matching the JPA criteria. Loads at least the given extent.

Parameters:
criteria - the criteria that the result has to fulfill
extent - the extent in which objects get loaded.
Returns:
all object that fulfill the criteria
Throws:
DataAccessException
See Also:
ConvenienceJpaTemplate#findByCriteria(DetachedCriteria)

findByQuery

List<T> findByQuery(QueryBuilder criteria,
                    int firstResult,
                    int maxResults)
                    throws DataAccessException
Retrieves a range of domain objects matching the JPA criteria.

Parameters:
criteria - the criteria that the result has to fulfill
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:
ConvenienceJpaTemplate#findByCriteria(DetachedCriteria, int, int)

findByQuery

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

Parameters:
criteria - the criteria that the result has to fulfill
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:
ConvenienceJpaTemplate#findByCriteria(DetachedCriteria, int, int)

findCountByQuery

int findCountByQuery(QueryBuilder criteria)
                     throws DataAccessException
Retrieves the number of domain objects matching the JPA criteria.

Parameters:
criteria - the criteria that the result has to fulfill
Returns:
the number of objects that fulfill the criteria
Throws:
DataAccessException
See Also:
ConvenienceJpaTemplate#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

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

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


Copyright © 2005-2011 ELCA. All Rights Reserved.