|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.kuali.rice.krad.data.jpa.JpaPersistenceProvider
@Transactional public class JpaPersistenceProvider
Java Persistence API (JPA) implementation of PersistenceProvider.
When creating a new instance of this provider, a reference to a "shared" entity manager (like that created by
Spring's org.springframework.orm.jpa.support.SharedEntityManagerBean must be injected. Additionally, a
reference to the DataObjectService must be injected as well.
This class will perform persistence exception translation (converting JPA exceptions to
DataAccessExceptions. It will scan the
BeanFactory in which it was created to find beans which implement
PersistenceExceptionTranslator and use those translators for translation.
org.springframework.orm.jpa.support.SharedEntityManagerBean,
PersistenceExceptionTranslator| Field Summary | |
|---|---|
static String |
AUTO_FLUSH
Indicates if a JPA EntityManager flush should be automatically executed when calling
DataObjectService.save(Object, org.kuali.rice.krad.data.PersistenceOption...)
using a JPA provider. |
| Constructor Summary | |
|---|---|
JpaPersistenceProvider()
|
|
| Method Summary | ||
|---|---|---|
|
copyInstance(T dataObject)
Returns a copy of the given data object instance. |
|
void |
delete(Object dataObject)
Deletes a given data object. |
|
protected org.springframework.dao.support.PersistenceExceptionTranslator |
detectPersistenceExceptionTranslators(org.springframework.beans.factory.ListableBeanFactory beanFactory)
Gets any PersistenceExceptionTranslators from the BeanFactory. |
|
protected
|
doWithExceptionTranslation(Callable<T> callable)
Surrounds the transaction with a try/catch block that can use the PersistenceExceptionTranslator to
translate the exception if necessary. |
|
|
find(Class<T> type,
Object id)
Invoked to retrieve a data object instance by a single primary key field or id object. |
|
|
findMatching(Class<T> type,
QueryByCriteria queryByCriteria)
Executes a query for the given data object. |
|
void |
flush(Class<?> type)
Flush any outstanding changes within the current context for the provider pertaining to the given data object Class type. |
|
DataObjectService |
getDataObjectService()
Returns the DataObjectService. |
|
javax.persistence.EntityManager |
getSharedEntityManager()
Gets the shared EntityManager. |
|
boolean |
handles(Class<?> type)
Indicates whether or not this provider handles persistence for the given data object type. |
|
|
save(T dataObject,
PersistenceOption... options)
Saves the given data object, determining whether or not this is a new data object which is being created, or an existing one which should be updated. |
|
void |
setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
|
|
void |
setDataObjectService(DataObjectService dataObjectService)
Setter for the DataObjectService. |
|
void |
setSharedEntityManager(javax.persistence.EntityManager sharedEntityManager)
Setter for the shared EntityManager. |
|
protected void |
verifyDataObjectWritable(Object dataObject)
Verifies that the data object can be written to. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String AUTO_FLUSH
EntityManager flush should be automatically executed when calling
DataObjectService.save(Object, org.kuali.rice.krad.data.PersistenceOption...)
using a JPA provider.
This is recommended for testing only since the change is global and would affect all persistence units.
| Constructor Detail |
|---|
public JpaPersistenceProvider()
| Method Detail |
|---|
public javax.persistence.EntityManager getSharedEntityManager()
EntityManager.
EntityManager.public void setSharedEntityManager(javax.persistence.EntityManager sharedEntityManager)
EntityManager.
sharedEntityManager - The shared EntityManager to set.public void setDataObjectService(DataObjectService dataObjectService)
DataObjectService.
dataObjectService - The DataObjectService to set.public DataObjectService getDataObjectService()
DataObjectService.
DataObjectService
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
throws org.springframework.beans.BeansException
setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAwareorg.springframework.beans.BeansExceptionprotected org.springframework.dao.support.PersistenceExceptionTranslator detectPersistenceExceptionTranslators(org.springframework.beans.factory.ListableBeanFactory beanFactory)
PersistenceExceptionTranslators from the BeanFactory.
beanFactory - The BeanFactory to use.
PersistenceExceptionTranslator from the BeanFactory.
public <T> T save(T dataObject,
PersistenceOption... options)
Optional persistence options can be passed to indicate whether or not linking should be performed prior to persistence and whether or not validation should be performed. By default, linking is performed as well as validation.
save in interface PersistenceProviderT - the data object class typedataObject - the data object to saveoptions - the options to use when saving the data object
public <T> T find(Class<T> type,
Object id)
In the case of a compound primary key consisting of multiple attributes on the data object, a CompoundKey can be passed in order to encapsulate these into a single argument.
find in interface PersistenceProviderT - the data object class typetype - the type of the data object to findid - the id representing the primary key of the data object to find
public <T> QueryResults<T> findMatching(Class<T> type,
QueryByCriteria queryByCriteria)
If the given QueryByCriteria is empty or null, then all data objects for the given type will be returned. Depending on the given criteria and the implementation for the query execution, not all matching results may be returned. The QueryResults will contain information on whether or not there are additional results which can be used for paging and similar functionality.
findMatching in interface PersistenceProviderT - the data object class typetype - the type of the data objects to queryqueryByCriteria - query object, can contain sorting and page request configuration
public void delete(Object dataObject)
delete in interface PersistenceProviderdataObject - the data object to deletepublic <T> T copyInstance(T dataObject)
The method of copying is provider dependent, and will handle instances (including nested) using whatever measures might be required to deal with the quirks of said provider (e.g. fetching lazy loaded relations).
copyInstance in interface PersistenceProviderT - the type of the data objectdataObject - the data object to copy
public boolean handles(Class<?> type)
Responsibility on with the caller to call prior to invocation of any other PersistenceProvider methods to ensure the data objects of the right type are passed.
handles in interface PersistenceProvidertype - the data object type to check
public void flush(Class<?> type)
If an implementation of this interface does not support or require the concept of "flushing", this method can be ignored.
flush in interface PersistenceProvidertype - the type of the data object for which to perform the flush. This shoul be used to identify the
context in which to perform the flush.protected void verifyDataObjectWritable(Object dataObject)
dataObject - The data object to check.protected <T> T doWithExceptionTranslation(Callable<T> callable)
PersistenceExceptionTranslator to
translate the exception if necessary.
T - The type of the data operation.callable - The data operation to invoke.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||