org.spicefactory.pimento.io
Class EntityHandler

java.lang.Object
  extended by org.spicefactory.pimento.io.TypeHandler<EntitySnapshot,Entity>
      extended by org.spicefactory.pimento.io.EntityHandler

public class EntityHandler
extends TypeHandler<EntitySnapshot,Entity>

Responsible for managing a particular entity type.

Author:
Jens Halm

Method Summary
protected  void applyUpdates(PropertyChangeSet changeSet)
          Applies the specified change set to the entity managed by this instance.
static Object convertEntityId(Object value, Entity entity)
          Convert the specified value to the corresponding target type of the id property of the specified entity type.
static Object getEntityId(Object instance, Entity entity)
          Retrieves the id for the specified entity.
 void invalidateSnapshot()
          Invalidates the snapshot managed by this instance.
 boolean isRefreshable()
          Indicates whether the entity type managed by this handler contains refreshable properties.
 void populateSnapshot(SnapshotEncoder encoder, FetchPlan fetchPlan)
          Populates the snapshot of the entity managed by this instance.
 void setSnapshotId()
          Sets the id for the snapshot managed by this instance.
 
Methods inherited from class org.spicefactory.pimento.io.TypeHandler
assertUpdatePermitted, getInstance, getSnapshot, getState, getType, getValueForSnapshot, populateSnapshot, prepareChangeSet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getEntityId

public static Object getEntityId(Object instance,
                                 Entity entity)
Retrieves the id for the specified entity.

Parameters:
instance - the entity to retrieve the id for
entity - the metamodel for the entity
Returns:
the id for the specified entity

convertEntityId

public static Object convertEntityId(Object value,
                                     Entity entity)
Convert the specified value to the corresponding target type of the id property of the specified entity type.

Parameters:
value - the property value to convert
entity - the metamodel for the entity
Returns:
the converted property value

isRefreshable

public boolean isRefreshable()
Indicates whether the entity type managed by this handler contains refreshable properties. For transient instances this method always returns true since the primary key value must be managed for the client.

Returns:
true if the entity type managed by this handler contains refreshable properties

applyUpdates

protected void applyUpdates(PropertyChangeSet changeSet)
Description copied from class: TypeHandler
Applies the specified change set to the entity managed by this instance.

Overrides:
applyUpdates in class TypeHandler<EntitySnapshot,Entity>
Parameters:
changeSet - the change set to apply

setSnapshotId

public void setSnapshotId()
Sets the id for the snapshot managed by this instance. The value will be read from the entity instance.


invalidateSnapshot

public void invalidateSnapshot()
Invalidates the snapshot managed by this instance. This method will be invoked for transient instance that were sent from the client but were never persisted on the server. Such an entity may not be included in responses.


populateSnapshot

public void populateSnapshot(SnapshotEncoder encoder,
                             FetchPlan fetchPlan)
Description copied from class: TypeHandler
Populates the snapshot of the entity managed by this instance.

Overrides:
populateSnapshot in class TypeHandler<EntitySnapshot,Entity>
Parameters:
encoder - the encoder to use for encoding associations
fetchPlan - the effective fetch plan