-
Type:
Contribution
-
Status: Closed
-
Priority:
Unprioritized
-
Resolution: Won't Fix
-
Affects Version/s: 3.4 Enterprise, 4.0.a Community
-
Fix Version/s: None
-
Component/s: Repository
-
Security Level: external (External user)
-
Labels:None
Currently, the product only provides specific persistence mechanisms for types, entities and DAOs shipped with Alfresco. Although developers are able to define new data types using the dictionary bootstraps, they have no control over how these data types are persisted. Certain types may require specific persistence mechanisms in order to support scalability, performance and specific business features (i.e. querying of value realm), which is not possible with the default persistence of any unrecognized types as Serializable. Alfresco itself uses type specific persistence logic for handling content data, which is only referenced by the node properties table.
The attached patch file contains the changes necessary to make the node property value persistence code extensible. It enhances the already existing concept of a ValueType as an abstraction layer and allows developers to both implement new ValueTypes and associate their custom data types with a specific ValueType defining the behavior in regards to persistence (persisted type and conversion). Through integration with the converter registry, Alfresco is able to persist and load any type of property value without resorting to Serializable as long as the developer provides the necessary conversion logic.
With this enhancement, the following steps are necessary to add a new property data type with a custom DAO component for persistence:
1) Implement the value type class which has to implement Serializable
2) Implement your custom DAO component (may use any persistence technology, but assumed to use custom MyBatis mapping)
3) Hook up DAO component via converter registry, e.g.
// conversion from runtime value type to persistent value type
DefaultTypeConverter.INSTANCE.addConverter(PriorityCode.class, Long.class, new Converter<PriorityCode, Long>() {
@Override
public Long convert(final PriorityCode source)
});
// conversion from persistent value type to runtime value type
DefaultTypeConverter.INSTANCE.addConverter(Long.class, PriorityCode.class, new Converter<Long, PriorityCode>() {
@Override
public PriorityCode convert(final Long source)
});
4) Register the custom ValueType, e.g.
ValueTypeRegistry.addValueType(new ValueType(){
@Override
public Serializable convert(final Serializable value)
@Override
public String getName()
@Override
public int getOrdinalNumber()
@Override
public CoreValueType getPersistedType(Serializable value)
@Override
public boolean isInstance(Serializable value) {
return PriorityCode.class.isInstance(value);
}});
5) Model your custom data types, e.g.
<?xml version="1.0" encoding="UTF-8"?>
<model name="basfpoc:pocModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
<description>BASF POC Model</description>
<author>PRODYNA AG</author>
<version>1.0</version>
<namespaces>
<namespace uri="http://www.basf.com/model/poc/pocModel/1.0"
prefix="basfpoc" />
</namespaces>
<data-types>
<data-type name="basfpoc:priorityCode">
<analyser-class>org.alfresco.repo.search.impl.lucene.analysis.AlfrescoStandardAnalyser</analyser-class>
<java-class>com.basf.alfresco.poc.repository.model.PriorityCode</java-class>
<value-type>PRIORITY_CODE</value-type>
</data-type>
</data-types>
</model>
6) Use your new data type in your custom node types and aspects