org.spicefactory.pimento.adapter
Interface PersistenceAdapter

All Known Implementing Classes:
JpaPersistenceAdapter

public interface PersistenceAdapter

Extension point that allows to create a custom adapter for a data source. The only built-in implementation is the JpaPersistenceAdapter that manages JPA entities. To register custom implementations they only need to be added to the Spring ApplicationContext.

Author:
Jens Halm

Method Summary
 List<Entity> createEntities(MetamodelBuilderFactory factory)
          Creates the metamodel for all persistent entities managed by Pimento.
 Object executeQuery(Query query, boolean executeUpdatePermitted)
          Executes the specified query and returns the result.
 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 update(Object entity)
          Updates the specified entity.
 boolean useAutoCascade()
          Specifies whether automatic cascading should be performed.
 

Method Detail

createEntities

List<Entity> createEntities(MetamodelBuilderFactory factory)
Creates the metamodel for all persistent entities managed by Pimento.

Parameters:
factory - the factory to use for creating MetamodelBuilder instances
Returns:
metamodel instances for all managed persistent entities

isUninitializedProxy

boolean isUninitializedProxy(Object entity)
Checks whether the specified entity or collection is an uninitialized proxy.

Parameters:
entity - the entity or collection to check
Returns:
true if the specified entity or collection is an uninitialized proxy

getReference

Object getReference(Class<?> persistentClass,
                    Object primaryKey)
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.

Parameters:
persistentClass - the entity type
primaryKey - the primary key of the entity
Returns:
a reference for the specified entity type and primary key

load

Object load(Class<?> persistentClass,
            Object primaryKey)
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.

Parameters:
persistentClass - the entity type
primaryKey - the primary key of the entity
Returns:
a reference for the specified entity type and primary key

persist

void persist(Object entity)
Persists the specified entity.

Parameters:
entity - the entity to persist

update

void update(Object entity)
Updates the specified entity.

Parameters:
entity - the entity to update

remove

void remove(Object entity)
Removes the specified entity.

Parameters:
entity - the entity to remove

executeQuery

Object executeQuery(Query query,
                    boolean executeUpdatePermitted)
Executes the specified query and returns the result.

Parameters:
query - the query to execute
executeUpdatePermitted - whether updates are allowed
Returns:
the result of the query

useAutoCascade

boolean useAutoCascade()
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.

Returns:
whether automatic cascading should be performed