use of org.datanucleus.store.types.TypeManager in project datanucleus-api-jdo by datanucleus.
the class MemberMetadataImpl method setConverter.
/* (non-Javadoc)
* @see javax.jdo.metadata.MemberMetadata#setConverter(javax.jdo.AttributeConverter)
*/
@Override
public MemberMetadata setConverter(AttributeConverter<?, ?> conv) {
Class attrType = JDOTypeConverterUtils.getAttributeTypeForAttributeConverter(conv.getClass(), getInternal().getType());
Class dbType = JDOTypeConverterUtils.getDatastoreTypeForAttributeConverter(conv.getClass(), attrType, null);
// Register the TypeConverter under the name of the AttributeConverter class
JDOTypeConverter typeConv = new JDOTypeConverter(conv);
TypeManager typeMgr = getInternal().getMetaDataManager().getNucleusContext().getTypeManager();
typeMgr.registerConverter(conv.getClass().getName(), typeConv, attrType, dbType, false, null);
getInternal().setTypeConverterName(conv.getClass().getName());
return this;
}
use of org.datanucleus.store.types.TypeManager in project datanucleus-rdbms by datanucleus.
the class EmbeddedPCMapping method getObjectProviderForEmbeddedObject.
/**
* Accessor for the ObjectProvider of the embedded PC object when provided with the owner object.
* @param ownerOP ObjectProvider of the owner
* @return ObjectProvider of the embedded object
*/
private ObjectProvider getObjectProviderForEmbeddedObject(ObjectProvider ownerOP) {
AbstractMemberMetaData theMmd = getRealMemberMetaData();
// Owner (non-embedded) PC
Object value = ownerOP.provideField(theMmd.getAbsoluteFieldNumber());
TypeManager typeManager = ownerOP.getExecutionContext().getTypeManager();
value = mmd.isSingleCollection() ? typeManager.getContainerAdapter(value).iterator().next() : value;
if (value == null) {
return null;
}
ExecutionContext ec = ownerOP.getExecutionContext();
ObjectProvider thisOP = ec.findObjectProvider(value);
if (thisOP == null) {
// Assign a ObjectProvider to manage our embedded object
thisOP = ec.getNucleusContext().getObjectProviderFactory().newForEmbedded(ec, value, false, ownerOP, theMmd.getAbsoluteFieldNumber());
thisOP.setPcObjectType(objectType);
}
return thisOP;
}
use of org.datanucleus.store.types.TypeManager in project datanucleus-api-jdo by datanucleus.
the class KeyMetadataImpl method setConverter.
/* (non-Javadoc)
* @see javax.jdo.metadata.KeyMetadata#setConverter(javax.jdo.AttributeConverter)
*/
@Override
public KeyMetadata setConverter(AttributeConverter<?, ?> conv) {
String keyType = ((AbstractMemberMetaData) getInternal().getParent()).getMap().getKeyType();
Class keyCls = getInternal().getMetaDataManager().getNucleusContext().getClassLoaderResolver(null).classForName(keyType);
Class attrType = JDOTypeConverterUtils.getAttributeTypeForAttributeConverter(conv.getClass(), keyCls);
Class dbType = JDOTypeConverterUtils.getDatastoreTypeForAttributeConverter(conv.getClass(), attrType, null);
// Register the TypeConverter under the name of the AttributeConverter class
JDOTypeConverter typeConv = new JDOTypeConverter(conv);
TypeManager typeMgr = getInternal().getMetaDataManager().getNucleusContext().getTypeManager();
typeMgr.registerConverter(conv.getClass().getName(), typeConv, attrType, dbType, false, null);
getInternal().addExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_NAME, conv.getClass().getName());
return this;
}
use of org.datanucleus.store.types.TypeManager in project datanucleus-api-jdo by datanucleus.
the class ValueMetadataImpl method setConverter.
/* (non-Javadoc)
* @see javax.jdo.metadata.ValueMetadata#setConverter(javax.jdo.AttributeConverter)
*/
@Override
public ValueMetadata setConverter(AttributeConverter<?, ?> conv) {
String valType = ((AbstractMemberMetaData) getInternal().getParent()).getMap().getKeyType();
Class valCls = getInternal().getMetaDataManager().getNucleusContext().getClassLoaderResolver(null).classForName(valType);
Class attrType = JDOTypeConverterUtils.getAttributeTypeForAttributeConverter(conv.getClass(), valCls);
Class dbType = JDOTypeConverterUtils.getDatastoreTypeForAttributeConverter(conv.getClass(), attrType, null);
// Register the TypeConverter under the name of the AttributeConverter class
JDOTypeConverter typeConv = new JDOTypeConverter(conv);
TypeManager typeMgr = getInternal().getMetaDataManager().getNucleusContext().getTypeManager();
typeMgr.registerConverter(conv.getClass().getName(), typeConv, attrType, dbType, false, null);
getInternal().addExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_NAME, conv.getClass().getName());
return this;
}
use of org.datanucleus.store.types.TypeManager in project datanucleus-api-jdo by datanucleus.
the class ElementMetadataImpl method setConverter.
/* (non-Javadoc)
* @see javax.jdo.metadata.ElementMetadata#setConverter(javax.jdo.AttributeConverter)
*/
@Override
public ElementMetadata setConverter(AttributeConverter<?, ?> conv) {
String elemType = ((AbstractMemberMetaData) getInternal().getParent()).getCollection().getElementType();
Class elemCls = getInternal().getMetaDataManager().getNucleusContext().getClassLoaderResolver(null).classForName(elemType);
Class attrType = JDOTypeConverterUtils.getAttributeTypeForAttributeConverter(conv.getClass(), elemCls);
Class dbType = JDOTypeConverterUtils.getDatastoreTypeForAttributeConverter(conv.getClass(), attrType, null);
// Register the TypeConverter under the name of the AttributeConverter class
JDOTypeConverter typeConv = new JDOTypeConverter(conv);
TypeManager typeMgr = getInternal().getMetaDataManager().getNucleusContext().getTypeManager();
typeMgr.registerConverter(conv.getClass().getName(), typeConv, attrType, dbType, false, null);
getInternal().addExtension(MetaData.EXTENSION_MEMBER_TYPE_CONVERTER_NAME, conv.getClass().getName());
return this;
}
Aggregations