Package org.datanucleus.store

Examples of org.datanucleus.store.ObjectProvider


        if (relationType != Relation.ONE_TO_MANY_BI && relationType != Relation.MANY_TO_MANY_BI)
        {
            return;
        }

        ObjectProvider elemSM = ownerSM.getObjectManager().findObjectProvider(val);
        if (elemSM != null)
        {
            AbstractMemberMetaData relatedMmd = mmd.getRelatedMemberMetaData(ownerSM.getObjectManager().getClassLoaderResolver())[0];
            if (elemSM.isFieldLoaded(relatedMmd.getAbsoluteFieldNumber()))
            {
                Object currentOwnerId = ownerSM.getObjectManager().getApiAdapter().getIdForObject(elemSM.provideField(relatedMmd.getAbsoluteFieldNumber()));
                ownerSM.getObjectManager().removeObjectFromLevel2Cache(currentOwnerId);
            }
        }

        Integer fieldKey = Integer.valueOf(fieldNumber);
View Full Code Here


        if (newValue != null)
        {
            // Previously had "a.b = b1"; Now have "a.b = b2"
            // Check that the new value hasnt been assigned to something other than this object
            AbstractMemberMetaData relatedMmd = mmd.getRelatedMemberMetaDataForObject(clr, pc, newValue);
            ObjectProvider newSM = om.findObjectProvider(newValue);
            if (newSM != null && relatedMmd != null)
            {
                if (!newSM.isFieldLoaded(relatedMmd.getAbsoluteFieldNumber()))
                {
                    // Load the field in case we need to set the old value
                    newSM.loadField(relatedMmd.getAbsoluteFieldNumber());
                }
                Object newValueFieldValue = newSM.provideField(relatedMmd.getAbsoluteFieldNumber());
                if (newValueFieldValue != pc)
                {
                    RelationshipManager newRelMgr = ec.getRelationshipManager(newSM);
                    if (newRelMgr != null && newRelMgr.managesField(relatedMmd.getAbsoluteFieldNumber()))
                    {
View Full Code Here

                        StringUtils.toJVMIDString(pc), mmd.getName(), StringUtils.toJVMIDString(change.value)));
                }
                else
                {
                    AbstractMemberMetaData relatedMmd = mmd.getRelatedMemberMetaData(clr)[0];
                    ObjectProvider newElementSM = om.findObjectProvider(change.value);
                    if (newElementSM != null)
                    {
                        if (newElementSM.isFieldLoaded(relatedMmd.getAbsoluteFieldNumber()))
                        {
                            RelationshipManager newElementRelMgr = ec.getRelationshipManager(newElementSM);
                            if (newElementRelMgr != null && newElementRelMgr.managesField(relatedMmd.getAbsoluteFieldNumber()))
                            {
                                // Element has had the owner set, so make sure it is set to this object
                                Object newValueFieldValue = newElementSM.provideField(relatedMmd.getAbsoluteFieldNumber());
                                if (newValueFieldValue != pc && newValueFieldValue != null)
                                {
                                    // The element has a different owner than the PC with this collection
                                    // This catches cases where the user has set the wrong owner, and also
                                    // will catch cases where the user has added it to two collections
                                    throw new NucleusUserException(LOCALISER.msg("013009",
                                        StringUtils.toJVMIDString(pc), mmd.getName(),
                                        StringUtils.toJVMIDString(change.value),
                                        StringUtils.toJVMIDString(newValueFieldValue)));
                                }
                            }
                        }
                    }
                }
            }
            else if (change.type == ChangeType.REMOVE_OBJECT)
            {
                if (ownerSM.getObjectManager().getApiAdapter().isDeleted(change.value))
                {
                    // The element was removed and was then the element object was deleted so do nothing
                }
                else
                {
                    AbstractMemberMetaData relatedMmd = mmd.getRelatedMemberMetaData(clr)[0];
                    ObjectProvider newElementSM = om.findObjectProvider(change.value);
                    if (newElementSM != null)
                    {
                        if (newElementSM.isFieldLoaded(relatedMmd.getAbsoluteFieldNumber()))
                        {
                            RelationshipManager newElementRelMgr = ec.getRelationshipManager(newElementSM);
                            if (newElementRelMgr != null && newElementRelMgr.managesField(relatedMmd.getAbsoluteFieldNumber()))
                            {
                                // Element has had the owner set, so make sure it is not set to this object
                                Object newValueFieldValue = newElementSM.provideField(relatedMmd.getAbsoluteFieldNumber());
                                if (newValueFieldValue == pc)
                                {
                                    // The element was removed from the collection, but was updated to have its owner
                                    // set to the collection owner!
                                    throw new NucleusUserException(LOCALISER.msg("013010",
View Full Code Here

                ExecutionContext ec = ownerSM.getExecutionContext();
                Iterator iter = c.iterator();
                while (iter.hasNext())
                {
                    Object pc = iter.next();
                    ObjectProvider objSM = ec.findObjectProvider(pc);
                    if (objSM == null)
                    {
                        objSM = ObjectProviderFactory.newForEmbedded(ec, pc, false, ownerSM, fieldNumber);
                    }
                }
View Full Code Here

        if (oldValue != null)
        {
            // Previously had "a.b = b1"; "a.b" has been changed
            // Need to remove from the other side if still set
            AbstractMemberMetaData relatedMmd = mmd.getRelatedMemberMetaDataForObject(clr, pc, oldValue);
            ObjectProvider oldSM = om.findObjectProvider(oldValue);
            if (oldSM != null)
            {
                boolean oldIsDeleted = om.getApiAdapter().isDeleted(oldSM.getObject());
                if (!oldIsDeleted)
                {
                    // Old still exists, so make sure its relation is correct
                    if (!oldSM.isFieldLoaded(relatedMmd.getAbsoluteFieldNumber()))
                    {
                        // Load the field in case we need to set the old value
                        oldSM.loadField(relatedMmd.getAbsoluteFieldNumber());
                    }
                    Object oldValueFieldValue = oldSM.provideField(relatedMmd.getAbsoluteFieldNumber());
                    if (oldValueFieldValue == null)
                    {
                        // Set to null so nothing to do
                    }
                    else if (oldValueFieldValue == pc)
                    {
                        // Still set to this object, so null out the other objects relation
                        if (NucleusLogger.PERSISTENCE.isDebugEnabled())
                        {
                            NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("013004",
                                    StringUtils.toJVMIDString(oldValue), relatedMmd.getFullFieldName(),
                                    StringUtils.toJVMIDString(pc), StringUtils.toJVMIDString(newValue)));
                        }
                        oldSM.replaceFieldValue(relatedMmd.getAbsoluteFieldNumber(), null);
                    }
                }
                else
                {
                    ownerSM.replaceFieldValue(mmd.getAbsoluteFieldNumber(), null);
                }
            }
        }
        if (newValue != null)
        {
            // Previously had "a.b = b1"; Now have "a.b = b2"
            // Need to set the other side if not yet set, and unset any related old value on the other side
            AbstractMemberMetaData relatedMmd = mmd.getRelatedMemberMetaDataForObject(clr, pc, newValue);
            ObjectProvider newSM = om.findObjectProvider(newValue);
            if (newSM != null && relatedMmd != null)
            {
                if (!newSM.isFieldLoaded(relatedMmd.getAbsoluteFieldNumber()))
                {
                    // Load the field in case we need to set the link from the old value
                    newSM.loadField(relatedMmd.getAbsoluteFieldNumber());
                }
                Object newValueFieldValue = newSM.provideField(relatedMmd.getAbsoluteFieldNumber());
                if (newValueFieldValue == null)
                {
                    // Was set to null so set to our object
                    if (NucleusLogger.PERSISTENCE.isDebugEnabled())
                    {
                        NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("013005",
                                StringUtils.toJVMIDString(newValue), relatedMmd.getFullFieldName(),
                                StringUtils.toJVMIDString(pc)));
                    }
                    newSM.replaceFieldValue(relatedMmd.getAbsoluteFieldNumber(), pc);
                }
                else if (newValueFieldValue != pc)
                {
                    // Was set to different object, so null out the other objects relation
                    ObjectProvider newValueFieldSM = om.findObjectProvider(newValueFieldValue);
                    if (newValueFieldSM != null)
                    {
                        // Null out the field of the related object of the new value
                        if (!newValueFieldSM.isFieldLoaded(mmd.getAbsoluteFieldNumber()))
                        {
                            // Load the field in case we need to set the link from the old value
                            newValueFieldSM.loadField(mmd.getAbsoluteFieldNumber());
                        }
                        if (NucleusLogger.PERSISTENCE.isDebugEnabled())
                        {
                            NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("013004",
                                    StringUtils.toJVMIDString(newValueFieldValue),
                                    mmd.getFullFieldName(),
                                    StringUtils.toJVMIDString(newValue), StringUtils.toJVMIDString(pc)));
                        }
                        newValueFieldSM.replaceFieldValue(mmd.getAbsoluteFieldNumber(), null);
                    }
                    // Update the field of the new value to our object
                    if (NucleusLogger.PERSISTENCE.isDebugEnabled())
                    {
                        NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("013005",
View Full Code Here

        while (iter.hasNext())
        {
            RelationChange change = (RelationChange)iter.next();
            if (change.type == ChangeType.ADD_OBJECT)
            {
                ObjectProvider sm = om.findObjectProvider(change.value);
                if (sm != null)
                {
                    // make sure the link to the owner is now set
                    AbstractMemberMetaData relatedMmd = mmd.getRelatedMemberMetaData(clr)[0];
                    if (sm.isFieldLoaded(relatedMmd.getAbsoluteFieldNumber()))
                    {
                        Object currentVal = sm.provideField(relatedMmd.getAbsoluteFieldNumber());
                        if (currentVal != ownerSM.getObject())
                        {
                            sm.replaceFieldValue(relatedMmd.getAbsoluteFieldNumber(), ownerSM.getObject());
                        }
                    }
                    else
                    {
                        ownerSM.getObjectManager().removeObjectFromLevel2Cache(sm.getInternalObjectId());
                    }
                }
            }
            else if (change.type == ChangeType.REMOVE_OBJECT)
            {
                ObjectProvider sm = om.findObjectProvider(change.value);
                if (sm != null)
                {
                    // make sure the link back to the owner is not still set
                    AbstractMemberMetaData relatedMmd = mmd.getRelatedMemberMetaData(clr)[0];
                    if (sm.isFieldLoaded(relatedMmd.getAbsoluteFieldNumber()))
                    {
                        Object currentVal = sm.provideField(relatedMmd.getAbsoluteFieldNumber());
                        if (currentVal == ownerSM.getObject())
                        {
                            sm.replaceFieldValue(relatedMmd.getAbsoluteFieldNumber(), null);
                        }
                    }
                    else
                    {
                        ownerSM.getObjectManager().removeObjectFromLevel2Cache(sm.getInternalObjectId());
                    }
                }
            }
        }
    }
View Full Code Here

    {
        if (oldValue != null)
        {
            // Has been removed from a Collection/Map
            AbstractMemberMetaData relatedMmd = mmd.getRelatedMemberMetaDataForObject(clr, pc, oldValue);
            ObjectProvider oldSM = om.findObjectProvider(oldValue);
            if (oldSM != null && relatedMmd != null &&
                oldSM.getLoadedFields()[relatedMmd.getAbsoluteFieldNumber()])
            {
                if (oldSM.isFieldLoaded(relatedMmd.getAbsoluteFieldNumber()))
                {
                    Object oldContainerValue = oldSM.provideField(relatedMmd.getAbsoluteFieldNumber());
                    if (oldContainerValue instanceof Collection)
                    {
                        Collection oldColl = (Collection)oldContainerValue;
                        if (oldColl.contains(pc))
                        {
                            if (NucleusLogger.PERSISTENCE.isDebugEnabled())
                            {
                                NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("013006",
                                        StringUtils.toJVMIDString(pc), mmd.getFullFieldName(),
                                        relatedMmd.getFullFieldName(), StringUtils.toJVMIDString(oldValue)));
                            }

                            if (oldColl instanceof SCOCollection)
                            {
                                // Avoid any cascade deletes that could have been fired by this action
                                ((SCOCollection)oldColl).remove(pc, false);
                            }
                            else
                            {
                                oldColl.remove(pc);
                            }
                        }
                    }
                }
            }
            else
            {
                if (oldSM != null)
                {
                    ownerSM.getObjectManager().removeObjectFromLevel2Cache(oldSM.getInternalObjectId());
                }
            }
        }

        if (newValue != null)
        {
            // Add new value to the Collection
            AbstractMemberMetaData relatedMmd = mmd.getRelatedMemberMetaDataForObject(clr, pc, newValue);
            ObjectProvider newSM = om.findObjectProvider(newValue);
            if (newSM != null && relatedMmd != null &&
                newSM.getLoadedFields()[relatedMmd.getAbsoluteFieldNumber()])
            {
                Object newContainerValue = newSM.provideField(relatedMmd.getAbsoluteFieldNumber());
                if (newContainerValue instanceof Collection)
                {
                    Collection newColl = (Collection)newContainerValue;
                    if (!newColl.contains(pc))
                    {
View Full Code Here

        while (iter.hasNext())
        {
            RelationChange change = (RelationChange)iter.next();
            if (change.type == ChangeType.ADD_OBJECT)
            {
                ObjectProvider sm = om.findObjectProvider(change.value);
                if (sm != null)
                {
                    // make sure the element has the owner in its collection
                    AbstractMemberMetaData relatedMmd = mmd.getRelatedMemberMetaData(clr)[0];
                    ownerSM.getObjectManager().removeObjectFromLevel2Cache(sm.getInternalObjectId());
                    ownerSM.getObjectManager().removeObjectFromLevel2Cache(ownerSM.getInternalObjectId());
                    if (ownerSM.isFieldLoaded(mmd.getAbsoluteFieldNumber()) && !ownerSM.getLifecycleState().isDeleted)
                    {
                        Collection currentVal = (Collection)ownerSM.provideField(mmd.getAbsoluteFieldNumber());
                        if (currentVal != null && !currentVal.contains(sm.getObject()))
                        {
                            currentVal.add(sm.getObject());
                        }
                    }
                    if (sm.isFieldLoaded(relatedMmd.getAbsoluteFieldNumber()))
                    {
                        Collection currentVal = (Collection)sm.provideField(relatedMmd.getAbsoluteFieldNumber());
                        if (currentVal != null && !currentVal.contains(ownerSM.getObject()))
                        {
                            currentVal.add(ownerSM.getObject());
                        }
                    }
                }
            }
            else if (change.type == ChangeType.REMOVE_OBJECT)
            {
                ObjectProvider sm = om.findObjectProvider(change.value);
                if (sm != null)
                {
                    // make sure the element removes the owner from its collection
                    AbstractMemberMetaData relatedMmd = mmd.getRelatedMemberMetaData(clr)[0];
                    ownerSM.getObjectManager().removeObjectFromLevel2Cache(sm.getInternalObjectId());
                    ownerSM.getObjectManager().removeObjectFromLevel2Cache(ownerSM.getInternalObjectId());
                    if (ownerSM.isFieldLoaded(mmd.getAbsoluteFieldNumber()) && !ownerSM.getLifecycleState().isDeleted)
                    {
                        Collection currentVal = (Collection)ownerSM.provideField(mmd.getAbsoluteFieldNumber());
                        if (!sm.getLifecycleState().isDeleted && currentVal != null && currentVal.contains(sm.getObject()))
                        {
                            currentVal.remove(sm.getObject());
                        }
                        else
                        {
                            // element is deleted so can't call remove since it may try to read fields from it
                            // so just unload the collection in the owner forcing it to be reloaded from the DB
                            ownerSM.unloadField(mmd.getName());
                        }
                    }
                    if (sm.isFieldLoaded(relatedMmd.getAbsoluteFieldNumber()) && !sm.getLifecycleState().isDeleted)
                    {
                        Collection currentVal = (Collection)sm.provideField(relatedMmd.getAbsoluteFieldNumber());
                        if (currentVal != null && currentVal.contains(ownerSM.getObject()))
                        {
                            currentVal.remove(ownerSM.getObject());
                        }
                    }
View Full Code Here

                ExecutionContext ec = ownerSM.getExecutionContext();
                Iterator iter = c.iterator();
                while (iter.hasNext())
                {
                    Object pc = iter.next();
                    ObjectProvider objSM = ec.findObjectProvider(pc);
                    if (objSM == null)
                    {
                        objSM = ObjectProviderFactory.newForEmbedded(ec, pc, false, ownerSM, fieldNumber);
                    }
                }
View Full Code Here

                ExecutionContext ec = ownerSM.getExecutionContext();
                Iterator iter = c.iterator();
                while (iter.hasNext())
                {
                    Object pc = iter.next();
                    ObjectProvider objSM = ec.findObjectProvider(pc);
                    if (objSM == null)
                    {
                        objSM = ObjectProviderFactory.newForEmbedded(ec, pc, false, ownerSM, fieldNumber);
                    }
                }
View Full Code Here

TOP

Related Classes of org.datanucleus.store.ObjectProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.