org.spicefactory.pimento.type
Interface PropertyType

All Known Implementing Classes:
AbstractAssociationType, AbstractCollectionType, AbstractPropertyType, AbstractUnindexedCollectionType, AssociationType, BagType, BooleanType, DateType, EnumType, ListType, MapType, NumberType, SetType, StringType

public interface PropertyType

Represents a single type of property and encapsulates the mechanism with which values for that type are converted from and to entity snapshots.

Author:
Jens Halm

Method Summary
 Object getValueForSnapshot(Object entity, Property property, IoContext context, FetchMode fetchMode)
          Reads the specified property from the given entity and returns it in a form suitable for inclusion in an entity snapshot.
 Object prepareValueFromSnapshot(Object entity, Object value, Property property, IoContext context, boolean createChangeSet)
          Prepares the specified property value, performing all necessary conversions, but without actually applying it to the specified entity.
 void setValue(Object entity, Object value, Property property)
          Sets the specified property value of the given entity.
 

Method Detail

getValueForSnapshot

Object getValueForSnapshot(Object entity,
                           Property property,
                           IoContext context,
                           FetchMode fetchMode)
Reads the specified property from the given entity and returns it in a form suitable for inclusion in an entity snapshot. For associations this means that non-null values should be converted to snapshots themselves, using the provided IoContext instance. Simple values could be returned as-is in most cases.

Parameters:
entity - the entity to extract the property value from
property - the property to extract
context - the active IoContext
fetchMode - the fetchMode to use if the property type is an association
Returns:
the current value of the property as a simple value, an entity snapshot or an instance of PropertyState

prepareValueFromSnapshot

Object prepareValueFromSnapshot(Object entity,
                                Object value,
                                Property property,
                                IoContext context,
                                boolean createChangeSet)
Prepares the specified property value, performing all necessary conversions, but without actually applying it to the specified entity. The prepared values will be collected in a EntityUpdate instance which gets passed to any configured interceptors before the property is applied with the setValue method of this class.

Parameters:
entity - the entity to prepare the property for
value - the new value for the property
property - the property to prepare
context - the active IoContext
createChangeSet - whether a change set is being created
Returns:
the (possibly converted) value of the property as it will later be applied to the entity.

setValue

void setValue(Object entity,
              Object value,
              Property property)
Sets the specified property value of the given entity. This method can safely assume that the value has been property prepared (possibly converted) with the prepareValueFromSnapshot method of this class before this method gets invoked.

Parameters:
entity - the entity to set the property for
value - the new value for the property
property - the property to set