org.spicefactory.pimento.io
Class TypeHandler<S extends TypeSnapshot,T extends ManagedType>

java.lang.Object
  extended by org.spicefactory.pimento.io.TypeHandler<S,T>
Direct Known Subclasses:
EmbeddableHandler, EntityHandler

public abstract class TypeHandler<S extends TypeSnapshot,T extends ManagedType>
extends Object

Responsible for managing a particular persistent type.

Author:
Jens Halm

Constructor Summary
protected TypeHandler(Object instance, S snapshot, T type, EntityState state)
          Creates a new instance.
 
Method Summary
protected  void applyUpdates(PropertyChangeSet changeSet)
          Applies the specified change set to the entity managed by this instance.
protected  void assertUpdatePermitted(ManagedProperty property)
          Assert whether an update for the specified property is permitted
 Object getInstance()
          Returns the entity instance.
 S getSnapshot()
          Returns the snapshot representation of the entity instance.
 EntityState getState()
          The persistent state of the entity.
 T getType()
          Returns the metamodel of the entity.
protected  Object getValueForSnapshot(ManagedProperty property, SnapshotEncoder encoder, FetchMode fetchMode)
          Return the value to be included in a snapshot for the specified property.
 void populateSnapshot(SnapshotEncoder encoder, FetchPlan fetchPlan)
          Populates the snapshot of the entity managed by this instance.
protected  void populateSnapshot(SnapshotEncoder encoder, FetchPlan fetchPlan, EntityEncoder entityEncoder)
          Populates the snapshot of the entity managed by this instance.
protected  PropertyChangeSet prepareChangeSet(SnapshotDecoder decoder)
          Prepares a change set that may later be applied to the snapshot and entity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeHandler

protected TypeHandler(Object instance,
                      S snapshot,
                      T type,
                      EntityState state)
Creates a new instance.

Parameters:
instance - the entity instance to manage
snapshot - the snapshot representation of the entity instance
type - the metamodel of the entity
state - the state of the entity
Method Detail

getInstance

public Object getInstance()
Returns the entity instance.

Returns:
the entity instance

getSnapshot

public S getSnapshot()
Returns the snapshot representation of the entity instance.

Returns:
the snapshot representation of the entity instance

getType

public T getType()
Returns the metamodel of the entity.

Returns:
the metamodel of the entity

getState

public EntityState getState()
The persistent state of the entity.

Returns:
the persistent state of the entity

populateSnapshot

public void populateSnapshot(SnapshotEncoder encoder,
                             FetchPlan fetchPlan)
Populates the snapshot of the entity managed by this instance.

Parameters:
encoder - the encoder to use for encoding associations
fetchPlan - the effective fetch plan

populateSnapshot

protected void populateSnapshot(SnapshotEncoder encoder,
                                FetchPlan fetchPlan,
                                EntityEncoder entityEncoder)
Populates the snapshot of the entity managed by this instance.

Parameters:
encoder - the encoder to use for encoding associations
fetchPlan - the effective fetch plan
entityEncoder - the encode specifying potential exclusions

getValueForSnapshot

protected Object getValueForSnapshot(ManagedProperty property,
                                     SnapshotEncoder encoder,
                                     FetchMode fetchMode)
Return the value to be included in a snapshot for the specified property.

Parameters:
property - the property to return the snapshot value for
encoder - the encoder to use for encoding associations
fetchMode - the effective fetch mode for the property
Returns:
the value to be included in a snapshot for the specified property

prepareChangeSet

protected PropertyChangeSet prepareChangeSet(SnapshotDecoder decoder)
Prepares a change set that may later be applied to the snapshot and entity.

Parameters:
decoder - the decoder to use for decoding associations
Returns:
a change set that may later be applied to the entity

applyUpdates

protected void applyUpdates(PropertyChangeSet changeSet)
Applies the specified change set to the entity managed by this instance.

Parameters:
changeSet - the change set to apply

assertUpdatePermitted

protected void assertUpdatePermitted(ManagedProperty property)
Assert whether an update for the specified property is permitted

Parameters:
property - the property to check