org.spicefactory.pimento.io
Class IoContext

java.lang.Object
  extended by org.spicefactory.pimento.io.IoContext

public class IoContext
extends Object

The I/O context for a single service invocation. This class is responsible for converting snapshots to entities and vice versa and keeping track of already processed entities.

Author:
Jens Halm

Constructor Summary
IoContext(PimentoConfig config, EntityManager em, Operation operation)
          Creates a new instance.
 
Method Summary
 Object getEntity(EntitySnapshot snapshot, EntityMetadata metadata)
          Assemble the specified snapshot to a persistent entity.
 Object getEntityForProxy(ProxyEntitySnapshot proxy, EntityMetadata metadata)
          Retrieves a reference for the specified proxy snapshot.
 Class<?> getPersistentClass(Object entity)
          Returns the persistent class for the specified entity.
 PimentoConfig getPimentoConfig()
          Returns the Pimento configuration for this context instance.
 EntitySnapshot getSnapshot(Object entity, EntityMetadata metadata, FetchPlan fetchPlan)
          Disassemble the specified entity to a snapshot representation.
 EntitySnapshot getSnapshot(Object entity, EntityMetadata metadata, FetchPlan fetchPlan, boolean lazy)
          Disassemble the specified entity to a snapshot representation.
 boolean isUnitializedProxy(Object entity)
          Checks whether the specified entity is an uninitialized proxy.
 void prefetchUpdatedEntities(List<ApplicableEntitySnapshot> updatedEntities)
          Prefetches all updated entities from the database and applies all changes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IoContext

public IoContext(PimentoConfig config,
                 EntityManager em,
                 Operation operation)
Creates a new instance.

Parameters:
config - the Pimento configuration
em - the EntityManager
operation - the current operation
Method Detail

getPimentoConfig

public PimentoConfig getPimentoConfig()
Returns the Pimento configuration for this context instance.

Returns:
the Pimento configuration for this context instance

prefetchUpdatedEntities

public void prefetchUpdatedEntities(List<ApplicableEntitySnapshot> updatedEntities)
Prefetches all updated entities from the database and applies all changes.

Parameters:
updatedEntities - list of snapshots that contain the updates to process

getEntityForProxy

public Object getEntityForProxy(ProxyEntitySnapshot proxy,
                                EntityMetadata metadata)
Retrieves a reference for the specified proxy snapshot.

Parameters:
proxy - the proxy snapshot to retrieve a reference for
metadata - the metadata for the entity
Returns:
the entity reference for the specified snapshot

getEntity

public Object getEntity(EntitySnapshot snapshot,
                        EntityMetadata metadata)
Assemble the specified snapshot to a persistent entity. For snapshots that were already processed this method returns an existing entity instance.

Parameters:
snapshot - the snapshot to process
metadata - the metadata for the entity
Returns:
the assembled persistent entity

getSnapshot

public EntitySnapshot getSnapshot(Object entity,
                                  EntityMetadata metadata,
                                  FetchPlan fetchPlan)
Disassemble the specified entity to a snapshot representation. For entities that were already processed this method returns an existing snapshot instance.

Parameters:
entity - the entity to disassemble
metadata - the metadata for the entity
fetchPlan - the fetch plan to use
Returns:
the snapshot representation of the entity

getSnapshot

public EntitySnapshot getSnapshot(Object entity,
                                  EntityMetadata metadata,
                                  FetchPlan fetchPlan,
                                  boolean lazy)
Disassemble the specified entity to a snapshot representation. For entities that were already processed this method returns an existing snapshot instance.

Parameters:
entity - the entity to disassemble
metadata - the metadata for the entity
fetchPlan - the fetch plan to use
lazy - whether the entity should be lazily fetched
Returns:
the snapshot representation of the entity

isUnitializedProxy

public boolean isUnitializedProxy(Object entity)
Checks whether the specified entity is an uninitialized proxy.

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

getPersistentClass

public Class<?> getPersistentClass(Object entity)
Returns the persistent class for the specified entity.

Parameters:
entity - the entity to return the persistent class for
Returns:
the persistent class for the specified entity