public object Structure(object item) { CollectionCacheEntry entry = (CollectionCacheEntry)item; object[] state = entry.State; IDictionary map = new Hashtable(state.Length); for (int i = 0; i < state.Length; ) { map[state[i++]] = state[i++]; } return map; }
/// <summary> Add the collection to the second-level cache </summary> /// <param name="lce">The entry representing the collection to add </param> /// <param name="persister">The persister </param> private void AddCollectionToCache(LoadingCollectionEntry lce, ICollectionPersister persister) { ISessionImplementor session = LoadContext.PersistenceContext.Session; ISessionFactoryImplementor factory = session.Factory; if (log.IsDebugEnabled) { log.Debug("Caching collection: " + MessageHelper.InfoString(persister, lce.Key, factory)); } if (!(session.EnabledFilters.Count == 0) && persister.IsAffectedByEnabledFilters(session)) { // some filters affecting the collection are enabled on the session, so do not do the put into the cache. log.Debug("Refusing to add to cache due to enabled filters"); // todo : add the notion of enabled filters to the CacheKey to differentiate filtered collections from non-filtered; // but CacheKey is currently used for both collections and entities; would ideally need to define two separate ones; // currently this works in conjunction with the check on // DefaultInitializeCollectionEventHandler.initializeCollectionFromCache() (which makes sure to not read from // cache with enabled filters). return; // EARLY EXIT!!!!! } IComparer versionComparator; object version; if (persister.IsVersioned) { versionComparator = persister.OwnerEntityPersister.VersionType.Comparator; object collectionOwner = LoadContext.PersistenceContext.GetCollectionOwner(lce.Key, persister); version = LoadContext.PersistenceContext.GetEntry(collectionOwner).Version; } else { version = null; versionComparator = null; } CollectionCacheEntry entry = new CollectionCacheEntry(lce.Collection, persister); CacheKey cacheKey = session.GenerateCacheKey(lce.Key, persister.KeyType, persister.Role); bool put = persister.Cache.Put(cacheKey, persister.CacheEntryStructure.Structure(entry), session.Timestamp, version, versionComparator, factory.Settings.IsMinimalPutsEnabled && session.CacheMode != CacheMode.Refresh); if (put && factory.Statistics.IsStatisticsEnabled) { factory.StatisticsImplementor.SecondLevelCachePut(persister.Cache.RegionName); } }
public virtual object Structure(object item) { CollectionCacheEntry entry = (CollectionCacheEntry)item; return(new ArrayList(entry.State)); }
public override void AfterTransactionCompletion(bool success) { // NH Different behavior: to support unlocking collections from the cache.(r3260) if (Persister.HasCache) { CacheKey ck = new CacheKey(Key, Persister.KeyType, Persister.Role, Session.EntityMode, Session.Factory); if (success) { // we can't disassemble a collection if it was uninitialized // or detached from the session if (Collection.WasInitialized && Session.PersistenceContext.ContainsCollection(Collection)) { CollectionCacheEntry entry = new CollectionCacheEntry(Collection, Persister); bool put = Persister.Cache.AfterUpdate(ck, entry, null, Lock); if (put && Session.Factory.Statistics.IsStatisticsEnabled) { Session.Factory.StatisticsImplementor.SecondLevelCachePut(Persister.Cache.RegionName); } } } else { Persister.Cache.Release(ck, Lock); } } }