Versions Compared

Key

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

...

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.

Parameters

Object - The value that is being written to the data provider

...

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.

Parameters

Object - The value that is being written to the data provider

String - The column's data type: TEXT, INTEGER, NUMBER, DATETIME, MEDIA

...

Code Block
/**
 * This method converts Text data stored in the database column, presenting it as Date object
 * @parameter {Object} value The value stored in the column
 * @parameter {String} columnType The data type of the column
 * @returns {Object} The value that was converted
 * @properties={typeid:24,uuid:"16BDC049-E63B-47C4-B49C-595D916FD51B"}
 */
function dbToObj(value, columnType) {
	return utils.dateFormat(value,'MMddyyyy');
}
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()).

Calculations

A Calculation is very much like a database column, except that its value, rather than being stored, is dynamically computed each time it is requested. This is achieved by creating a JavaScript function which is bound to a database table. The function takes no arguments and returns a value, which like a real database column, is declared to be one of the five general data types. The scope of the JavaScript function is an individual record object. Therefore any of the record's other data providers, and related foundsets are immediately available, as well as global variables and globally related foundsets.

...