This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

--Userdefined ColumnMetaData and ColumnDefinition

Documents for the development of and with JVx.

--Userdefined ColumnMetaData and ColumnDefinition

Postby Development@SIB » Wed Mar 18, 2015 4:11 pm



This article is outdated - please use our new system at

https://doc.sibvisions.com




MetaData are an important element of JVx' model. Every column, used in DataBook or Editor has a ColumnDefinition internally. This controls which Editor will be used (Date, Text, Number, Selection, ...), the datatype of the column, how many characters can be entered, etc. A ColumnDefinition is created from Metadata. The Metadata are generated on server-side.

In simplest case, the metadata are read from the database, if a database is used. The metadata creation is done automatically and, usually, requires no changes.

However, it may be necessary in certain situations to adapt the standard mechanism to your own needs, e.g. add additional information, define standard values with your own algorithm or set specific labels.

Working with your own metadata means that you understand the default behavior:

The class DBAccess is responsible for creating metadata from database tables and views. It also enables you to change default metadata creation and to implement your own requirements.

DBAccess is a server-side class. The metadata thus generated are transferred to the client as needed and the model takes care of the conversion.

The creation of custom metadata is explained by the following example.

We want to extend the metadata with an additional field. It contains detail information about the field.

1. Create your own implementations of ColumnMetaData and ColumnDefinition
Syntax: [ Download ] [ Hide ]
public static class MyColumnMetaData extends ColumnMetaData
{
    private String columnInfo;
   
    public String getColumnInfo()
    {
        return columnInfo;
    }
   
    public void setColumnInfo(String pColumnInfo)
    {
        columnInfo = pColumnInfo;
    }
   
    public ColumnDefinition createColumnDefinition() throws ModelException
    {
        MyColumnDefinition columnDef = new MyColumnDefinition();
        initializeColumnDefinition(columnDef);
       
        columnDef.setColumnInfo(columnInfo);
       
        return columnDef;
    }
}

public static class MyColumnDefinition extends ColumnDefinition
{
    private String columnInfo;
   
    public String getColumnInfo()
    {
        return columnInfo;
    }
   
    public void setColumnInfo(String pColumnInfo)
    {
        columnInfo = pColumnInfo;
    }
}

As can be seen already, both classes are linked. The class ColumnMetaData creates a new instance of ColumnDefinition.

In 2. step, we're going to configure a DBAccess object. It should use our new classes:
Syntax: [ Download ] [ Hide ]
DBAccess dba = DBAccess.getDBAccess("<jdbcurl>");
dba.setUsername("<username>");
dba.setPassword("<password>");
dba.open();

dba.setColumnMetaDataCreator(new IColumnMetaDataCreator()
{
    public ColumnMetaData createColumnMetaData(DBAccess pDBAccess,
                                               ResultSetMetaData pResultSetMetaData,
                                               int pResultSetColumnIndex)
    {
        MyColumnMetaData cmd = new MyColumnMetaData();
        pDBAccess.initializeColumnMetaData(pResultSetMetaData, pResultSetColumnIndex, cmd);
       
        cmd.setColumnInfo(cmd.getName() + "(" + cmd.getLabel() + ")");
       
        return cmd;
    }
});

We have to implement the interface IColumnMetaDataCreator and simply return our own class. We set the new columnInfo before we return the object.

From now on, all metadata instance are created using the ColumnMetaDataCreator.

The newly created MyColumnMetaData instance is transferred to the client as usual. The model continues to generate automatically our MyColumnDefinition instance, via createColumnDefinition. No more further actions needed.
User avatar
Development@SIB
 
Posts: 325
Joined: Mon Sep 28, 2009 1:54 pm

Return to Documentation