Mig-infocom MiG Calendar DBConnect Guide Manual de usuario Pagina 24

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 25
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 23
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 SimplePropertyMappings you created.
DBConnect Guide Page 24 / 25
Vista de pagina 23
1 2 ... 19 20 21 22 23 24 25

Comentarios a estos manuales

Sin comentarios