Package org.alfresco.repo.domain.propval
Class DefaultPropertyTypeConverter
- java.lang.Object
-
- org.alfresco.repo.domain.propval.DefaultPropertyTypeConverter
-
- All Implemented Interfaces:
PropertyTypeConverter
public class DefaultPropertyTypeConverter extends java.lang.Object implements 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 enumerationPropertyValueEntity.PersistedType. Ultimately, data can be persisted as BLOB data, but must be the last resort.- Since:
- 3.2
- Author:
- Derek Hulley
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.util.Map<java.lang.Class<?>,PropertyValueEntity.PersistedType>defaultPersistedTypesByClassAn unmodifiable map of types and how they should be persisted
-
Constructor Summary
Constructors Constructor Description DefaultPropertyTypeConverter()Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddTypeMapping(java.lang.Class<?> clazz, PropertyValueEntity.PersistedType targetType)Allow subclasses to add further type mappings specific to the implementationjava.io.SerializableconstructInstance(java.lang.String clazzName)Construct an instance of an object that was deemed to bePropertyValueEntity.PersistedType.CONSTRUCTABLE.<T> Tconvert(java.lang.Class<T> targetClass, java.io.Serializable value)Performs the conversion usingDefaultTypeConverterbut also adds special handling forenum types.PropertyValueEntity.PersistedTypegetPersistentType(java.io.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(java.io.Serializable value)Determines if the value can be adequately recreated (to equality) by creating a new instance.
-
-
-
Field Detail
-
defaultPersistedTypesByClass
protected static final java.util.Map<java.lang.Class<?>,PropertyValueEntity.PersistedType> defaultPersistedTypesByClass
An unmodifiable map of types and how they should be persisted
-
-
Method Detail
-
addTypeMapping
protected void addTypeMapping(java.lang.Class<?> clazz, PropertyValueEntity.PersistedType targetType)Allow subclasses to add further type mappings specific to the implementation- Parameters:
clazz- the class to be convertedtargetType- the target persisted type
-
isConstructable
protected boolean isConstructable(java.io.Serializable value)
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
public java.io.Serializable constructInstance(java.lang.String clazzName)
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
public PropertyValueEntity.PersistedType getPersistentType(java.io.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.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
public <T> T convert(java.lang.Class<T> targetClass, java.io.Serializable value)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
-
-