/// <summary> /// Monitor when a global transaction close, we need to disconnect from the current transaction /// and reconnect. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void OnTransactionClosing(Object sender, TransactionClosingEventArgs e) { //First of all check if the transaction is rollbacked, this means that we need to dispose all //Sessions because all sessions are no longer usable. if (e.IsDoomed) { IterateThroughAllOpenSessionInContext(sd => sd.Session.Dispose()); } else { //a transaction is about to be committed, flush everything IterateThroughAllOpenSessionInContext(sd => sd.Session.Flush()); //if we are still in a global transaction, we can still use the //same connection because DataAccess layer use the same connection for all transaction level. if (GlobalTransactionManager.TransactionsCount > 2) { return; } //Ok, we are out of all transaction, we need to recreate a valid connection for each session. IterateThroughAllOpenSessionInContext(sd => { sd.Session.Disconnect(); sd.Session.Reconnect(); }); } }
/// <summary> /// Monitor when a global transaction close, we need to disconnect from the current transaction /// and reconnect. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void OnTransactionClosing(Object sender, TransactionClosingEventArgs e) { //First of all check if the transaction is rollbacked, this means that we need to dispose all //Sessions because all sessions are no longer usable. if (e.IsDoomed) { IterateThroughAllOpenSessionInContext(sd => sd.Session.Dispose()); } else { //a transaction is about to be committed, flush everything IterateThroughAllOpenSessionInContext(sd => sd.Session.Flush()); //if we are still in a global transaction, we can still use the //same connection because DataAccess layer use the same connection for all transaction level. if (GlobalTransactionManager.TransactionsCount > 2) return; //Ok, we are out of all transaction, we need to recreate a valid connection for each session. IterateThroughAllOpenSessionInContext(sd => { sd.Session.Disconnect(); sd.Session.Reconnect(); }); } }