Search in sources :

Example 16 with TypeManager

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;
}
Also used : TypeManager(org.datanucleus.store.types.TypeManager) JDOTypeConverter(org.datanucleus.api.jdo.JDOTypeConverter)

Example 17 with TypeManager

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;
}
Also used : ExecutionContext(org.datanucleus.ExecutionContext) TypeManager(org.datanucleus.store.types.TypeManager) ObjectProvider(org.datanucleus.state.ObjectProvider) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData)

Example 18 with TypeManager

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;
}
Also used : TypeManager(org.datanucleus.store.types.TypeManager) JDOTypeConverter(org.datanucleus.api.jdo.JDOTypeConverter)

Example 19 with TypeManager

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;
}
Also used : TypeManager(org.datanucleus.store.types.TypeManager) JDOTypeConverter(org.datanucleus.api.jdo.JDOTypeConverter)

Example 20 with TypeManager

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;
}
Also used : TypeManager(org.datanucleus.store.types.TypeManager) JDOTypeConverter(org.datanucleus.api.jdo.JDOTypeConverter)

Aggregations

TypeManager (org.datanucleus.store.types.TypeManager)26 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)10 JDOTypeConverter (org.datanucleus.api.jdo.JDOTypeConverter)8 ApiAdapter (org.datanucleus.api.ApiAdapter)6 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)5 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)5 RelationType (org.datanucleus.metadata.RelationType)5 ContainerHandler (org.datanucleus.store.types.ContainerHandler)5 AttributeConverter (javax.jdo.AttributeConverter)4 PersistenceNucleusContext (org.datanucleus.PersistenceNucleusContext)4 ExecutionContext (org.datanucleus.ExecutionContext)3 NucleusException (org.datanucleus.exceptions.NucleusException)3 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)3 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)3 EmbeddedMetaData (org.datanucleus.metadata.EmbeddedMetaData)3 FieldMetaData (org.datanucleus.metadata.FieldMetaData)3 FieldPersistenceModifier (org.datanucleus.metadata.FieldPersistenceModifier)3 ObjectProvider (org.datanucleus.state.ObjectProvider)3 MultiColumnConverter (org.datanucleus.store.types.converters.MultiColumnConverter)3 TypeConverter (org.datanucleus.store.types.converters.TypeConverter)3