/// <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 & CacheMode.Get) == CacheMode.Get);

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

                CacheKey ck = new CacheKey(id, persister.KeyType, persister.Role, source.EntityMode, factory);
                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)
                {
                    return false;
                }
                else
                {
                    IPersistenceContext persistenceContext = source.PersistenceContext;

                    // NH Different implementation but similar behavior H3.2 CollectionCacheEntry.Assemble do de same
                    collection.InitializeFromCache(persister, ce, persistenceContext.GetCollectionOwner(id, persister));
                    collection.AfterInitialize(persister);

                    persistenceContext.GetCollectionEntry(collection).PostInitialize(collection);
                    return true;
                }
            }
        }
		public virtual void Assemble(IPersistentCollection collection, ICollectionPersister persister, object owner)
		{
			collection.InitializeFromCache(persister, state, owner);
			collection.AfterInitialize(persister);
		}
Exemplo n.º 3
0
 public virtual void Assemble(IPersistentCollection collection, ICollectionPersister persister, object owner)
 {
     collection.InitializeFromCache(persister, state, owner);
     collection.AfterInitialize(persister);
 }