Package org.datanucleus.store

Examples of org.datanucleus.store.ObjectProvider


                    Map.Entry entry = (Map.Entry)iter.next();
                    Object key = entry.getKey();
                    Object value = entry.getValue();
                    if (fmd.getMap().keyIsPersistent())
                    {
                        ObjectProvider objSM = ec.findObjectProvider(key);
                        if (objSM == null)
                        {
                            objSM = ObjectProviderFactory.newForEmbedded(ec, key, false, ownerSM, fieldNumber);
                        }
                    }
                    if (fmd.getMap().valueIsPersistent())
                    {
                        ObjectProvider objSM = ec.findObjectProvider(value);
                        if (objSM == null)
                        {
                            objSM = ObjectProviderFactory.newForEmbedded(ec, value, false, ownerSM, fieldNumber);
                        }
                    }
View Full Code Here


     * @return Whether the element contains the owner
     */
    private boolean elementAlreadyContainsOwnerInMtoN(ObjectProvider ownerSM, Object element)
    {
        ExecutionContext ec = ownerSM.getExecutionContext();
        ObjectProvider elementSM = ec.findObjectProvider(element);
        AbstractMemberMetaData[] relatedMmds = ownerMemberMetaData.getRelatedMemberMetaData(ec.getClassLoaderResolver());
        Object elementSCO = elementSM.provideField(relatedMmds[0].getAbsoluteFieldNumber());
        if (elementSCO instanceof SCOMtoN)
        {
            // The field is already a SCO wrapper so just query it
            if (contains(ownerSM, element))
            {
View Full Code Here

        if (relationType == Relation.ONE_TO_MANY_BI)
        {
            // TODO This is ManagedRelations - move into RelationshipManager
            // Managed Relations : make sure we have consistency of relation
            ObjectProvider elementSM = sm.getExecutionContext().findObjectProvider(element);
            if (elementSM != null)
            {
                AbstractMemberMetaData[] relatedMmds = ownerMemberMetaData.getRelatedMemberMetaData(clr);
                Object elementOwner = elementSM.provideField(relatedMmds[0].getAbsoluteFieldNumber());
                if (elementOwner == null)
                {
                    // No owner, so correct it
                    NucleusLogger.PERSISTENCE.info(LOCALISER.msg("056037", sm.toPrintableID(), ownerMemberMetaData
                            .getFullFieldName(), StringUtils.toJVMIDString(elementSM.getObject())));
                    elementSM.replaceField(relatedMmds[0].getAbsoluteFieldNumber(), sm.getObject());
                }
                else if (elementOwner != sm.getObject() && sm.getReferencedPC() == null)
                {
                    // Owner of the element is neither this container nor being attached
                    // Inconsistent owner, so throw exception
                    throw new NucleusUserException(LOCALISER.msg("056038", sm.toPrintableID(), ownerMemberMetaData
                            .getFullFieldName(), StringUtils.toJVMIDString(elementSM.getObject()), StringUtils.toJVMIDString(elementOwner)));
                }
            }
        }

        boolean modified = false;
View Full Code Here

            if (relationType == Relation.ONE_TO_MANY_BI)
            {
                // TODO This is ManagedRelations - move into RelationshipManager
                // Managed Relations : make sure we have consistency of relation
                ObjectProvider elementSM = sm.getExecutionContext().findObjectProvider(element);
                if (elementSM != null)
                {
                    AbstractMemberMetaData[] relatedMmds = ownerMemberMetaData.getRelatedMemberMetaData(clr);
                    Object elementOwner = elementSM.provideField(relatedMmds[0].getAbsoluteFieldNumber());
                    if (elementOwner == null)
                    {
                        // No owner, so correct it
                        NucleusLogger.PERSISTENCE.info(LOCALISER.msg("056037", sm.toPrintableID(), ownerMemberMetaData
                                .getFullFieldName(), StringUtils.toJVMIDString(elementSM.getObject())));
                        elementSM.replaceField(relatedMmds[0].getAbsoluteFieldNumber(), sm.getObject());
                    }
                    else if (elementOwner != sm.getObject() && sm.getReferencedPC() == null)
                    {
                        // Owner of the element is neither this container nor its referenced object
                        // Inconsistent owner, so throw exception
                        throw new NucleusUserException(LOCALISER.msg("056038", sm.toPrintableID(),
                            ownerMemberMetaData.getFullFieldName(), StringUtils.toJVMIDString(elementSM.getObject()), StringUtils
                                    .toJVMIDString(elementOwner)));
                    }
                }
            }
        }
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 (!fieldName.equals(candidateAlias))
            {
                if (ec.getApiAdapter().isPersistent(value))
                {
                    // Make sure this field is loaded
                    ObjectProvider valueSM = ec.findObjectProvider(value);
                    if (valueSM != null)
                    {
                        AbstractMemberMetaData mmd = valueSM.getClassMetaData().getMetaDataForMember(fieldName);
                        if (mmd == null)
                        {
                            NucleusLogger.QUERY.error("Cannot find " + fieldName + " member of " + valueSM.getClassMetaData().getFullClassName());
                            return new InMemoryFailure();
                        }
                        if (mmd.getAbsoluteFieldNumber() >= 0)
                        {
                            // Field is managed, and not loaded, so load it
                            valueSM.isLoaded(mmd.getAbsoluteFieldNumber());
                        }
                    }
                }
                value = ClassUtils.getValueOfFieldByReflection(value, fieldName);
            }
View Full Code Here

            // Transient or detached maybe
            return ClassUtils.getValueOfFieldByReflection(object, mmd.getName());
            // TODO What if this is a property?
        }

        ObjectProvider sm = ec.findObjectProvider(object);
        if (!mmd.isPrimaryKey())
        {
            // Make sure the field is loaded
            ec.getApiAdapter().isLoaded(sm, mmd.getAbsoluteFieldNumber());
        }

        FieldManager fm = new SingleValueFieldManager();
        sm.provideFields(new int[] {mmd.getAbsoluteFieldNumber()}, fm);
        return fm.fetchObjectField(mmd.getAbsoluteFieldNumber());
    }
View Full Code Here

        if (!ec.getApiAdapter().isPersistable(obj))
        {
            return null;
        }

        ObjectProvider sm = ec.findObjectProvider(obj);
        if (sm == null)
        {
            // Find the identity
            Object id = null;
            if (acmd.getIdentityType() == IdentityType.DATASTORE)
            {
                throw new NucleusException(LOCALISER.msg("XML.DatastoreID"));
            }
            else
            {
                id = ec.getApiAdapter().getNewApplicationIdentityObjectId(obj, acmd);
            }
            // TODO What about nondurable?

            // Object not managed so give it a StateManager before returning it
            sm = ObjectProviderFactory.newForPersistentClean(ec, id, obj);
            AbstractClassMetaData cmd = sm.getClassMetaData();

            // Mark as not loaded all (non-embedded) relation fields
            int[] members = cmd.getAllMemberPositions();
            for (int i = 0; i < members.length; i++)
            {
                AbstractMemberMetaData mmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(i);
                if (mmd.getRelationType(ec.getClassLoaderResolver()) != Relation.NONE &&
                    mmd.getEmbeddedMetaData() == null)
                {
                    sm.unloadField(mmd.getName());
                }
            }
        }

        // Wrap all unwrapped SCO fields of this instance so we can pick up any changes
        sm.replaceAllLoadedSCOFieldsWithWrappers();

        return sm;
    }
View Full Code Here

                        Object id = ec.getApiAdapter().getNewApplicationIdentityObjectId(clr.classForName(cmd.getFullClassName()), nList.item(0).getFirstChild().getNodeValue());
                        Object related = ec.findObject(id, true, true, null);
                        if (relationType == Relation.ONE_TO_ONE_BI)
                        {
                            // Set other side of relation to avoid reloading
                            ObjectProvider relatedSM = ec.findObjectProvider(related);
                            AbstractMemberMetaData relatedMmd = mmd.getRelatedMemberMetaDataForObject(clr, sm.getObject(), related);
                            relatedSM.replaceField(relatedMmd.getAbsoluteFieldNumber(), sm.getObject());
                        }
                        return related;
                    }
                    return null;

                case Relation.ONE_TO_MANY_UNI :
                case Relation.ONE_TO_MANY_BI :
                    // TODO Cater for Map/array
                    if (mmd.hasCollection())
                    {
                        AbstractClassMetaData cmd2 = sm.getExecutionContext().getMetaDataManager().getMetaDataForClass(mmd.getCollection().getElementType(), clr);

                        // Get value being unmarshalled
                        sm.copyFieldsFromObject(value, new int[]{fieldNumber});
                        Collection collection = (Collection) sm.provideField(fieldNumber);

                        // Make sure we get the right type of element (allow for inheritance)
                        NodeList nLists = ((Element) node).getElementsByTagName(
                            XMLUtils.getElementNameForMember(mmd, FieldRole.ROLE_COLLECTION_ELEMENT));
                        for (int i = 0; i < nLists.getLength(); i++)
                        {
                            final String nodeValue = nLists.item(i).getFirstChild().getNodeValue();
                            if (nodeValue != null && nodeValue.trim().length() > 0)
                            {
                                final AbstractClassMetaData elementCmd = XMLUtils.findMetaDataForNode(doc, cmd2,
                                    ec.getMetaDataManager(), nodeValue, clr);
                                if (elementCmd == null && cmd2 != null)
                                {
                                    throw new NucleusException("Unable to find object of type " + cmd2.getFullClassName() + " with id=" + nodeValue);
                                }

                                Object id = ec.getApiAdapter().getNewApplicationIdentityObjectId(
                                    clr.classForName(elementCmd.getFullClassName()), nodeValue);
                                Object related = ec.findObject(id, true, true, null);
                                if (relationType == Relation.ONE_TO_MANY_BI)
                                {
                                    // Set other side of relation to avoid reloading
                                    ObjectProvider relatedSM = ec.findObjectProvider(related);
                                    AbstractMemberMetaData relatedMmd = relatedSM.getClassMetaData().getMetaDataForMember(mmd.getMappedBy());
                                    relatedSM.replaceField(relatedMmd.getAbsoluteFieldNumber(), sm.getObject());
                                }
                                collection.add(related);
                            }
                        }
View Full Code Here

        }
        else
        {
            // Element was already persistent so make sure the FK is in place
            // TODO This is really "ManagedRelationships" so needs to go in RelationshipManager
            ObjectProvider elementSM = ec.findObjectProvider(element);
            if (getFieldNumberInElementForBidirectional(elementSM) >= 0)
            {
                // Managed Relations : 1-N bidir, so update the owner of the element
                ec.getApiAdapter().isLoaded(elementSM, getFieldNumberInElementForBidirectional(elementSM)); // Ensure is loaded
                Object oldOwner = elementSM.provideField(getFieldNumberInElementForBidirectional(elementSM));
                if (oldOwner != newOwner)
                {
                    if (NucleusLogger.PERSISTENCE.isDebugEnabled())
                    {
                        NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("055009", sm.toPrintableID(),
                            ownerMemberMetaData.getFullFieldName(), StringUtils.toJVMIDString(element)));
                    }

                    int relatedFieldNumber = getFieldNumberInElementForBidirectional(elementSM);
                    elementSM.replaceFieldMakeDirty(relatedFieldNumber, newOwner);
                    if (ec.getManageRelations())
                    {
                        // Managed Relationships - add the change we've made here to be analysed at flush
                        ec.getRelationshipManager(elementSM).relationChange(relatedFieldNumber, oldOwner, newOwner);
                    }

                    if (ec.isFlushing())
                    {
                        elementSM.flush();
                    }
                }
                return oldOwner != newOwner;
            }
            else
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.