Package org.datanucleus.store

Examples of org.datanucleus.store.ExecutionContext


        return (String) sm.provideField(fieldNumber);
    }

    public Object fetchObjectField(int fieldNumber)
    {
        ExecutionContext ec = sm.getExecutionContext();
        ClassLoaderResolver clr = ec.getClassLoaderResolver();
        AbstractMemberMetaData mmd = sm.getClassMetaData().getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
        int relationType = mmd.getRelationType(clr);
        if (relationType == Relation.NONE)
        {
            // Object-based field (non-relation)
            sm.copyFieldsFromObject(value, new int[]{fieldNumber});
            return sm.provideField(fieldNumber);
        }
        else if (mmd.getEmbeddedMetaData() != null)
        {
            // TODO Implement embedded relation objects
        }
        else
        {
            switch (relationType)
            {
                case Relation.ONE_TO_ONE_UNI :
                case Relation.ONE_TO_ONE_BI :
                case Relation.MANY_TO_ONE_BI :
                    final AbstractClassMetaData cmd = sm.getExecutionContext().getMetaDataManager().getMetaDataForClass(mmd.getType(), clr);
                    final NodeList nList = ((Element) node).getElementsByTagName(mmd.getName());
                    if (nList.getLength() == 1)
                    {
                        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


    {
        validateKeyType(sm.getExecutionContext().getClassLoaderResolver(), key);

        if (!keysAreEmbedded && !keysAreSerialised)
        {
            ExecutionContext ec = sm.getExecutionContext();
            if (key!=null && (!ec.getApiAdapter().isPersistent(key) ||
                ec != ec.getApiAdapter().getExecutionContext(key)) && !ec.getApiAdapter().isDetached(key))
            {
                return false;
            }
        }
View Full Code Here

    {
        validateValueType(sm.getExecutionContext().getClassLoaderResolver(), value);

        if (!valuesAreEmbedded && !valuesAreSerialised)
        {
            ExecutionContext ec = sm.getExecutionContext();
            if (value != null && (!ec.getApiAdapter().isPersistent(value) ||
                ec != ec.getApiAdapter().getExecutionContext(value)) && !ec.getApiAdapter().isDetached(value))
            {
                return false;
            }
        }
View Full Code Here

     */
    public SortedMap(ObjectProvider ownerSM, String fieldName)
    {
        super(ownerSM, fieldName);

        ExecutionContext ec = ownerSM.getExecutionContext();
        AbstractMemberMetaData fmd = ownerSM.getClassMetaData().getMetaDataForMember(fieldName);
        fieldNumber = fmd.getAbsoluteFieldNumber();
        allowNulls = SCOUtils.allowNullsInContainer(allowNulls, fmd);
        queued = ec.isDelayDatastoreOperationsEnabled();
        useCache = SCOUtils.useContainerCache(ownerSM, fieldName);

        if (!SCOUtils.mapHasSerialisedKeysAndValues(fmd) &&
                fmd.getPersistenceModifier() == FieldPersistenceModifier.PERSISTENT)
        {
            ClassLoaderResolver clr = ec.getClassLoaderResolver();
            this.backingStore = (MapStore)
            ((BackedSCOStoreManager)ec.getStoreManager()).getBackingStoreForField(clr, fmd, java.util.SortedMap.class);
        }

        // Set up our delegate, using a suitable comparator
        Comparator comparator = SCOUtils.getComparator(fmd, ownerSM.getExecutionContext().getClassLoaderResolver());
        if (comparator != null)
View Full Code Here

            // Check for the case of serialised maps, and assign StateManagers to any PC keys/values without
            AbstractMemberMetaData fmd = ownerSM.getClassMetaData().getMetaDataForMember(fieldName);
            if (SCOUtils.mapHasSerialisedKeysAndValues(fmd) &&
                (fmd.getMap().keyIsPersistent() || fmd.getMap().valueIsPersistent()))
            {
                ExecutionContext ec = ownerSM.getExecutionContext();
                Iterator iter = m.entrySet().iterator();
                while (iter.hasNext())
                {
                    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

    throws MappedDatastoreException
    {
        this.sm = sm;
        this.abstractListStore = als;

        ExecutionContext ec = sm.getExecutionContext();
        ArrayList results = new ArrayList();
        if (resultSet != null)
        {
            DatastoreContainerObject containerTable = als.getContainerTable();
            boolean elementsAreSerialised = als.isElementsAreSerialised();
View Full Code Here

        super(ownerSM, fieldName);

        // Set up our delegate
        this.delegate = new java.util.HashSet();

        ExecutionContext ec = ownerSM.getExecutionContext();
        AbstractMemberMetaData fmd = ownerSM.getClassMetaData().getMetaDataForMember(fieldName);
        fieldNumber = fmd.getAbsoluteFieldNumber();
        allowNulls = SCOUtils.allowNullsInContainer(allowNulls, fmd);
        queued = ec.isDelayDatastoreOperationsEnabled();
        useCache = SCOUtils.useContainerCache(ownerSM, fieldName);

        if (!SCOUtils.collectionHasSerialisedElements(fmd) &&
                fmd.getPersistenceModifier() == FieldPersistenceModifier.PERSISTENT)
        {
            ClassLoaderResolver clr = ec.getClassLoaderResolver();
            this.backingStore = (SetStore)
            ((BackedSCOStoreManager)ec.getStoreManager()).getBackingStoreForField(clr, fmd, java.util.HashSet.class);
        }
        if (NucleusLogger.PERSISTENCE.isDebugEnabled())
        {
            NucleusLogger.PERSISTENCE.debug(SCOUtils.getContainerInfoMessage(ownerSM, fieldName, this,
                useCache, queued, allowNulls, SCOUtils.useCachedLazyLoading(ownerSM, fieldName)));
View Full Code Here

        {
            // Check for the case of serialised PC elements, and assign StateManagers to the elements without
            AbstractMemberMetaData fmd = ownerSM.getClassMetaData().getMetaDataForMember(fieldName);
            if (SCOUtils.collectionHasSerialisedElements(fmd) && fmd.getCollection().elementIsPersistent())
            {
                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

        // Put any new entries
        if (puts.size() > 0)
        {
            try
            {
                ExecutionContext ec = sm.getExecutionContext();
                ManagedConnection mconn = storeMgr.getConnection(ec);
                try
                {
                    // Loop through all entries
                    Iterator iter = puts.iterator();
                    while (iter.hasNext())
                    {
                        // Add the row to the join table
                        Map.Entry entry = (Map.Entry)iter.next();
                        internalPut(sm, mconn, batched, entry.getKey(), entry.getValue(), (!iter.hasNext()));
                    }
                }
                finally
                {
                    mconn.release();
                }
            }
            catch (MappedDatastoreException e)
            {
                throw new NucleusDataStoreException(LOCALISER.msg("056016", e.getMessage()), e);
            }
        }

        // Update any changed entries
        if (updates.size() > 0)
        {
            try
            {
                ExecutionContext ec = sm.getExecutionContext();
                ManagedConnection mconn = storeMgr.getConnection(ec);
                try
                {
                    // Loop through all entries
                    Iterator iter = updates.iterator();
View Full Code Here

        if (oldValue != value)
        {
            // Value changed so update the map
            try
            {
                ExecutionContext ec = sm.getExecutionContext();
                ManagedConnection mconn = storeMgr.getConnection(ec);
                try
                {
                    if (exists)
                    {
View Full Code Here

TOP

Related Classes of org.datanucleus.store.ExecutionContext

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.