Package org.alfresco.repo.domain.propval
Class DefaultPropertyTypeConverter
java.lang.Object
org.alfresco.repo.domain.propval.DefaultPropertyTypeConverter
- All Implemented Interfaces:
PropertyTypeConverter
Default converter for handling data going to and from the persistence layer.
Properties are stored as a set of well-defined types defined by the enumeration
PropertyValueEntity.PersistedType. Ultimately, data can be persisted as BLOB data, but must be the last resort.- Since:
- 3.2
- Author:
- Derek Hulley
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Map<Class<?>,PropertyValueEntity.PersistedType> An unmodifiable map of types and how they should be persisted -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddTypeMapping(Class<?> clazz, PropertyValueEntity.PersistedType targetType) Allow subclasses to add further type mappings specific to the implementationconstructInstance(String clazzName) Construct an instance of an object that was deemed to bePropertyValueEntity.PersistedType.CONSTRUCTABLE.<T> Tconvert(Class<T> targetClass, Serializable value) Performs the conversion usingDefaultTypeConverterbut also adds special handling forenum types.getPersistentType(Serializable value) When external to persisted type mappings are not obvious, the persistence framework, before persisting asPropertyValueEntity.PersistedType.SERIALIZABLE, will give the converter a chance to choose how the value must be persisted:PropertyValueEntity.PersistedType.LONGPropertyValueEntity.PersistedType.DOUBLEPropertyValueEntity.PersistedType.STRINGPropertyValueEntity.PersistedType.SERIALIZABLEPropertyValueEntity.PersistedType.CONSTRUCTABLEThe converter should returnPropertyValueEntity.PersistedType.SERIALIZABLEif no further conversions are possible.protected booleanisConstructable(Serializable value) Determines if the value can be adequately recreated (to equality) by creating a new instance.
-
Field Details
-
defaultPersistedTypesByClass
An unmodifiable map of types and how they should be persisted
-
-
Constructor Details
-
DefaultPropertyTypeConverter
public DefaultPropertyTypeConverter()Default constructor
-
-
Method Details
-
addTypeMapping
Allow subclasses to add further type mappings specific to the implementation- Parameters:
clazz- the class to be convertedtargetType- the target persisted type
-
isConstructable
Determines if the value can be adequately recreated (to equality) by creating a new instance. For example, a java.util.HashMap is constructable provided that the map is empty.Subclasses can override this to handle any well-known types, and in conjunction with
constructInstance(String), even choose to return true if it needs a non-default constructor.- Parameters:
value- the value to check- Returns:
- Returns true if the value can be reconstructed by instantiation using a default constructor
-
constructInstance
Construct an instance of an object that was deemed to bePropertyValueEntity.PersistedType.CONSTRUCTABLE.- Specified by:
constructInstancein interfacePropertyTypeConverter- Parameters:
clazzName- the name of the class- Returns:
- Returns the new instance
-
getPersistentType
When external to persisted type mappings are not obvious, the persistence framework, before persisting asPropertyValueEntity.PersistedType.SERIALIZABLE, will give the converter a chance to choose how the value must be persisted:PropertyValueEntity.PersistedType.LONGPropertyValueEntity.PersistedType.DOUBLEPropertyValueEntity.PersistedType.STRINGPropertyValueEntity.PersistedType.SERIALIZABLEPropertyValueEntity.PersistedType.CONSTRUCTABLE
PropertyValueEntity.PersistedType.SERIALIZABLEif no further conversions are possible. Implicit in the return value is the converter's ability to do the conversion when required. If the converter can fully reconstruct an equal instance using just the name of the value's class, thenPropertyValueEntity.PersistedType.CONSTRUCTABLEcan be used.- Specified by:
getPersistentTypein interfacePropertyTypeConverter- Parameters:
value- the value that does not have an obvious persistence slot- Returns:
- Returns the type of persistence to use
-
convert
Performs the conversion usingDefaultTypeConverterbut also adds special handling forenum types.- Specified by:
convertin interfacePropertyTypeConverter- Parameters:
targetClass- the desired type to convert tovalue- the value to convert- Returns:
- Returns the persisted type and value to persist
-