MiG InfoCom MiG Calendar DBConnect Guide User Manual
Page 23

MiG InfoCom AB
public static class MyComplexPropertyMapping extends PropertyMapping
{
private static final PropertyKey MY_KEY = PropertyKey.getKey("myComplexKeyName");
public MyComplexPropertyMapping(String columnName)
{
super(columnName,
PropertyMapping.MTYPE_GENERIC,
PropertyMapping.STRING_NOT_NULL);
}
public void setPropertyValueFromStorage(Object o, PropertyConsumer pc)
{
String[] parts = ((String) o).split(",");
MyComplexType value = new MyComplexType(parts[0], parts[1]);
pc.setPropertySilent(MY_KEY, value, Boolean.FALSE);
}
public Object getColumnValueToStorage(PropertyConsumer pc)
{
MyComplexType value = (MyComplexType) pc.getProperty(MY_KEY);
return value.getFirstInt() + "," + value.getSecondInt();
}
public boolean isAffectedByProperty(PropertyKey key)
{
return key == MY_KEY;
}
public boolean canConvertFromStorage() { return true; }
public boolean canConvertToStorage() { return true; }
}
There is also the possibility that you want the complex type to be
persisted to two or more database columns, for instance one column
for each of the Integers in
MyComplexType
above. This is more
correct from a database optimization perspective and opens up for
SQL queries on these columns, something not suitable if you are
using the composite approach as describe in the code above.
Setting up the property mappings for storing the
MyComplexType
to
the backing store is not very hard. Just use one
SimplePropertyMapping
that writes from the real key to the
backing store but reads it back into two temporary properties. The
override is so that the value that are saved is the correct part of the
complex type.
DBConnect Guide
Page 23 / 25