Code mappings are an easy way to store data efficiently in a table and even so maintaining the attributes of a class comfortably. Very often you only find some kind of code (simple characters or numbers) inside tables that have a special meaning for the application. Especially when dealing with a large number of rows, huge memory consumption is prevented using codes.
The following example uses code mappings for the gender of a person:
{
...
private String gender;
...
}
The gender of the person should be stored inside the attribute gender in this class in detail, for example using male and female. In opposition to that, the table stores simple characters (M or F).
The persistent fields of the class must be described in the JDO file. The mapping between code and their meaning is declared using a mapping-extension with the value "code ".
Potential nested extensions of this mapping are field-name, table-name , sql-type (for description see chapter "Direct Field-Mapping")and codes. You have to define at least one code, the other extensions defaults as described above if they are not set. The codes extension has no value itself but encloses a list of code mappings, i.e. nested extensions with key-value pairs describing the codes to map.
Using this definition, Signsoft intelliBO will only write single characters in the FGENDER database table field. In contrast to that, the object attribute gender always contains the complete description. The conversion is made according to the given definition automatically.
Sample how to specify code mappings:
...
<field name="gender">
<extension vendor-name="ssibo" key="jdbc">
<extension vendor-name="ssibo"key="mapping" value="code">
<extension vendor-name="ssibo"key="field-name" value="FGENDER"/>
<extension vendor-name="ssibo" key="codes">
<extension vendor-name="ssibo" key="M" value="male"/>
<extension vendor-name="ssibo" key="F" value="female"/>
</extension>
</extension>
</extension>
</field>
....