org.spicefactory.pimento.metadata
Class EntityMetadata

java.lang.Object
  extended by org.spicefactory.pimento.metadata.EntityMetadata
All Implemented Interfaces:
Externalizable

public class EntityMetadata
extends Object
implements Externalizable

The metadata for a single persistent entity type.

Author:
Jens Halm

Constructor Summary
EntityMetadata()
          Creates a new instance.
 
Method Summary
 void addInterceptor(Class<? extends Annotation> interceptorType, Object interceptor, MethodInvoker invoker)
          Adds an interceptor for this entity type.
 void applyUpdate(Object entity, EntityUpdate update)
          Applies the specified update to the given entity.
 Object getEntityId(Object entity)
          Retrieves the id for the specified entity.
 int getId()
          Returns the id for this entity metadata.
 PropertyMetadata getIdProperty()
          Returns the property holding the entity id.
 String getLogString(Object entity)
          Retrieves log output for the specified entity
 EntityMetadata getMetadataById(int id)
          Retrieves the metadata for the specified id, if it corresponds to this entity or to a subclass of this entity.
 EntityMetadata getMetadataForClass(Class<?> persistentClass)
          Retrieves the metadata for the specified persistent class, if its type is a subclass of this entity or the entity class itself.
 Set<Operation> getOperations()
          Returns the EnityManager operations permitted for the client.
 List<PropertyMetadata> getProperties()
          Returns all property metadata for this entity.
 PropertyMetadata getPropery(String name)
          Returns the property metadata for the specified property name.
 EntityMetadata getSuperclass()
          Returns the metadata for the persistent superclass.
 Class<?> getType()
          Returns the entity type.
 boolean hasOperation(Operation op)
          Checks whether the specified EntityManager operation is permitted for the client
 void invokeInterceptors(Class<? extends Annotation> type, Object entity, Operation operation)
          Invokes the interceptors for the specified type and operation.
 void invokeInterceptors(Object entity, EntityEncoder encoder, Operation operation)
          Invokes the load interceptor for the specified operaion.
 void invokeInterceptors(Object entity, EntityUpdate update, Operation operation)
          Invokes the merge interceptor for the specified operaion.
 boolean isRefreshable()
          Checks whether this entity contains any properties marked as refreshable.
 void populateFullSnapshot(Object entity, FullEntitySnapshot snapshot, FetchPlan fetchPlan, IoContext context, EntityEncoder encoder)
          Populates the specified snapshot with property values from the specified entity.
 void populateRefreshedSnapshot(Object entity, PartialEntitySnapshot snapshot, IoContext context)
          Populates the specified snapshot with property values from the specified entity.
 void readExternal(DataInput input)
          Restores the content of this object from the DataInput instance.
 void setSuperclass(EntityMetadata superMetadata)
          Sets the metadata for the pesistent superclass of this entity.
 void writeExternal(DataOutput output)
          Saves the content of this object to the DataOutput instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EntityMetadata

public EntityMetadata()
Creates a new instance. The default constructor will only be used by the Cinnamon AMF engine.

Method Detail

getId

public int getId()
Returns the id for this entity metadata.

Returns:
the id for this entity metadata.

getType

public Class<?> getType()
Returns the entity type.

Returns:
the entity type

getIdProperty

public PropertyMetadata getIdProperty()
Returns the property holding the entity id.

Returns:
the property holding the entity id.

getProperties

public List<PropertyMetadata> getProperties()
Returns all property metadata for this entity.

Returns:
all property metadata for this entity.

getPropery

public PropertyMetadata getPropery(String name)
Returns the property metadata for the specified property name.

Parameters:
name - the name of the property
Returns:
the property metadata for the specified property name

getOperations

public Set<Operation> getOperations()
Returns the EnityManager operations permitted for the client.

Returns:
the EnityManager operations permitted for the client

hasOperation

public boolean hasOperation(Operation op)
Checks whether the specified EntityManager operation is permitted for the client

Parameters:
op - the operation to check
Returns:
true if the specified operation is permitted for the client

getEntityId

public Object getEntityId(Object entity)
Retrieves the id for the specified entity.

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

getLogString

public String getLogString(Object entity)
Retrieves log output for the specified entity

Parameters:
entity - the entity to log
Returns:
log output for the specified entity

populateFullSnapshot

public void populateFullSnapshot(Object entity,
                                 FullEntitySnapshot snapshot,
                                 FetchPlan fetchPlan,
                                 IoContext context,
                                 EntityEncoder encoder)
Populates the specified snapshot with property values from the specified entity.

Parameters:
entity - the entity to extract property values from
snapshot - the snapshot to populate
fetchPlan - the fetch plan to use for the entity
context - the active IoContext
encoder - the encoder instance for the specified entity

populateRefreshedSnapshot

public void populateRefreshedSnapshot(Object entity,
                                      PartialEntitySnapshot snapshot,
                                      IoContext context)
Populates the specified snapshot with property values from the specified entity. This method will only consider properties that have been annotated with @Refreshable.

Parameters:
entity - the entity to extract property values from
snapshot - the partial snapshot to populate
context - the active IoContext

applyUpdate

public void applyUpdate(Object entity,
                        EntityUpdate update)
Applies the specified update to the given entity.

Parameters:
entity - the entity to apply the update for
update - the update to apply

addInterceptor

public void addInterceptor(Class<? extends Annotation> interceptorType,
                           Object interceptor,
                           MethodInvoker invoker)
Adds an interceptor for this entity type.

Parameters:
interceptorType - the interceptor type
interceptor - the interceptor instance
invoker - the interceptor method

invokeInterceptors

public void invokeInterceptors(Class<? extends Annotation> type,
                               Object entity,
                               Operation operation)
Invokes the interceptors for the specified type and operation.

Parameters:
type - the interceptor type
entity - the affected entity
operation - the current operation or null if this is not an EntityManager operation

invokeInterceptors

public void invokeInterceptors(Object entity,
                               EntityUpdate update,
                               Operation operation)
Invokes the merge interceptor for the specified operaion.

Parameters:
entity - the affected entity
update - the currently processed entity update
operation - the current operation or null if this is not an EntityManager operation

invokeInterceptors

public void invokeInterceptors(Object entity,
                               EntityEncoder encoder,
                               Operation operation)
Invokes the load interceptor for the specified operaion.

Parameters:
entity - the affected entity
encoder - the encoder for the currently processed entity
operation - the current operation or null if this is not an EntityManager operation

getSuperclass

public EntityMetadata getSuperclass()
Returns the metadata for the persistent superclass. Will be null if the superclass of this entity is not persistent.

Returns:
the metadata for the persistent superclass or null

setSuperclass

public void setSuperclass(EntityMetadata superMetadata)
Sets the metadata for the pesistent superclass of this entity.

Parameters:
superMetadata - the metadata for the pesistent superclass of this entity

getMetadataForClass

public EntityMetadata getMetadataForClass(Class<?> persistentClass)
Retrieves the metadata for the specified persistent class, if its type is a subclass of this entity or the entity class itself. This method is used to retrieve the matching metadata for polymorphic associations.

Parameters:
persistentClass - the type to retrieve the metadata for
Returns:
the metadata for the specified persistent class or null if no such metadata exists

getMetadataById

public EntityMetadata getMetadataById(int id)
Retrieves the metadata for the specified id, if it corresponds to this entity or to a subclass of this entity. This method is used to retrieve the matching metadata for polymorphic associations.

Parameters:
id - the metadata id
Returns:
the metadata for the specified id or null if no such metadata exists

isRefreshable

public boolean isRefreshable()
Checks whether this entity contains any properties marked as refreshable.

Returns:
true if this entity contains any properties marked as refreshable

readExternal

public void readExternal(DataInput input)
Description copied from interface: Externalizable
Restores the content of this object from the DataInput instance. Values must be read in the same sequence as they were written on the client side.

Specified by:
readExternal in interface Externalizable
Parameters:
input - the AMF3 data to read from

writeExternal

public void writeExternal(DataOutput output)
Description copied from interface: Externalizable
Saves the content of this object to the DataOutput instance.

Specified by:
writeExternal in interface Externalizable
Parameters:
output - the output to write to