コード例 #1
0
        /// <summary> Try to initialize a collection from the cache</summary>
        private bool InitializeCollectionFromCache(object id, ICollectionPersister persister, IPersistentCollection collection, ISessionImplementor source)
        {
            if (!(source.EnabledFilters.Count == 0) && persister.IsAffectedByEnabledFilters(source))
            {
                log.Debug("disregarding cached version (if any) of collection due to enabled filters ");
                return(false);
            }

            bool useCache = persister.HasCache && source.CacheMode.HasFlag(CacheMode.Get);

            if (!useCache)
            {
                return(false);
            }
            else
            {
                ISessionFactoryImplementor factory = source.Factory;

                CacheKey ck = source.GenerateCacheKey(id, persister.KeyType, persister.Role);
                object   ce = persister.Cache.Get(ck, source.Timestamp);

                if (factory.Statistics.IsStatisticsEnabled)
                {
                    if (ce == null)
                    {
                        factory.StatisticsImplementor.SecondLevelCacheMiss(persister.Cache.RegionName);
                    }
                    else
                    {
                        factory.StatisticsImplementor.SecondLevelCacheHit(persister.Cache.RegionName);
                    }
                }

                if (ce == null)
                {
                    log.DebugFormat("Collection cache miss: {0}", ck);
                }
                else
                {
                    log.DebugFormat("Collection cache hit: {0}", ck);
                }

                if (ce == null)
                {
                    return(false);
                }
                else
                {
                    IPersistenceContext persistenceContext = source.PersistenceContext;

                    CollectionCacheEntry cacheEntry = (CollectionCacheEntry)persister.CacheEntryStructure.Destructure(ce, factory);
                    cacheEntry.Assemble(collection, persister, persistenceContext.GetCollectionOwner(id, persister));

                    persistenceContext.GetCollectionEntry(collection).PostInitialize(collection);
                    return(true);
                }
            }
        }
        private bool Assemble(
            CacheKey ck, object ce, ICollectionPersister persister, ISessionImplementor source,
            IPersistentCollection collection, object collectionKey, bool alterStatistics)
        {
            ISessionFactoryImplementor factory = source.Factory;

            if (factory.Statistics.IsStatisticsEnabled && alterStatistics)
            {
                if (ce == null)
                {
                    factory.StatisticsImplementor.SecondLevelCacheMiss(persister.Cache.RegionName);
                }
                else
                {
                    factory.StatisticsImplementor.SecondLevelCacheHit(persister.Cache.RegionName);
                }
            }

            if (ce == null)
            {
                log.Debug("Collection cache miss: {0}", ck);
            }
            else
            {
                log.Debug("Collection cache hit: {0}", ck);
            }

            if (ce == null)
            {
                return(false);
            }
            else
            {
                IPersistenceContext persistenceContext = source.PersistenceContext;

                CollectionCacheEntry cacheEntry = (CollectionCacheEntry)persister.CacheEntryStructure.Destructure(ce, factory);
                cacheEntry.Assemble(collection, persister, persistenceContext.GetCollectionOwner(collectionKey, persister));

                persistenceContext.GetCollectionEntry(collection).PostInitialize(collection, persistenceContext);

                if (collection.HasQueuedOperations)
                {
                    collection.ApplyQueuedOperations();
                }
                return(true);
            }
        }