public void Dispose() { if (NotRaised) { WorkbenchUtil <string, bool> .SetValue(UniqueRaiseKey, key, false); } }
ISession OpenSession(ISessionFactory factory, ShardId shardId, PartitionId partitionId) { var workbench = Workbench.Current; var session = WorkbenchUtil <ShardId, ISession> .GetValue(SessionCacheKey, shardId); //检测同一个session是否有相同的逻辑表但真实表不一致的情况 if (session != null) { var interceptor = (ShardInterceptor)((ISessionImplementor)session).Interceptor; if (!interceptor.Register(partitionId)) { session = null; } } if (session == null) { workbench.AttachDisposeHandler(DisposeSessions); using (var scope = ProfilerContext.Profile("open nhibernate inner session")) { session = factory.OpenSession(new ShardInterceptor(partitionId)); } WorkbenchUtil <ShardId, ISession> .SetValue(SessionCacheKey, shardId, session); } if (TransactionScope.IsScope && !TransactionScope.IsLinkWidhTranscation(session)) { ProfilerContext.Current.Trace("platform", "open a transaction session"); TransactionScope.Push(new NHibernateTranscation(session.BeginTransaction()), session); } return(session); }
void DisposeSessions(Workbench workbench) { var sessions = WorkbenchUtil <ShardId, ISession> .GetValues(SessionCacheKey); foreach (var session in sessions) { session.Dispose(); } WorkbenchUtil <ShardId, ISession> .Clear(SessionCacheKey); }
public UniqueRaise(RaiseType raiseType, ClassDefineMetadata metadata, object entity, bool autoDisposed) { key = String.Format("{0}:{1}:{2}", metadata.EntityType.FullName, EntityUtil.GetId(entity), raiseType); NotRaised = !WorkbenchUtil <string, bool> .GetValue(UniqueRaiseKey, key); if (NotRaised) { WorkbenchUtil <string, bool> .SetValue(UniqueRaiseKey, key, true); } AutoDisposed = autoDisposed; }