org.jboss.seam.persistence
Class PersistenceProvider

java.lang.Object
  extended by org.jboss.seam.persistence.PersistenceProvider
Direct Known Subclasses:
HibernatePersistenceProvider

@Name(value="org.jboss.seam.persistence.persistenceProvider")
@Scope(value=STATELESS)
@BypassInterceptors
@Install(precedence=0,
         classDependencies="javax.persistence.EntityManager")
public class PersistenceProvider
extends Object

Abstraction layer for persistence providers (JPA implementations). This class provides a working base implementation that can be optimized for performance and non-standardized features by extending and overriding the methods. The methods on this class are a great todo list for the next rev of the JPA spec ;-)

Author:
Gavin King, Pete Muir

Nested Class Summary
static class PersistenceProvider.Feature
           
 
Field Summary
protected  Set<PersistenceProvider.Feature> featureSet
           
 
Constructor Summary
PersistenceProvider()
           
 
Method Summary
 void checkVersion(Object bean, javax.persistence.EntityManager entityManager, Object oldVersion, Object version)
           
 void enableFilter(Filter filter, javax.persistence.EntityManager entityManager)
          Enable a Filter.
 Class getBeanClass(Object bean)
          Returns the class of an entity bean instance
 Object getId(Object bean, javax.persistence.EntityManager entityManager)
          Get the value of the entity identifier attribute.
 String getName(Object bean, javax.persistence.EntityManager entityManager)
          Get the name of the entity
 Method getPostLoadMethod(Class beanClass)
          Deprecated. 
 Method getPostLoadMethod(Object bean, javax.persistence.EntityManager entityManager)
           
 Method getPrePersistMethod(Class beanClass)
          Deprecated. 
 Method getPrePersistMethod(Object bean, javax.persistence.EntityManager entityManager)
           
 Method getPreRemoveMethod(Class beanClass)
          Deprecated. 
 Method getPreRemoveMethod(Object bean, javax.persistence.EntityManager entityManager)
           
 Method getPreUpdateMethod(Class beanClass)
          Deprecated. 
 Method getPreUpdateMethod(Object bean, javax.persistence.EntityManager entityManager)
           
 Object getVersion(Object bean, javax.persistence.EntityManager entityManager)
          Get the value of the entity version attribute.
 void init()
           
static PersistenceProvider instance()
           
 boolean isDirty(javax.persistence.EntityManager entityManager)
          Does the persistence context have unflushed changes? If it does not, persistence context replication can be optimized.
 Object proxyDelegate(Object delegate)
          Wrap the delegate before returning it to the application
 javax.persistence.EntityManager proxyEntityManager(javax.persistence.EntityManager entityManager)
          Wrap the entityManager before returning it to the application
 boolean registerSynchronization(Synchronization sync, javax.persistence.EntityManager entityManager)
          Register a Synchronization with the current transaction.
 void setFlushModeManual(javax.persistence.EntityManager entityManager)
          Set the flush mode to manual-only flushing.
 void setRenderFlushMode()
           Set the FlushMode the persistence contexts should use during rendering by calling PersistenceContexts#changeFlushMode(FlushModeType, true).
 boolean supportsFeature(PersistenceProvider.Feature feature)
          Indicate whether this JPA provider supports the feature defined by the provided Feature enum value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

featureSet

protected Set<PersistenceProvider.Feature> featureSet
Constructor Detail

PersistenceProvider

public PersistenceProvider()
Method Detail

init

@PostConstruct
public void init()

supportsFeature

public boolean supportsFeature(PersistenceProvider.Feature feature)
Indicate whether this JPA provider supports the feature defined by the provided Feature enum value.


setFlushModeManual

public void setFlushModeManual(javax.persistence.EntityManager entityManager)
Set the flush mode to manual-only flushing. Called when an atomic persistence context is required.


setRenderFlushMode

public void setRenderFlushMode()

Set the FlushMode the persistence contexts should use during rendering by calling PersistenceContexts#changeFlushMode(FlushModeType, true). The actual changing of the flush mode is handled by the PersistenceContexts instance. The boolean argument should be true to indicate that this is a temporary change and that the old flush mode should be restored after render.

Ideally, this should be MANUAL since changes should never flush to the database while in render response and the cost of a dirty check can be avoided. However, since the MANUAL mode is not officially part of the JPA specification, the default implementation will perform no operation.


isDirty

public boolean isDirty(javax.persistence.EntityManager entityManager)
Does the persistence context have unflushed changes? If it does not, persistence context replication can be optimized.

Returns:
true to indicate that there are unflushed changes

getId

public Object getId(Object bean,
                    javax.persistence.EntityManager entityManager)
Get the value of the entity identifier attribute.

Parameters:
bean - a managed entity instance

getName

public String getName(Object bean,
                      javax.persistence.EntityManager entityManager)
               throws IllegalArgumentException
Get the name of the entity

Parameters:
bean -
entityManager -
Throws:
IllegalArgumentException - if the passed object is not an entity

getVersion

public Object getVersion(Object bean,
                         javax.persistence.EntityManager entityManager)
Get the value of the entity version attribute.

Parameters:
bean - a managed entity instance

checkVersion

public void checkVersion(Object bean,
                         javax.persistence.EntityManager entityManager,
                         Object oldVersion,
                         Object version)

enableFilter

public void enableFilter(Filter filter,
                         javax.persistence.EntityManager entityManager)
Enable a Filter. This is here just especially for Hibernate, since we well know that other products don't have such cool features.


registerSynchronization

public boolean registerSynchronization(Synchronization sync,
                                       javax.persistence.EntityManager entityManager)
Register a Synchronization with the current transaction.


instance

public static PersistenceProvider instance()

proxyDelegate

public Object proxyDelegate(Object delegate)
Wrap the delegate before returning it to the application


proxyEntityManager

public javax.persistence.EntityManager proxyEntityManager(javax.persistence.EntityManager entityManager)
Wrap the entityManager before returning it to the application


getBeanClass

public Class getBeanClass(Object bean)
Returns the class of an entity bean instance

Parameters:
bean - The entity bean instance
Returns:
The class of the entity bean

getPostLoadMethod

public Method getPostLoadMethod(Object bean,
                                javax.persistence.EntityManager entityManager)

getPrePersistMethod

public Method getPrePersistMethod(Object bean,
                                  javax.persistence.EntityManager entityManager)

getPreUpdateMethod

public Method getPreUpdateMethod(Object bean,
                                 javax.persistence.EntityManager entityManager)

getPreRemoveMethod

public Method getPreRemoveMethod(Object bean,
                                 javax.persistence.EntityManager entityManager)

getPreRemoveMethod

@Deprecated
public Method getPreRemoveMethod(Class beanClass)
Deprecated. 


getPostLoadMethod

@Deprecated
public Method getPostLoadMethod(Class beanClass)
Deprecated. 


getPrePersistMethod

@Deprecated
public Method getPrePersistMethod(Class beanClass)
Deprecated. 


getPreUpdateMethod

@Deprecated
public Method getPreUpdateMethod(Class beanClass)
Deprecated. 



Copyright © 2011 Seam Framework. All Rights Reserved.