Search in sources :

Example 16 with RelationType

use of org.datanucleus.metadata.RelationType in project datanucleus-core by datanucleus.

the class StateManagerImpl method updateOwnerFieldInEmbeddedField.

/**
 * Method to update the "owner-field" in an embedded object with the owner object.
 * TODO Likely this should be moved into a replaceField method, or maybe Managed Relationships.
 * @param fieldNumber The field number
 * @param value The value to initialise the wrapper with (if any)
 */
public void updateOwnerFieldInEmbeddedField(int fieldNumber, Object value) {
    if (value != null) {
        AbstractMemberMetaData mmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
        RelationType relationType = mmd.getRelationType(myEC.getClassLoaderResolver());
        if (RelationType.isRelationSingleValued(relationType) && mmd.getEmbeddedMetaData() != null && mmd.getEmbeddedMetaData().getOwnerMember() != null) {
            // Embedded field, so assign the embedded/serialised object "owner-field" if specified
            ObjectProvider subSM = myEC.findObjectProvider(value);
            int ownerAbsFieldNum = subSM.getClassMetaData().getAbsolutePositionOfMember(mmd.getEmbeddedMetaData().getOwnerMember());
            if (ownerAbsFieldNum >= 0) {
                flags |= FLAG_UPDATING_EMBEDDING_FIELDS_WITH_OWNER;
                subSM.replaceFieldMakeDirty(ownerAbsFieldNum, myPC);
                flags &= ~FLAG_UPDATING_EMBEDDING_FIELDS_WITH_OWNER;
            }
        }
    }
}
Also used : RelationType(org.datanucleus.metadata.RelationType) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData)

Example 17 with RelationType

use of org.datanucleus.metadata.RelationType in project datanucleus-core by datanucleus.

the class DeleteFieldManager method storeObjectField.

/**
 * Method to store an object field.
 * @param fieldNumber Number of the field (absolute)
 * @param value Value of the field
 */
public void storeObjectField(int fieldNumber, Object value) {
    if (value != null) {
        AbstractMemberMetaData mmd = op.getClassMetaData().getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
        ExecutionContext ec = op.getExecutionContext();
        RelationType relationType = mmd.getRelationType(ec.getClassLoaderResolver());
        if (relationType != RelationType.NONE) {
            if (mmd.hasContainer()) {
                processContainer(fieldNumber, value, mmd, ec, relationType);
            } else {
                processSingleValue(value, mmd, ec, relationType);
            }
        }
    }
}
Also used : ExecutionContext(org.datanucleus.ExecutionContext) RelationType(org.datanucleus.metadata.RelationType) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData)

Example 18 with RelationType

use of org.datanucleus.metadata.RelationType in project datanucleus-core by datanucleus.

the class LoadFieldManager method internalFetchObjectField.

/**
 * Method to fetch an object field whether it is SCO collection, PC, or whatever for the fetchplan
 * process.
 * @param fieldNumber Number of the field
 * @return The object
 */
protected Object internalFetchObjectField(int fieldNumber) {
    SingleValueFieldManager sfv = new SingleValueFieldManager();
    op.provideFields(new int[] { fieldNumber }, sfv);
    Object value = sfv.fetchObjectField(fieldNumber);
    if (value != null) {
        AbstractMemberMetaData mmd = op.getClassMetaData().getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
        RelationType relationType = mmd.getRelationType(op.getExecutionContext().getClassLoaderResolver());
        if (relationType != RelationType.NONE) {
            if (mmd.hasContainer()) {
                value = processContainer(fieldNumber, value, mmd);
            } else {
                // Process PC fields
                processPersistable(value);
            }
        }
    }
    return value;
}
Also used : RelationType(org.datanucleus.metadata.RelationType) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData)

Example 19 with RelationType

use of org.datanucleus.metadata.RelationType in project datanucleus-core by datanucleus.

the class MakeTransientFieldManager method internalFetchObjectField.

/**
 * Method to fetch an object field whether it is SCO collection, PC, or whatever for the fetchplan process.
 * @param fieldNumber Number of the field
 * @return The object
 */
protected Object internalFetchObjectField(int fieldNumber) {
    SingleValueFieldManager sfv = new SingleValueFieldManager();
    op.provideFields(new int[] { fieldNumber }, sfv);
    Object value = sfv.fetchObjectField(fieldNumber);
    if (value != null) {
        AbstractMemberMetaData mmd = op.getClassMetaData().getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
        RelationType relType = mmd.getRelationType(op.getExecutionContext().getClassLoaderResolver());
        if (relType != RelationType.NONE) {
            if (mmd.hasContainer()) {
                // Replace with SCO, when possible
                value = SCOUtils.wrapSCOField(op, fieldNumber, value, true);
                TypeManager typeManager = op.getExecutionContext().getTypeManager();
                ContainerAdapter containerAdapter = typeManager.getContainerAdapter(value);
                ApiAdapter api = op.getExecutionContext().getApiAdapter();
                // Process all elements of the Container that are PC
                for (Object object : containerAdapter) {
                    if (api.isPersistable(object)) {
                        processPersistable(object);
                    }
                }
            } else {
                processPersistable(value);
            }
        }
        if (value instanceof SCO) {
            ((SCO) value).unsetOwner();
        }
    }
    return value;
}
Also used : ApiAdapter(org.datanucleus.api.ApiAdapter) RelationType(org.datanucleus.metadata.RelationType) TypeManager(org.datanucleus.store.types.TypeManager) ContainerAdapter(org.datanucleus.store.types.ContainerAdapter) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) SCO(org.datanucleus.store.types.SCO)

Example 20 with RelationType

use of org.datanucleus.metadata.RelationType in project datanucleus-core by datanucleus.

the class NullifyRelationFieldManager method fetchObjectField.

/**
 * Accessor for object field.
 * @param fieldNumber Number of field
 * @return Object value
 */
public Object fetchObjectField(int fieldNumber) {
    Object value = op.provideField(fieldNumber);
    if (value != null) {
        AbstractMemberMetaData mmd = op.getClassMetaData().getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
        RelationType relType = mmd.getRelationType(op.getExecutionContext().getClassLoaderResolver());
        // do not need to nullify fields that are not references and resides embedded in this object
        if (relType != RelationType.NONE) {
            if (mmd.hasContainer()) {
                TypeManager typeManager = op.getExecutionContext().getTypeManager();
                ContainerAdapter containerAdapter = typeManager.getContainerAdapter(value);
                containerAdapter.clear();
                return containerAdapter.getContainer();
            }
            // Process PC fields
            op.makeDirty(fieldNumber);
            return null;
        }
    }
    return value;
}
Also used : RelationType(org.datanucleus.metadata.RelationType) TypeManager(org.datanucleus.store.types.TypeManager) ContainerAdapter(org.datanucleus.store.types.ContainerAdapter) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData)

Aggregations

RelationType (org.datanucleus.metadata.RelationType)41 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)33 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)14 ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)10 NucleusUserException (org.datanucleus.exceptions.NucleusUserException)10 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)10 ArrayList (java.util.ArrayList)9 ExecutionContext (org.datanucleus.ExecutionContext)7 ApiAdapter (org.datanucleus.api.ApiAdapter)7 DatastoreClass (org.datanucleus.store.rdbms.table.DatastoreClass)7 ObjectProvider (org.datanucleus.state.ObjectProvider)6 Collection (java.util.Collection)5 Iterator (java.util.Iterator)5 List (java.util.List)5 NucleusException (org.datanucleus.exceptions.NucleusException)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 ColumnMetaData (org.datanucleus.metadata.ColumnMetaData)4 EmbeddedPCMapping (org.datanucleus.store.rdbms.mapping.java.EmbeddedPCMapping)4