org.spicefactory.pimento.adapter
Class JpaPersistenceAdapter

java.lang.Object
  extended by org.spicefactory.pimento.adapter.JpaPersistenceAdapter
All Implemented Interfaces:
PersistenceAdapter

public class JpaPersistenceAdapter
extends Object
implements PersistenceAdapter

PersistenceAdapter implementation that manages JPA entities. This is the only built-in implementation of the PersistenceAdapter interface.

Author:
Jens Halm

Constructor Summary
JpaPersistenceAdapter()
          Creates a new instance.
 
Method Summary
 List<Entity> createEntities(MetamodelBuilderFactory factory)
          Creates the metamodel for all persistent entities managed by Pimento.
 Object executeQuery(Query clientQuery, boolean executeUpdatePermitted)
          Executes the specified query and returns the result.
 JpaProvider getJpaProvider()
          Returns the JPA provider in use.
 Object getReference(Class<?> persistentClass, Object primaryKey)
          Returns a reference for the specified entity type and primary key.
 boolean isUninitializedProxy(Object entity)
          Checks whether the specified entity or collection is an uninitialized proxy.
 Object load(Class<?> persistentClass, Object primaryKey)
          Loads the entity with the specified type and primary key.
 void persist(Object entity)
          Persists the specified entity.
 void remove(Object entity)
          Removes the specified entity.
 void setDefaultOperations(Set<Operation> operations)
          Sets the default EntityManager operations permitted on the client side.
 void setJpaProvider(JpaProvider jpaProvider)
          Sets the JPA provider.
 void update(Object entity)
          Updates the specified entity.
 boolean useAutoCascade()
          Specifies whether automatic cascading should be performed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JpaPersistenceAdapter

public JpaPersistenceAdapter()
Creates a new instance.

Method Detail

getJpaProvider

public JpaProvider getJpaProvider()
Returns the JPA provider in use. The JpaProvider interface allows to hook different JPA implementations into Pimento. Out-of-the-box only Hibernate is supported, but any other JPA provider can be used if you provide a corresponding JpaProvider implementation.

Returns:
the JPA provider in use

setJpaProvider

public void setJpaProvider(JpaProvider jpaProvider)
Sets the JPA provider. The JpaProvider interface allows to hook different JPA implementations into Pimento. Out-of-the-box only Hibernate is supported, but any other JPA provider can be used if you provide a corresponding JpaProvider implementation.

Parameters:
jpaProvider - the JPA provider to use

setDefaultOperations

public void setDefaultOperations(Set<Operation> operations)
Sets the default EntityManager operations permitted on the client side. This value can be overwritten for any persistent entity with the @Managed annotation. If no default operations are set, entities without the @Managed annotation won't be managed by Pimento at all.

Parameters:
operations - the default EntityManager operations permitted on the client side

createEntities

public List<Entity> createEntities(MetamodelBuilderFactory factory)
Description copied from interface: PersistenceAdapter
Creates the metamodel for all persistent entities managed by Pimento.

Specified by:
createEntities in interface PersistenceAdapter
Parameters:
factory - the factory to use for creating MetamodelBuilder instances
Returns:
metamodel instances for all managed persistent entities

executeQuery

public Object executeQuery(Query clientQuery,
                           boolean executeUpdatePermitted)
Description copied from interface: PersistenceAdapter
Executes the specified query and returns the result.

Specified by:
executeQuery in interface PersistenceAdapter
Parameters:
clientQuery - the query to execute
executeUpdatePermitted - whether updates are allowed
Returns:
the result of the query

getReference

public Object getReference(Class<?> persistentClass,
                           Object primaryKey)
Description copied from interface: PersistenceAdapter
Returns a reference for the specified entity type and primary key. The difference to the load method is primarily, that this method gets called by Pimento before updating or removing an entity. Thus implementations may choose to return uninitialized proxies for improved efficiency.

Specified by:
getReference in interface PersistenceAdapter
Parameters:
persistentClass - the entity type
primaryKey - the primary key of the entity
Returns:
a reference for the specified entity type and primary key

load

public Object load(Class<?> persistentClass,
                   Object primaryKey)
Description copied from interface: PersistenceAdapter
Loads the entity with the specified type and primary key. The difference to the load method is primarily, that this method gets called by Pimento for entities that will be sent to the client. Thus it would be inefficient to return uninitialized proxies with this method.

Specified by:
load in interface PersistenceAdapter
Parameters:
persistentClass - the entity type
primaryKey - the primary key of the entity
Returns:
a reference for the specified entity type and primary key

persist

public void persist(Object entity)
Description copied from interface: PersistenceAdapter
Persists the specified entity.

Specified by:
persist in interface PersistenceAdapter
Parameters:
entity - the entity to persist

update

public void update(Object entity)
Description copied from interface: PersistenceAdapter
Updates the specified entity.

Specified by:
update in interface PersistenceAdapter
Parameters:
entity - the entity to update

remove

public void remove(Object entity)
Description copied from interface: PersistenceAdapter
Removes the specified entity.

Specified by:
remove in interface PersistenceAdapter
Parameters:
entity - the entity to remove

isUninitializedProxy

public boolean isUninitializedProxy(Object entity)
Description copied from interface: PersistenceAdapter
Checks whether the specified entity or collection is an uninitialized proxy.

Specified by:
isUninitializedProxy in interface PersistenceAdapter
Parameters:
entity - the entity or collection to check
Returns:
true if the specified entity or collection is an uninitialized proxy

useAutoCascade

public boolean useAutoCascade()
Description copied from interface: PersistenceAdapter
Specifies whether automatic cascading should be performed. If this method returns true, Pimento will pass each entity of an object graph that gets persisted or updated to the adapter individually. If it returns false only the root object will be passed to persist or update respectively. In this case the persistence adapter itself is responsible for determining cascading behaviour. An example is the built-in JpaPersistenceAdapter where cascading behaviour will be determined by the JPA configuration (annotations or XML). This method does not affect remove operations where Pimento will always only pass the root object to the persistence adapter. It is always the responsibility of a persistence adapter to determine cascading behaviour for remove operations.

Specified by:
useAutoCascade in interface PersistenceAdapter
Returns:
whether automatic cascading should be performed