Uploaded image for project: 'Alfresco'
  1. Alfresco
  2. ALF-10838

Extensible node property value persistence


    • 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:


      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>() {

      public Long convert(final PriorityCode source)

      { // DAO call final Pair<Long, PriorityCode> priorityCode = createPriorityCode(source); final Long result = priorityCode != null ? priorityCode.getFirst() : null; return result; }


      // conversion from persistent value type to runtime value type
      DefaultTypeConverter.INSTANCE.addConverter(Long.class, PriorityCode.class, new Converter<Long, PriorityCode>() {

      public PriorityCode convert(final Long source)

      { // DAO call final Pair<Long, PriorityCode> priorityCode = getPriorityCode(source); final PriorityCode result = priorityCode != null ? priorityCode.getSecond() : null; return result; }


      4) Register the custom ValueType, e.g.

      ValueTypeRegistry.addValueType(new ValueType(){

      public Serializable convert(final Serializable value)

      { final Serializable result = DefaultTypeConverter.INSTANCE.convert(PriorityCode.class, value); return result; }

      public String getName()

      { return "PRIORITY_CODE"; }

      public int getOrdinalNumber()

      { // a globally unique ordinal (Alfresco uses 1 - 21) // use 1xx as our business specific ordinal range return 101; }

      public CoreValueType getPersistedType(Serializable value)

      { // persist as Long (the reason for our type converters) return CoreValueType.LONG; }

      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>

      <namespace uri="http://www.basf.com/model/poc/pocModel/1.0"
      prefix="basfpoc" />


      <data-type name="basfpoc:priorityCode">

      6) Use your new data type in your custom node types and aspects





              • Assignee:
                closedissues Closed Issues
                afaust Axel Faust
              • Votes:
                0 Vote for this issue
                3 Start watching this issue


                • Created:
                  Date of First Response:

                  Structure Helper Panel