⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 evictvisitor.cs

📁 NHibernate NET开发者所需的
💻 CS
字号:
using log4net;
using NHibernate.Collection;
using NHibernate.Engine;
using NHibernate.Impl;
using NHibernate.Type;

namespace NHibernate.Event.Default
{
	/// <summary> 
	/// Evict any collections referenced by the object from the session cache.
	/// This will NOT pick up any collections that were dereferenced, so they
	/// will be deleted (suboptimal but not exactly incorrect). 
	/// </summary>
	public class EvictVisitor : AbstractVisitor
	{
		private static readonly ILog log = LogManager.GetLogger(typeof(EvictVisitor));

		public EvictVisitor(IEventSource session) : base(session) { }

		internal override object ProcessCollection(object collection, CollectionType type)
		{

			if (collection != null)
				EvictCollection(collection, type);

			return null;
		}

		public virtual void EvictCollection(object value, CollectionType type)
		{
			IPersistentCollection pc;
			if (type.IsArrayType)
			{
				pc = Session.PersistenceContext.RemoveCollectionHolder(value);
			}
			else if (value is IPersistentCollection)
			{
				pc = (IPersistentCollection)value;
			}
			else
			{
				return; //EARLY EXIT!
			}

			IPersistentCollection collection = pc;
			if (collection.UnsetSession(Session))
				EvictCollection(collection);
		}

		private void EvictCollection(IPersistentCollection collection)
		{
			CollectionEntry ce = (CollectionEntry)Session.PersistenceContext.CollectionEntries[collection];
			Session.PersistenceContext.CollectionEntries.Remove(collection);
			if (log.IsDebugEnabled)
				log.Debug("evicting collection: " + MessageHelper.InfoString(ce.LoadedPersister, ce.LoadedKey, Session.Factory));
			if (ce.LoadedPersister != null && ce.LoadedKey != null)
			{
				//TODO: is this 100% correct?
				Session.PersistenceContext.CollectionsByKey.Remove(new CollectionKey(ce.LoadedPersister, ce.LoadedKey, Session.EntityMode));
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -