javatelosys

Telosys Type Overriding - `timestamp` -> `OffsetDateTime`


My entities contain a timestamp attribute that is getting converted to a LocalDateTime as the docs specify. However, I would like to convert the timestamp into an OffsetDateTime. Is there any way to override the default conversion behavior?

This question mentions a .dbrep, but I don't have such a file in my project.


Solution

  • You can't override the default conversion behavior,
    but you can change the type in the templates (.vm files) using Velocity language.

    1. If you want to convert the type systematically (for all attributes of all entities) you can proceed like these:

    #if ( $attribute.neutralType == 'timestamp' )
    #set ($mytype = 'OffsetDateTime')
    #else
    #set ($mytype = $attribute.simpleType )
    #end

    if this operation must be repeated in several templates you can define a macro

    1. If you want to force the conversion only for some attributes :

    myField : timestamp { #tagetType(OffsetDateTime) } ;

    $attribute.tagValue( 'targetType', $attribute.simpleType )

    In both cases, do not forget to import 'java.time.OffsetDateTime'