ch.elca.el4j.services.persistence.jpa.dao
Class ConvenienceJpaTemplate

java.lang.Object
  extended by org.springframework.orm.jpa.EntityManagerFactoryAccessor
      extended by org.springframework.orm.jpa.JpaAccessor
          extended by org.springframework.orm.jpa.JpaTemplate
              extended by ch.elca.el4j.services.persistence.jpa.dao.ConvenienceJpaTemplate
All Implemented Interfaces:
InitializingBean, JpaOperations

public class ConvenienceJpaTemplate
extends JpaTemplate

This is a convenience class for the Jpa template. Features:

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

Field Summary
 
Fields inherited from class org.springframework.orm.jpa.EntityManagerFactoryAccessor
logger
 
Constructor Summary
ConvenienceJpaTemplate(javax.persistence.EntityManagerFactory emf)
          Constructor.
 
Method Summary
<T> List<T>
findByCriteria(javax.persistence.criteria.CriteriaQuery<T> criteria)
          Finds entities matching the given criteria query.
<T> List<T>
findByCriteria(javax.persistence.criteria.CriteriaQuery<T> criteria, int firstResult, int maxResults)
          Finds entities matching the given criteria query, with paging support.
<T> T
findByIdStrong(Class<T> entityClass, Serializable id, String objectName)
          Retrieves the persistent instance given by its identifier in a strong way: does the same as the find(Class, java.io.Serializable) method, but throws a DataRetrievalException instead of null if the persistent instance could not be found.
<T> T
findByIdStrongLazy(Class<T> entityClass, Serializable id, String objectName)
          Retrieves the persistent instance given by its identifier in a strong way: does the same as the getReference(Class, java.io.Serializable) method, but throws a DataRetrievalException instead of null if the persistent instance could not be found.
 int getFirstResult()
          Gets the id of the first result to return.
 Object mergeStrong(Object entity, String objectName)
          Merges the given persistent instance in a strong way: does the same as the saveOrUpdate(Object) method, but throws a more specific OptimisticLockingFailureException in the case of an optimistic locking failure.
 void removeAll(Collection<?> entities)
          removes all entities in the given collection.
 void removeStrong(Class<?> entityClass, Serializable id, String objectName)
          Removes the persistent instance given by its identifier in a strong way: first, the persistent instance is retrieved with the help of the identifier.
 void setFirstResult(int firstResult)
          Sets the id of the first result to return.
 
Methods inherited from class org.springframework.orm.jpa.JpaTemplate
contains, createEntityManagerProxy, execute, execute, executeFind, find, find, find, findByNamedParams, findByNamedQuery, findByNamedQuery, findByNamedQueryAndNamedParams, flush, getReference, isExposeNativeEntityManager, merge, persist, prepareQuery, refresh, remove, setExposeNativeEntityManager
 
Methods inherited from class org.springframework.orm.jpa.JpaAccessor
afterPropertiesSet, flushIfNecessary, getEntityManager, getJpaDialect, isFlushEager, setEntityManager, setFlushEager, setJpaDialect, translateIfNecessary
 
Methods inherited from class org.springframework.orm.jpa.EntityManagerFactoryAccessor
createEntityManager, getEntityManagerFactory, getJpaPropertyMap, getTransactionalEntityManager, setEntityManagerFactory, setJpaProperties, setJpaPropertyMap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConvenienceJpaTemplate

public ConvenienceJpaTemplate(javax.persistence.EntityManagerFactory emf)
Constructor.

Parameters:
emf - EntityManagerFactory used to create EntityManager
Method Detail

mergeStrong

public Object mergeStrong(Object entity,
                          String objectName)
                   throws DataAccessException,
                          OptimisticLockingFailureException
Merges the given persistent instance in a strong way: does the same as the saveOrUpdate(Object) method, but throws a more specific OptimisticLockingFailureException in the case of an optimistic locking failure.

Parameters:
entity - the persistent entity to save or update
objectName - Name of the persistent object type.
Returns:
the merged entity
Throws:
DataAccessException - in case of Hibernate errors
OptimisticLockingFailureException - in case optimistic locking fails
See Also:
HibernateTemplate.saveOrUpdate(Object)

getFirstResult

public int getFirstResult()
Gets the id of the first result to return.

Returns:
The id of the first result to return.

setFirstResult

public void setFirstResult(int firstResult)
Sets the id of the first result to return.

Parameters:
firstResult - The id of the first result to return.

findByCriteria

public <T> List<T> findByCriteria(javax.persistence.criteria.CriteriaQuery<T> criteria)
Finds entities matching the given criteria query.

Type Parameters:
T - the entity type
Parameters:
criteria - the criteria query to run against the database
Returns:
the list of found objects, which may be empty.

findByCriteria

public <T> List<T> findByCriteria(javax.persistence.criteria.CriteriaQuery<T> criteria,
                                  int firstResult,
                                  int maxResults)
Finds entities matching the given criteria query, with paging support.

Type Parameters:
T - the entity type
Parameters:
criteria - the criteria query to run against the database
firstResult - the index of the first row to return
maxResults - the maximum number of rows to return
Returns:
the list of found objects, which may be empty.

findByIdStrong

public <T> T findByIdStrong(Class<T> entityClass,
                            Serializable id,
                            String objectName)
                 throws DataAccessException,
                        DataRetrievalFailureException
Retrieves the persistent instance given by its identifier in a strong way: does the same as the find(Class, java.io.Serializable) method, but throws a DataRetrievalException instead of null if the persistent instance could not be found.

Type Parameters:
T - entity type
Parameters:
entityClass - The class of the object which should be returned.
id - An identifier of the persistent instance
objectName - Name of the persistent object type.
Returns:
the persistent instance
Throws:
DataAccessException - in case of Jpa persistence exceptions
DataRetrievalFailureException - in case the persistent instance is null

findByIdStrongLazy

public <T> T findByIdStrongLazy(Class<T> entityClass,
                                Serializable id,
                                String objectName)
                     throws DataAccessException,
                            DataRetrievalFailureException
Retrieves the persistent instance given by its identifier in a strong way: does the same as the getReference(Class, java.io.Serializable) method, but throws a DataRetrievalException instead of null if the persistent instance could not be found.

Type Parameters:
T - entity type
Parameters:
entityClass - The class of the object which should be returned.
id - An identifier of the persistent instance
objectName - Name of the persistent object type.
Returns:
the persistent instance
Throws:
DataAccessException - in case of Jpa persistence exceptions
DataRetrievalFailureException - in case the persistent instance is null

removeStrong

public void removeStrong(Class<?> entityClass,
                         Serializable id,
                         String objectName)
                  throws DataRetrievalFailureException
Removes the persistent instance given by its identifier in a strong way: first, the persistent instance is retrieved with the help of the identifier. If it exists, it will be deleted, otherwise a DataRetrievalFailureException will be thrown.

Parameters:
entityClass - The class of the object which should be deleted.
id - The identifier of the persistent instance to delete
objectName - Name of the persistent object type.
Throws:
DataRetrievalFailureException - in case the persistent instance to delete is null
See Also:
JpaTemplate.remove(Object)

removeAll

public void removeAll(Collection<?> entities)
removes all entities in the given collection.

Parameters:
entities - the collection of all entities.


Copyright © 2005-2011 ELCA. All Rights Reserved.