/// <summary> /// Create a new unit of work implementation. /// </summary> /// <param name="maybeUserProvidedConnection"></param> /// <param name="previous"></param> /// <returns></returns> public IUnitOfWorkImplementor Create(IDbConnection maybeUserProvidedConnection, IUnitOfWorkImplementor previous) { Guard.Assert <NotSupportedException>(maybeUserProvidedConnection == null, USER_PROVIDED_CONNECTION_EXCEPTION_MESSAGE); if (IsDebugEnabled) { log.Debug("NHMultipleUnitOfWorkFactory에서 [{0}]개의 IUnitOfWorkImplementor를 새로 생성합니다...", Count); } var previousImplementors = previous as NHMultipleUnitOfWorkImplementor; var currentImplementor = new NHMultipleUnitOfWorkImplementor(); for (var i = 0; i < Count; i++) { IUnitOfWorkImplementor previousImplementor = null; if (previousImplementors != null) { previousImplementor = previousImplementors[i]; } currentImplementor.Add(this[i].Create(null, previousImplementor)); } if (IsDebugEnabled) { log.Debug("NHMultipleUnitOfWorkFactory에서 [{0}]개의 IUnitOfWorkImplementor를 새로 생성했습니다!!!", Count); } return(currentImplementor); }
private IContainer NewContext() { var ctx = AssemblySetup.ApplicationContainer.CreateInnerContainer(); CurrentUow = ctx.Resolve <IUnitOfWorkImplementor>(); CurrentUow.CommitMode = CommitMode.Explicit; return(ctx); }
/// <summary> /// called internally to clear the current Unit Of Work and move to the previous one. /// </summary> /// <param name="unitOfWork"></param> public static void DisposeUnitOfWork(IUnitOfWorkImplementor unitOfWork) { if (IsDebugEnabled) { log.Debug("UnitOfWork 를 종료시킵니다. 종료되는 UnitOfWork의 Previous를 Current UnitOfWork로 교체합니다."); } Current = (unitOfWork != null) ? unitOfWork.Previous : null; }
public void Can_create_UnitOfWorkImplementor() { using (_mocks.Record()) { } using (_mocks.Playback()) { _uow = new UnitOfWorkImplementor(_factory, _session); Assert.AreSame(_factory, ((UnitOfWorkImplementor)_uow).Factory); Assert.AreSame(_session, ((UnitOfWorkImplementor)_uow).Session); } }
public void Can_Flush_UnitOfWorkImplementor() { using (_mocks.Record()) { Expect.Call(_session.Flush); } using (_mocks.Playback()) { _uow = new UnitOfWorkImplementor(_factory, _session); _uow.Flush(); } }
public void Can_Flush_UnitOfWorkImplementor() { using(_mocks.Record()) { Expect.Call(_session.Flush); } using (_mocks.Playback()) { _uow = new UnitOfWorkImplementor(_factory, _session); _uow.Flush(); } }
public void Can_Dispose_UnitOfWorkImplementor() { using (_mocks.Record()) { Expect.Call(() => _factory.DisposeUnitOfWork(null, dbKey)).IgnoreArguments(); Expect.Call(_session.Dispose); } using(_mocks.Playback()) { _uow = new UnitOfWorkImplementor(_factory, _session, dbKey); _uow.Dispose(); } }
public void Can_BeginTransaction() { using (_mocks.Record()) { Expect.Call(_session.BeginTransaction()).Return(null); } using (_mocks.Playback()) { _uow = new UnitOfWorkImplementor(_factory, _session, dbKey); var transaction = _uow.BeginTransaction(); Assert.IsNotNull(transaction); } }
public void Can_Dispose_UnitOfWorkImplementor() { using (_mocks.Record()) { Expect.Call(() => _factory.DisposeUnitOfWork(null)).IgnoreArguments(); Expect.Call(_session.Dispose); } using (_mocks.Playback()) { _uow = new UnitOfWorkImplementor(_factory, _session); _uow.Dispose(); } }
public void Can_BeginTransaction() { using (_mocks.Record()) { Expect.Call(_session.BeginTransaction()).Return(null); } using (_mocks.Playback()) { _uow = new UnitOfWorkImplementor(_factory, _session); var transaction = _uow.BeginTransaction(); Assert.IsNotNull(transaction); } }
public void Can_create_UnitOfWorkImplementor() { using(_mocks.Record()) { } using (_mocks.Playback()) { _uow = new UnitOfWorkImplementor(_factory, _session); Assert.AreSame(_factory, ((UnitOfWorkImplementor)_uow).Factory); Assert.AreSame(_session, ((UnitOfWorkImplementor)_uow).Session); } }
public void Can_BeginTransaction_specifying_isolation_level() { var isolationLevel = IsolationLevel.Serializable; using (_mocks.Record()) { Expect.Call(_session.BeginTransaction(isolationLevel)).Return(null); } using (_mocks.Playback()) { _uow = new UnitOfWorkImplementor(_factory, _session, dbKey); var transaction = _uow.BeginTransaction(isolationLevel); Assert.IsNotNull(transaction); } }
public void Can_BeginTransaction_specifying_isolation_level() { var isolationLevel = IsolationLevel.Serializable; using (_mocks.Record()) { Expect.Call(_session.BeginTransaction(isolationLevel)).Return(null); } using (_mocks.Playback()) { _uow = new UnitOfWorkImplementor(_factory, _session); var transaction = _uow.BeginTransaction(isolationLevel); Assert.IsNotNull(transaction); } }
public void CanExecuteTransactionFlushWithIsolationLevel() { var tx = _mocks.StrictMock <ITransaction>(); var session = _mocks.DynamicMock <ISession>(); SetupResult.For(session.BeginTransaction(IsolationLevel.Serializable)).Return(tx); _uow = _mocks.PartialMock <UnitOfWorkImplementor>(_factory, session); using (_mocks.Record()) { Expect.Call(tx.Commit); Expect.Call(tx.Dispose); } using (_mocks.Playback()) { _uow.TransactionalFlush(IsolationLevel.Serializable); } }
public IUnitOfWorkImplementor Create(IDbConnection maybeUserProvidedConnection, IUnitOfWorkImplementor previous) { Guard.Against <NotSupportedException>(maybeUserProvidedConnection != null, USER_PROVIDED_CONNECTION_EXCEPTION_MESSAGE); MultipleUnitsOfWorkImplementor previousImplementors = previous as MultipleUnitsOfWorkImplementor; MultipleUnitsOfWorkImplementor currentImplementor = new MultipleUnitsOfWorkImplementor(); for (int i = 0; i < Count; i++) { IUnitOfWorkImplementor previousImplementor = null; if (previousImplementors != null) { previousImplementor = previousImplementors[i]; } currentImplementor.Add(this[i].Create(null, previousImplementor)); } return(currentImplementor); }
/// <summary> /// Disposing a given Unit of work /// </summary> /// <param name="adapter">instance of IUnitOfWork to dispose.</param> public virtual void DisposeUnitOfWork(IUnitOfWorkImplementor adapter) { adapter.ShouldNotBeNull("adapter"); if (IsDebugEnabled) { log.Debug("[{0}]를 Dispose합니다.", adapter.GetType().FullName); } ISession session = null; if (adapter.Previous != null) { session = adapter.Previous.Session; } CurrentSession = session; UnitOfWork.DisposeUnitOfWork(adapter); }
public void Can_execute_TransactionalFlush() { var tx = _mocks.CreateMock <ITransaction>(); var session = _mocks.DynamicMock <ISession>(); SetupResult.For(session.BeginTransaction(IsolationLevel.ReadCommitted)).Return(tx); _uow = _mocks.PartialMock <UnitOfWorkImplementor>(_factory, _session); using (_mocks.Record()) { Expect.Call(tx.Commit); Expect.Call(tx.Dispose); } using (_mocks.Playback()) { _uow = new UnitOfWorkImplementor(_factory, session); _uow.TransactionalFlush(); } }
/// <summary> /// Start a Unit of Work /// is called /// </summary> /// <returns> /// An IUnitOfwork object that can be used to work with the current UoW. /// </returns> public static IUnitOfWork Start(IDbConnection connection, UnitOfWorkNestingOptions nestingOptions) { if (globalNonThreadSafeUnitOfwork != null) { return(globalNonThreadSafeUnitOfwork); } IUnitOfWorkImplementor existing = (IUnitOfWorkImplementor)Local.Data[CurrentUnitOfWorkKey]; if (nestingOptions == UnitOfWorkNestingOptions.ReturnExistingOrCreateUnitOfWork && existing != null) { existing.IncrementUsages(); return(existing); } Current = IoC.Resolve <IUnitOfWorkFactory>().Create(connection, existing); foreach (IUnitOfWorkAware workAware in IoC.ResolveAll <IUnitOfWorkAware>()) { workAware.UnitOfWorkStarted(Current); } return(Current); }
/// <summary> /// Called internally to clear the current UoW and move to the previous one. /// </summary> public static void DisposeUnitOfWork(IUnitOfWorkImplementor unitOfWork) { IUnitOfWorkAware[] awareImplmenters = IoC.ResolveAll <IUnitOfWorkAware>(); foreach (IUnitOfWorkAware workAware in awareImplmenters) { workAware.UnitOfWorkDisposing(Current); } IUnitOfWork disposed = null; if (IsStarted) { disposed = Current; } Current = unitOfWork.Previous; foreach (IUnitOfWorkAware workAware in awareImplmenters) { workAware.UnitOfWorkDisposed(disposed); } }
public void Can_execute_TransactionFlush() { var tx = _mocks.CreateMock<ITransaction>(); var session = _mocks.DynamicMock<ISession>(); SetupResult.For(session.BeginTransaction(IsolationLevel.ReadCommitted)).Return(tx); _uow = _mocks.PartialMock<UnitOfWorkImplementor>(_factory, _session, dbKey); using (_mocks.Record()) { Expect.Call(tx.Commit); Expect.Call(tx.Dispose); } using (_mocks.Playback()) { _uow = new UnitOfWorkImplementor(_factory, session, dbKey); _uow.TransactionalFlush(); } }
/// <summary> /// Dispose the current session and the unit of work /// </summary> /// <param name="adapter"></param> public void DisposeUnitOfWork(IUnitOfWorkImplementor adapter) { CurrentSession = null; UnitOfWork.DisposeUnitOfWork(adapter); }
public static void DisposeUnitOfWork(IUnitOfWorkImplementor unitOfWork) { // Current = unitOfWork.Previous; Current = null; }
/// <summary> /// Create a new unit of work implementation. /// </summary> /// <param name="maybeUserProvidedConnection">instance of IDbConnection.</param> /// <param name="previous">현재 사용중인 IUnitOfWorkImplementor의 인스턴스</param> /// <returns>새로 생성한 IUnitOfWorkImplementor의 인스턴스</returns> public IUnitOfWorkImplementor Create(IDbConnection maybeUserProvidedConnection, IUnitOfWorkImplementor previous) { if (IsDebugEnabled) { log.Debug("새로운 IUnitOfWorkImplentor 인스턴스 생성을 시작합니다..."); log.Debug("새로운 ISession을 생성하여, CurrentSession으로 등록합니다..."); } var session = CreateSession(maybeUserProvidedConnection); Local.Data[CurrentNHibernateSessionKey] = session; if (IsDebugEnabled) { log.Debug("새로운 NHibernate Session을 Current Thread Context에 저장했습니다. Key=[{0}]", CurrentNHibernateSessionKey); } return(new NHUnitOfWorkAdapter(this, session, (NHUnitOfWorkAdapter)previous)); }
public void Is_DatabaseKey_Correct() { using (_mocks.Record()) { } using (_mocks.Playback()) { _uow = new UnitOfWorkImplementor(_factory, _session, dbKey); Assert.AreEqual(_uow.DatabaseKey, dbKey); } }
public ActiveRecordUnitOfWorkAdapter(ISessionScope scope, IUnitOfWorkImplementor previous) { this.scope = scope; this.previous = previous; }
public IUnitOfWorkImplementor Create(IDbConnection maybeUserProvidedConnection, IUnitOfWorkImplementor previous) { ISession session = CreateSession(maybeUserProvidedConnection); session.FlushMode = FlushMode.Commit; Local.Data[CurrentNHibernateSessionKey] = session; return(new NHibernateUnitOfWorkAdapter(this, session, (NHibernateUnitOfWorkAdapter)previous)); }
/// <summary> /// Creates a new repository instance. /// </summary> /// <param name="unitOfWork">The current open NHibernate UOW</param> protected RepositoryBase(IUnitOfWorkImplementor unitOfWork) { _unitOfWork = unitOfWork; }
/// <summary> /// Creates a new repository instance. /// </summary> /// <param name="unitOfWork"> /// A delegate for getting the ISession associated with the current UOW. /// </param> public UserRepository(IUnitOfWorkImplementor unitOfWork) : base(unitOfWork) { }
public IUnitOfWorkImplementor Create(IDbConnection maybeUserProvidedConnection, IUnitOfWorkImplementor previous) { InitializeIfNecessary(); ISessionScope scope; if (maybeUserProvidedConnection == null) { scope = new SessionScope(FlushAction.Never); } else { scope = new DifferentDatabaseScope(maybeUserProvidedConnection); } return(new ActiveRecordUnitOfWorkAdapter(scope, previous)); }
public IUnitOfWorkImplementor Create(IDbConnection maybeUserProvidedConnection, IUnitOfWorkImplementor previous) { ISession session = CreateSession(maybeUserProvidedConnection); session.FlushMode = FlushMode.Commit; Local.Data[CurrentNHibernateSessionKey] = session; return new NHibernateUnitOfWorkAdapter(this, session, (NHibernateUnitOfWorkAdapter)previous); }
/// <summary> /// Dispose of the current unit of work /// </summary> /// <param name="unitOfWork"></param> public static void DisposeUnitOfWork(IUnitOfWorkImplementor unitOfWork) { CurrentUnitOfWork = null; }
/// <summary> /// Called internally to clear the current UoW and move to the previous one. /// </summary> public static void DisposeUnitOfWork(IUnitOfWorkImplementor unitOfWork) { IUnitOfWorkAware[] awareImplmenters = IoC.ResolveAll<IUnitOfWorkAware>(); foreach (IUnitOfWorkAware workAware in awareImplmenters) workAware.UnitOfWorkDisposing(Current); IUnitOfWork disposed = null; if(IsStarted) disposed = Current; Current = unitOfWork.Previous; foreach (IUnitOfWorkAware workAware in awareImplmenters) workAware.UnitOfWorkDisposed(disposed); }
public IUnitOfWorkImplementor Create(IDbConnection maybeUserProvidedConnection, IUnitOfWorkImplementor previous) { InitializeIfNecessary(); ISessionScope scope; if (maybeUserProvidedConnection == null) scope = new SessionScope(FlushAction.Never); else scope = new DifferentDatabaseScope(maybeUserProvidedConnection); return new ActiveRecordUnitOfWorkAdapter(scope, previous); }
public static void DisposeUnitOfWork(IUnitOfWorkImplementor unitOfWork) { CurrentUnitOfWork = null; }
/// <summary> /// called internally to clear the current Unit Of Work and move to the previous one. /// </summary> /// <param name="unitOfWork"></param> public static void DisposeUnitOfWork(IUnitOfWorkImplementor unitOfWork) { if(IsDebugEnabled) log.Debug("UnitOfWork 를 종료시킵니다. 종료되는 UnitOfWork의 Previous를 Current UnitOfWork로 교체합니다."); Current = (unitOfWork != null) ? unitOfWork.Previous : null; }
public void Can_execute_TransactionalFlush_specifying_isolation_level() { var tx = _mocks.CreateMock<ITransaction>(); var session = _mocks.DynamicMock<ISession>(); SetupResult.For(session.BeginTransaction(IsolationLevel.Serializable)).Return(tx); _uow = _mocks.PartialMock<UnitOfWorkImplementor>(_factory, session); using (_mocks.Record()) { Expect.Call(tx.Commit); Expect.Call(tx.Dispose); } using (_mocks.Playback()) { _uow.TransactionalFlush(IsolationLevel.Serializable); } }