Package org.datanucleus.cache

Examples of org.datanucleus.cache.Level2Cache


        if (!myOM.getNucleusContext().getPersistenceConfiguration().getBooleanProperty("datanucleus.cache.level2.loadFields", true))
        {
            return fieldNumbers;
        }

        Level2Cache l2cache = myOM.getNucleusContext().getLevel2Cache();
        if (l2cache != null && cmd.isCacheable())
        {
            CachedPC cachedPC = null;
            synchronized (l2cache)
            {
                cachedPC = l2cache.get(myID);
                if (cachedPC != null)
                {
                    int[] cacheFieldsToLoad = getFlagsSetTo(cachedPC.getLoadedFields(), fieldNumbers, true);
                    if (cacheFieldsToLoad != null && cacheFieldsToLoad.length > 0)
                    {
View Full Code Here


        if (fieldNumbers == null || fieldNumbers.length == 0)
        {
            return;
        }

        Level2Cache l2cache = myOM.getNucleusContext().getLevel2Cache();
        if (l2cache != null && cmd.isCacheable() && !myOM.isObjectModifiedInTransaction(myID))
        {
            CachedPC cachedPC = null;
            synchronized (l2cache)
            {
                cachedPC = l2cache.get(myID);
            }
            if (cachedPC != null)
            {
                int[] cacheFieldsToLoad = getFlagsSetTo(cachedPC.getLoadedFields(), fieldNumbers, false);
                if (cacheFieldsToLoad != null && cacheFieldsToLoad.length > 0)
View Full Code Here

    {
        // Lock the L2 cache so nobody else can have it while we are updating objects
        // Without this we can get race conditions between threads taking objects out, and
        // us putting objects in leading to assorted exceptions in AbstractStateManager or
        // in the PC object jdoReplaceField() methods.
        Level2Cache l2Cache = context.getLevel2Cache();
        synchronized (l2Cache)
        {
            // Process all modified objects adding/updating/removing from L2 cache as appropriate
            Iterator txCachedIter = txCachedIds.iterator();
            while (txCachedIter.hasNext())
            {
                Object id = txCachedIter.next();
                StateManager sm = enlistedSMCache.get(id);
                if (sm == null)
                {
                    // Modified object no longer enlisted so has been GCed, so remove from L2
                    if (NucleusLogger.CACHE.isDebugEnabled())
                    {
                        NucleusLogger.CACHE.debug(LOCALISER.msg("004014", id));
                    }
                    l2Cache.evict(id);
                }
                else
                {
                    // Modified object still enlisted so cacheable
                    Object objID = getApiAdapter().getIdForObject(sm.getObject());
                    if (objID == null)
                    {
                        // Must be embedded
                    }
                    else if (getApiAdapter().isDeleted(sm.getObject()))
                    {
                        // Object has been deleted so remove from L2 cache
                        if (NucleusLogger.CACHE.isDebugEnabled())
                        {
                            NucleusLogger.CACHE.debug(LOCALISER.msg("004007",
                                StringUtils.toJVMIDString(sm.getObject()), sm.getInternalObjectId()));
                        }
                        l2Cache.evict(objID);
                    }
                    else if (!getApiAdapter().isDetached(sm.getObject()))
                    {
                        // Object has been added/modified so update in L2 cache
                        putObjectIntoLevel2CacheInternal(sm, true);
View Full Code Here

    protected void putObjectIntoLevel2CacheInternal(StateManager sm, boolean updateIfPresent)
    {
        if (sm.getClassMetaData().isCacheable())
        {
            Object id = sm.getInternalObjectId();
            Level2Cache l2Cache = context.getLevel2Cache();
            if (!updateIfPresent && l2Cache.containsOid(id))
            {
                // Already present and not wanting to update
                return;
            }

            synchronized (l2Cache)
            {
                CachedPC cachedPC = sm.cache();
                if (cachedPC != null)
                {
                    // Update/add in the L2 cache
                    if (NucleusLogger.CACHE.isDebugEnabled())
                    {
                        if (l2Cache.containsOid(id))
                        {
                            NucleusLogger.CACHE.debug(LOCALISER.msg("004013",
                                StringUtils.toJVMIDString(sm.getObject()), id,
                                StringUtils.booleanArrayToString(cachedPC.getLoadedFields()),
                                StringUtils.objectArrayToString(cachedPC.getRelationFieldNames())));
                        }
                        else
                        {
                            NucleusLogger.CACHE.debug(LOCALISER.msg("004003",
                                StringUtils.toJVMIDString(sm.getObject()), id,
                                StringUtils.booleanArrayToString(cachedPC.getLoadedFields()),
                                StringUtils.objectArrayToString(cachedPC.getRelationFieldNames())));
                        }
                    }
                    l2Cache.put(id, cachedPC);
                }
            }
        }
    }
View Full Code Here

     */
    public void removeObjectFromLevel2Cache(Object id)
    {
        if (id != null)
        {
            Level2Cache l2Cache = context.getLevel2Cache();
            synchronized (l2Cache)
            {
                if (l2Cache.containsOid(id))
                {
                    if (NucleusLogger.CACHE.isDebugEnabled())
                    {
                        NucleusLogger.CACHE.debug(LOCALISER.msg("004016", id));
                    }
                    l2Cache.evict(id);
                }
            }
        }
    }
View Full Code Here

        }

        // Try Level 2 since not in Level 1
        if (context.hasLevel2Cache())
        {
            Level2Cache l2Cache = context.getLevel2Cache();
            synchronized (l2Cache)
            {
                if (l2Cache.containsOid(id))
                {
                    return true;
                }
            }
        }
View Full Code Here

        }

        // Try Level 2 since not in Level 1
        if (context.hasLevel2Cache())
        {
            Level2Cache l2Cache = context.getLevel2Cache();
            CachedPC cachedPC = null;
            synchronized (l2Cache)
            {
                cachedPC = l2Cache.get(id);
            }

            // Create active version of cached object with StateManager connected and same id
            if (cachedPC != null)
            {
View Full Code Here

     * update the loaded value for that field(s).
     * @param fieldNumbers Numbers of fields to update
     */
    private void updateLevel2CacheForFields(int[] fieldNumbers)
    {
        Level2Cache l2cache = myOM.getObjectManagerFactory().getLevel2Cache();
        if (l2cache != null && cmd.isCacheable() && !myOM.isObjectModifiedInTransaction(myID))
        {
            synchronized (l2cache)
            {
                CachedPC cachedPC = l2cache.get(myID);
                if (cachedPC != null)
                {
                    int[] cacheFieldsToLoad = getFlagsSetTo(cachedPC.getLoadedFields(), fieldNumbers, false);
                    if (cacheFieldsToLoad != null && cacheFieldsToLoad.length > 0)
                    {
View Full Code Here

    {
        // Lock the L2 cache so nobody else can have it while we are updating objects
        // Without this we can get race conditions between threads taking objects out, and
        // us putting objects in leading to assorted exceptions in AbstractStateManager or
        // in the PC object jdoReplaceField() methods.
        Level2Cache l2Cache = omf.getLevel2Cache();
        synchronized (l2Cache)
        {
            // Process all modified objects adding/updating/removing from L2 cache as appropriate
            Iterator txCachedIter = txCachedIds.iterator();
            while (txCachedIter.hasNext())
            {
                Object id = txCachedIter.next();
                StateManager sm = enlistedSMCache.get(id);
                if (sm == null)
                {
                    // Modified object no longer enlisted so has been GCed, so remove from L2
                    if (NucleusLogger.CACHE.isDebugEnabled())
                    {
                        NucleusLogger.CACHE.debug(LOCALISER.msg("004014",
                            id, String.valueOf(l2Cache.getSize())));
                    }
                    l2Cache.evict(id);
                }
                else
                {
                    // Modified object still enlisted so cacheable
                    if (getApiAdapter().isDeleted(sm.getObject()))
                    {
                        // Object has been deleted so remove from L2 cache
                        if (NucleusLogger.CACHE.isDebugEnabled())
                        {
                            NucleusLogger.CACHE.debug(LOCALISER.msg("004007",
                                StringUtils.toJVMIDString(sm.getObject()),
                                sm.getInternalObjectId(),
                                String.valueOf(l2Cache.getSize())));
                        }
                        l2Cache.evict(getApiAdapter().getIdForObject(sm.getObject()));
                    }
                    else if (!getApiAdapter().isDetached(sm.getObject()))
                    {
                        // Object has been added/modified so update in L2 cache
                        putObjectIntoLevel2CacheInternal(sm, true);
View Full Code Here

    protected synchronized void putObjectIntoLevel2CacheInternal(StateManager sm, boolean updateIfPresent)
    {
        if (sm.getClassMetaData().isCacheable())
        {
            Object id = sm.getInternalObjectId();
            Level2Cache l2Cache = omf.getLevel2Cache();
            if (!updateIfPresent && l2Cache.containsOid(id))
            {
                // Already present and not wanting to update
                return;
            }

            synchronized (l2Cache)
            {
                CachedPC cachedPC = sm.cache();
                if (cachedPC != null)
                {
                    // Update/add in the L2 cache
                    if (NucleusLogger.CACHE.isDebugEnabled())
                    {
                        if (l2Cache.containsOid(id))
                        {
                            NucleusLogger.CACHE.debug(LOCALISER.msg("004013",
                                StringUtils.toJVMIDString(sm.getObject()), id,
                                StringUtils.booleanArrayToString(cachedPC.getLoadedFields())));
                        }
                        else
                        {
                            NucleusLogger.CACHE.debug(LOCALISER.msg("004003",
                                StringUtils.toJVMIDString(sm.getObject()), id,
                                StringUtils.booleanArrayToString(cachedPC.getLoadedFields()),
                                StringUtils.objectArrayToString(cachedPC.getRelationFieldNames())));
                        }
                    }
                    l2Cache.put(id, cachedPC);
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.datanucleus.cache.Level2Cache

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.