Detail
#28074
Cache application values of primitive types in the persistence layer
Currently, primitive model types for which there is no direct support at database level are converted from the database value (string, number, ...) to the respective application value (color, country, ...) when they are accessed. As the conversion takes place during access, this conversion is carried out again with each access. For many values, this is completely sufficient if either the accesses are infrequent or the conversion is trivial.
However, this procedure is not ideal for more complex values. It would be better to convert when loading from the database and cache the application value instead of the storage value.
Application
To cache a primitive attribute with a complex application type (which cannot be stored directly in the database) at DB level, the following steps must be carried out:
- Define the database column for the attribute. When defining the column, declare the storage primitive-column-storage with the storage mapping of the primitive type: {{{
<mo_attribute att_name="color" att_type="String" mandatory="false" db_size="16">
<primitive-column-storage
storage-mapping="com.top_logic.element.meta.complex.ColorValueProvider"
/>
</mo_attribute>
}}}
- Define the storage algorithm primitive-storage with the storage mapping "Direct-Mapping" and the application type of the attribute in the model: {{{
<property name="color"
type="tl.util:Color"
>
<annotations>
<storage-algorithm>
<primitive-storage>
<storage-mapping class="com.top_logic.element.meta.kbbased.storage.mappings.DirectMapping"
application-type="java.awt.Color"
/>
</primitive-storage>
</storage-algorithm>
</annotations>
</property>
}}}
- When changing in an update, formulate a migration statement: {{ <processors>
<add-mo-attribute table="DemoTypes">
<mo_attribute att_name="color" att_type="String" mandatory="false" db_size="16">
<primitive-column-storage
storage-mapping="com.top_logic.element.meta.complex.ColorValueProvider"
/>
</mo_attribute>
</add-mo-attribute>
<add-annotations name="DemoTypes:DemoTypes.A#color">
<annotations>
<storage-algorithm>
<primitive-storage>
<storage-mapping class="com.top_logic.element.meta.kbbased.storage.mappings.DirectMapping"
application-type="java.awt.Color"
/>
</primitive-storage>
</storage-algorithm>
</annotations>
</add-annotations>
</processors>
}}}
Test
The attribute "color" in tl-demo is now cached at DB level and no longer converted on access.