Package org.datanucleus.state

Examples of org.datanucleus.state.StateManager


                // Evict StateManagers and remove objects from cache
                // Performed in separate loop to avoid ConcurrentModificationException
                Iterator smIter = stateManagersToEvict.iterator();
                while (smIter.hasNext())
                {
                    StateManager sm = (StateManager)smIter.next();
                    Object pc = sm.getObject();
                    sm.evict();

                    // Evict from L1
                    removeObjectFromCache(getApiAdapter().getIdForObject(pc));
                }
            }
View Full Code Here


        {
            clr.setPrimary(obj.getClass().getClassLoader());
            assertClassPersistable(obj.getClass());
            assertNotDetached(obj);

            StateManager sm = findStateManager(obj);
            if (sm == null)
            {
                throw new NucleusUserException(LOCALISER.msg("010007", getApiAdapter().getIdForObject(obj)));
            }

            if (getApiAdapter().isPersistent(obj) && sm.isWaitingToBeFlushedToDatastore())
            {
                // Persistent but not yet flushed so nothing to "refresh" from!
                return;
            }

            sm.refresh();
        }
        finally
        {
            clr.unsetPrimary();
        }
View Full Code Here

            while (iter.hasNext())
            {
                try
                {
                    Object obj = iter.next();
                    StateManager sm;
                    if (getApiAdapter().isPersistable(obj))
                    {
                        sm = findStateManager(obj);
                    }
                    else
                    {
                        sm = (StateManager) obj;
                    }
                    sm.refresh();
                }
                catch (RuntimeException e)
                {
                    if (failures == null)
                    {
View Full Code Here

        {
            clr.setPrimary(obj.getClass().getClassLoader());
            assertClassPersistable(obj.getClass());
            assertNotDetached(obj);

            StateManager sm = findStateManager(obj);
            if (sm == null)
            {
                throw new NucleusUserException(LOCALISER.msg("010007", getApiAdapter().getIdForObject(obj)));
            }
            sm.retrieve(fgOnly);
        }
        finally
        {
            clr.unsetPrimary();
        }
View Full Code Here

        {
            persistedPc = persistObjectInternal(obj, null, null, -1, ObjectProvider.PC);
        }

        // If using reachability at commit and appropriate save it for reachability checks when we commit
        StateManager sm = findStateManager(persistedPc);
        if (sm != null)
        {
            if (indirectDirtySMs.contains(sm))
            {
                dirtySMs.add(sm);
                indirectDirtySMs.remove(sm);
            }
            else if (!dirtySMs.contains(sm))
            {
                dirtySMs.add(sm);
                if (txCachedIds != null)
                {
                    txCachedIds.add(sm.getInternalObjectId());
                }
            }

            if (getReachabilityAtCommit() && tx.isActive())
            {
                if (detached || getApiAdapter().isNew(persistedPc))
                {
                    txKnownPersistedIds.add(sm.getInternalObjectId());
                }
            }
        }

        return persistedPc;
View Full Code Here

                // TransientTransactional : persist it
                if (NucleusLogger.PERSISTENCE.isDebugEnabled())
                {
                    NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("010015", StringUtils.toJVMIDString(obj)));
                }
                StateManager sm = findStateManager(obj);
                if (sm == null)
                {
                    throw new NucleusUserException(LOCALISER.msg("010007", getApiAdapter().getIdForObject(obj)));
                }
                sm.makePersistentTransactionalTransient();
            }
            else if (!api.isPersistent(obj))
            {
                // Transient : persist it
                if (NucleusLogger.PERSISTENCE.isDebugEnabled())
                {
                    NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("010015", StringUtils.toJVMIDString(obj)));
                }
                boolean merged = false;
                ThreadContextInfo threadInfo = acquireThreadContextInfo();
                try
                {
                    if (threadInfo.merging)
                    {
                        AbstractClassMetaData cmd = getMetaDataManager().getMetaDataForClass(obj.getClass(), clr);
                        if (cmd.getIdentityType() == IdentityType.APPLICATION)
                        {
                            Object transientId = api.getNewApplicationIdentityObjectId(obj, cmd);
                            Object existingObj = findObject(transientId, true, true, cmd.getFullClassName());
                            ObjectProvider existingOP = findObjectProvider(existingObj);
                            ((StateManager)existingOP).attach(obj);
                            id = transientId;
                            merged = true;
                            persistedPc = existingObj;
                        }
                    }
                }
                catch (NucleusObjectNotFoundException onfe)
                {
                    // Object with this id doesn't exist, so just persist the transient (below)
                }
                finally
                {
                    releaseThreadContextInfo();
                }

                if (!merged)
                {
                    StateManager sm = findStateManager(obj);
                    if (sm == null)
                    {
                        if ((objectType == ObjectProvider.EMBEDDED_COLLECTION_ELEMENT_PC ||
                                objectType == ObjectProvider.EMBEDDED_MAP_KEY_PC ||
                                objectType == ObjectProvider.EMBEDDED_MAP_VALUE_PC ||
                                objectType == ObjectProvider.EMBEDDED_PC) && ownerOP != null)
                        {
                            // SCO object
                            sm = (StateManager) ObjectProviderFactory.newForEmbedded(this, obj, false, ownerOP, ownerFieldNum);
                            sm.setPcObjectType((short) objectType);
                            sm.makePersistent();
                            id = sm.getInternalObjectId();
                        }
                        else
                        {
                            // FCO object
                            sm = (StateManager) ObjectProviderFactory.newForPersistentNew(this, obj, preInsertChanges);
                            sm.makePersistent();
                            id = sm.getInternalObjectId();
                        }
                    }
                    else
                    {
                        if (sm.getReferencedPC() == null)
                        {
                            // Persist it
                            sm.makePersistent();
                            id = sm.getInternalObjectId();
                        }
                        else
                        {
                            // Being attached, so use the attached object
                            persistedPc = sm.getReferencedPC();
                        }
                    }
                }
            }
            else if (api.isPersistent(obj) && api.getIdForObject(obj) == null)
            {
                // Embedded/Serialised : have SM but no identity, allow persist in own right
                // Should we be making a copy of the object here ?
                if (NucleusLogger.PERSISTENCE.isDebugEnabled())
                {
                    NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("010015", StringUtils.toJVMIDString(obj)));
                }
                StateManager sm = findStateManager(obj);
                sm.makePersistent();
                id = sm.getInternalObjectId();
            }
            else if (api.isDeleted(obj))
            {
                // Deleted : (re)-persist it (permitted in JPA, but not JDO - see StateManager)
                if (NucleusLogger.PERSISTENCE.isDebugEnabled())
                {
                    NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("010015", StringUtils.toJVMIDString(obj)));
                }
                StateManager sm = findStateManager(obj);
                sm.makePersistent();
                id = sm.getInternalObjectId();
            }
            else
            {
                if (api.isPersistent(obj) && api.isTransactional(obj) && api.isDirty(obj) &&
                    isDelayDatastoreOperationsEnabled())
                {
                    // Object provisionally persistent (but not in datastore) so re-run reachability maybe
                    if (NucleusLogger.PERSISTENCE.isDebugEnabled())
                    {
                        NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("010015", StringUtils.toJVMIDString(obj)));
                    }
                    StateManager sm = findStateManager(obj);
                    sm.makePersistent();
                    id = sm.getInternalObjectId();
                }
            }

            if (id != null && txCachedIds != null)
            {
View Full Code Here

     */
    public Object persistObjectInternal(Object pc, ObjectProvider ownerSM, int ownerFieldNum, int objectType)
    {
        if (ownerSM != null)
        {
            StateManager sm = findStateManager(ownerSM.getObject());
            return persistObjectInternal(pc, null, sm, ownerFieldNum, objectType);
        }
        else
        {
            return persistObjectInternal(pc, null, null, ownerFieldNum, objectType);
View Full Code Here

     * NOT to be called by internal methods. Only callable by external APIs (JDO/JPA).
     * @param obj The object
     */
    synchronized void deleteObjectWork(Object obj)
    {
        StateManager sm = findStateManager(obj);
        if (sm == null && getApiAdapter().isDetached(obj))
        {
            // Delete of detached, so find a managed attached version and delete that
            Object attachedObj = findObject(getApiAdapter().getIdForObject(obj), true, false, obj.getClass().getName());
            sm = findStateManager(attachedObj);
        }
        if (sm != null)
        {
            // Add the object to the relevant list of dirty StateManagers
            if (indirectDirtySMs.contains(sm))
            {
                // Object is dirty indirectly, but now user-requested so move to direct list of dirty objects
                indirectDirtySMs.remove(sm);
                dirtySMs.add(sm);
            }
            else if (!dirtySMs.contains(sm))
            {
                dirtySMs.add(sm);
                if (txCachedIds != null)
                {
                    txCachedIds.add(sm.getInternalObjectId());
                }
            }
        }

        // Delete the object
        if (this.getMultithreaded())
        {
            synchronized (obj)
            {
                deleteObjectInternal(obj);
            }
        }
        else
        {
            deleteObjectInternal(obj);
        }

        if (getReachabilityAtCommit() && tx.isActive())
        {
            if (sm != null)
            {
                if (getApiAdapter().isDeleted(obj))
                {
                    txKnownDeletedIds.add(sm.getInternalObjectId());
                }
            }
        }
    }
View Full Code Here

                    throw new NucleusUserException(LOCALISER.msg("010021"));
                }
            }

            // Delete it
            StateManager sm = findStateManager(pc);
            if (sm == null)
            {
                if (!getApiAdapter().allowDeleteOfNonPersistentObject())
                {
                    // Not permitted by the API
                    throw new NucleusUserException(LOCALISER.msg("010007", getApiAdapter().getIdForObject(pc)));
                }

                // Put StateManager around object so it is P_NEW (unpersisted), then P_NEW_DELETED soon after
                sm = (StateManager) ObjectProviderFactory.newForPNewToBeDeleted(this, pc);
            }

            if (txCachedIds != null)
            {
                // Mark for L2 cache update
                txCachedIds.add(sm.getInternalObjectId());
            }

            // Move to deleted state
            sm.deletePersistent();
        }
        finally
        {
            clr.unsetPrimary();
        }
View Full Code Here

                NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("010022", StringUtils.toJVMIDString(obj)));
            }

            if (getApiAdapter().isPersistent(obj))
            {
                StateManager sm = findStateManager(obj);
                sm.makeTransient(state);
            }
        }
        finally
        {
            clr.unsetPrimary();
View Full Code Here

TOP

Related Classes of org.datanucleus.state.StateManager

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.