Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Some scenarios require that a value be stored in a database column in one form and written to and read from the database column in another form. Servoy supports this requirement with a feature called Column Conversion and it has three applications, : String Serialization, Blob Serialization and Global Method Conversion.
Servoy also

String Serialization

Servoy supports object persistence using String Serialization, which involves the conversion of a runtime object into a string format, which can then persist in a database column. When the column is read from the database, the persistent string will be deserialized back into a runtime object. Because Servoy uses JavaScript as its scripting language, runtime objects will be serialized into standard JSON format.

...

The column is bound to two methods which facilitate the conversion between the Object Value and the Database Value. A developer may also specify an optional Object Data Type, prompting Servoy to provide the data in an alternate data type in lieu of the default column type. This is useful when values are stored in a non-standard storage type to accommodate legacy systems, but should be treated like standard data type in the runtime. 

Column Converter from Java code (plugin)

A Column converter can be contributed by a java plugin.
To do this, the plugin must implement interface IColumnConverterProvider to produce IColumnConverter instances in the getColumnConverters() method, see http://www.servoy.com/docs/public-api/70x/com/servoy/j2db/plugins/IColumnConverterProvider.html.

An IColumnConverter converter has 3 methods, similar to the GlobalMethodConverter:

  • convertFromObject()
    Convert from Object value to database value
  • convertToObject()
    Converts from database value to Object value
  • type (one of TEXT, INTEGER, NUMBER, DATETIME or MEDIA)
    The Object data type (so the resulting type of the convertToObject()).
Object to Database Method

This method is called anytime a value is written to the data provider. It will be called regardless of the origin of the action, i.e. GUI event or programmatically. It will be called before data is committed to the database.

...

A UI converter can be contributed by a java plugin.
To do this, the plugin must implement interface IUIConverterProvider to produce IUIConverter instances in the getUIConverters() method, see http://www.servoy.com/docs/public-api/70x/com/servoy/j2db/plugins/IUIConverterProvider.html.

A An IUIConverter converter has 3 methods, similar to the GlobalMethodConverter:

...