MiG InfoCom MiG Calendar DBConnect Guide User Manual

Page 24

Advertising
background image

MiG InfoCom AB

// Keys normally created somewhere else
static final PropertyKey MY_KEY = PropertyKey.getKey("myKey");
static final PropertyKey MY_KEY_TMP1 = PropertyKey.getKey("myKey_tmp1");
static final PropertyKey MY_KEY_TMP2 = PropertyKey.getKey("myKey_tmp2");

// The mappings that goes in the PropertyMappingList
new SimplePropertyMapping("my_col_1", MY_KEY, MY_KEY_TMP1,

PropertyMapping.MTYPE_GENERIC, PropertyMapping.INTEGER_NOT_NULL ) {

public Object getColumnValueToStorage(PropertyConsumer pc)
{
return ((MyComplexType) pc.getProperty(MY_KEY)).getFirstInt();
}
},

new SimplePropertyMapping("my_col_2", MY_KEY, MY_KEY_TMP2,

PropertyMapping.MTYPE_GENERIC, PropertyMapping.INTEGER_NOT_NULL) {

public Object getColumnValueToStorage(PropertyConsumer pc)
{
return ((MyComplexType) pc.getProperty(MY_KEY)).getSecondInt();
}
},

The reason the property can't be read back into the correct property at
once is that the mapping is for one field in the backing store and when
read you only have one of the Integers at a time. This makes it
impossible to create the object from one

PropertyMapping

.

To create the final property you add a

Resolver

into the

PropertyMappingList

.

Resolver.resolve(PropertyConsumer)

is called when all

properties has been read into the

PropertyConsumer

. All you

have to do is to remove the temporary properties your property
mappings created and create the real property with them. Something
like this:

class MyComplexResolver implements Resolver
{
private static final PropertyKey MY_KEY = PropertyKey.getKey("myKey");
private static final PropertyKey MY_KEY_TMP1 = PropertyKey.getKey("myKey_tmp1");
private static final PropertyKey MY_KEY_TMP2 = PropertyKey.getKey("myKey_tmp2");

public void resolve(PropertyConsumer pc)
{
Integer int1 = (Integer) pc.removePropertySilent(MY_KEY_TMP1, Boolean.FALSE);
Integer int2 = (Integer) pc.removePropertySilent(MY_KEY_TMP1, Boolean.FALSE);
if (int1 != null && int2 != null)
pc.setPropertySilent(MY_KEY, new MyComplexType(int1, int2), Boolean.FALSE);
}
}

Then just add that resolver to the

PropertyMappingList

that

you added the

SimplePropertyMapping

s you created.

DBConnect Guide

Page 24 / 25

Advertising