org.jboss.seam.persistence
Class DefaultPersistenceProvider

java.lang.Object
  extended by org.jboss.seam.persistence.DefaultPersistenceProvider
All Implemented Interfaces:
SeamPersistenceProvider
Direct Known Subclasses:
HibernatePersistenceProvider

public class DefaultPersistenceProvider
extends Object
implements SeamPersistenceProvider

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, Stuart Douglas

Nested Class Summary
static class DefaultPersistenceProvider.Feature
           
 
Field Summary
protected  Set<DefaultPersistenceProvider.Feature> featureSet
           
 
Constructor Summary
DefaultPersistenceProvider()
           
 
Method Summary
 void checkVersion(Object bean, EntityManager entityManager, Object oldVersion, Object version)
           
 Set<Class<?>> getAdditionalEntityManagerInterfaces()
           
 Class<?> getBeanClass(Object bean)
          Returns the class of an entity bean instance
 Object getId(Object bean, EntityManager entityManager)
          Get the value of the entity identifier attribute.
 String getName(Object bean, EntityManager entityManager)
          Get the name of the entity
 Method getPostLoadMethod(Object bean, EntityManager entityManager)
           
 Method getPrePersistMethod(Object bean, EntityManager entityManager)
           
 Method getPreRemoveMethod(Object bean, EntityManager entityManager)
           
 Method getPreUpdateMethod(Object bean, EntityManager entityManager)
           
 FlushModeType getRenderFlushMode()
           Gets the FlushMode the persistence contexts should use during rendering
 Object getVersion(Object bean, EntityManager entityManager)
          Get the value of the entity version attribute.
 boolean isCorrectProvider(EntityManager em)
          Should return true if this is the correct persistence provider for the given entity manager factory
 boolean isDirty(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
 EntityManager proxyEntityManager(EntityManager entityManager)
           
 boolean registerSynchronization(Synchronization sync, EntityManager entityManager)
          Register a Synchronization with the current transaction.
 void setFlushMode(EntityManager entityManager, FlushModeType type)
          sets the flush mode
 void setFlushModeManual(EntityManager entityManager)
          Set the flush mode to manual-only flushing.
 boolean supportsFeature(DefaultPersistenceProvider.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<DefaultPersistenceProvider.Feature> featureSet
Constructor Detail

DefaultPersistenceProvider

public DefaultPersistenceProvider()
Method Detail

supportsFeature

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


isCorrectProvider

public boolean isCorrectProvider(EntityManager em)
Description copied from interface: SeamPersistenceProvider
Should return true if this is the correct persistence provider for the given entity manager factory

Specified by:
isCorrectProvider in interface SeamPersistenceProvider

setFlushMode

public void setFlushMode(EntityManager entityManager,
                         FlushModeType type)
Description copied from interface: SeamPersistenceProvider
sets the flush mode

Specified by:
setFlushMode in interface SeamPersistenceProvider

setFlushModeManual

public void setFlushModeManual(EntityManager entityManager)
Description copied from interface: SeamPersistenceProvider
Set the flush mode to manual-only flushing. Called when an atomic persistence context is required.

Specified by:
setFlushModeManual in interface SeamPersistenceProvider

getRenderFlushMode

public FlushModeType getRenderFlushMode()
Description copied from interface: SeamPersistenceProvider

Gets the FlushMode the persistence contexts should use during rendering

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.

Specified by:
getRenderFlushMode in interface SeamPersistenceProvider

isDirty

public boolean isDirty(EntityManager entityManager)
Description copied from interface: SeamPersistenceProvider
Does the persistence context have unflushed changes? If it does not, persistence context replication can be optimized.

Specified by:
isDirty in interface SeamPersistenceProvider
Returns:
true to indicate that there are unflushed changes

getId

public Object getId(Object bean,
                    EntityManager entityManager)
Description copied from interface: SeamPersistenceProvider
Get the value of the entity identifier attribute.

Specified by:
getId in interface SeamPersistenceProvider
Parameters:
bean - a managed entity instance

getName

public String getName(Object bean,
                      EntityManager entityManager)
               throws IllegalArgumentException
Description copied from interface: SeamPersistenceProvider
Get the name of the entity

Specified by:
getName in interface SeamPersistenceProvider
Throws:
IllegalArgumentException - if the passed object is not an entity

getVersion

public Object getVersion(Object bean,
                         EntityManager entityManager)
Description copied from interface: SeamPersistenceProvider
Get the value of the entity version attribute.

Specified by:
getVersion in interface SeamPersistenceProvider
Parameters:
bean - a managed entity instance

checkVersion

public void checkVersion(Object bean,
                         EntityManager entityManager,
                         Object oldVersion,
                         Object version)
Specified by:
checkVersion in interface SeamPersistenceProvider

registerSynchronization

public boolean registerSynchronization(Synchronization sync,
                                       EntityManager entityManager)
Description copied from interface: SeamPersistenceProvider
Register a Synchronization with the current transaction.

Specified by:
registerSynchronization in interface SeamPersistenceProvider

proxyDelegate

public Object proxyDelegate(Object delegate)
Description copied from interface: SeamPersistenceProvider
Wrap the delegate before returning it to the application

Specified by:
proxyDelegate in interface SeamPersistenceProvider

proxyEntityManager

public EntityManager proxyEntityManager(EntityManager entityManager)
Specified by:
proxyEntityManager in interface SeamPersistenceProvider

getAdditionalEntityManagerInterfaces

public Set<Class<?>> getAdditionalEntityManagerInterfaces()
Specified by:
getAdditionalEntityManagerInterfaces in interface SeamPersistenceProvider

getBeanClass

public Class<?> getBeanClass(Object bean)
Description copied from interface: SeamPersistenceProvider
Returns the class of an entity bean instance

Specified by:
getBeanClass in interface SeamPersistenceProvider
Parameters:
bean - The entity bean instance
Returns:
The class of the entity bean

getPostLoadMethod

public Method getPostLoadMethod(Object bean,
                                EntityManager entityManager)

getPrePersistMethod

public Method getPrePersistMethod(Object bean,
                                  EntityManager entityManager)

getPreUpdateMethod

public Method getPreUpdateMethod(Object bean,
                                 EntityManager entityManager)

getPreRemoveMethod

public Method getPreRemoveMethod(Object bean,
                                 EntityManager entityManager)


Copyright © 2011 Seam Framework. All Rights Reserved.