@@ -36,31 +36,38 @@ public void EnlistInDistributedTransactionIfNeeded(ISessionImplementor session)
36
36
logger . DebugFormat ( "enlisted into DTC transaction: {0}" ,
37
37
transactionContext . AmbientTransation . IsolationLevel ) ;
38
38
session . AfterTransactionBegin ( null ) ;
39
- transactionContext . AmbientTransation . TransactionCompleted +=
40
- delegate ( object sender , TransactionEventArgs e )
39
+
40
+ TransactionCompletedEventHandler handler = null ;
41
+
42
+ handler = delegate ( object sender , TransactionEventArgs e )
43
+ {
44
+ using ( new SessionIdLoggingContext ( session . SessionId ) )
41
45
{
42
- using ( new SessionIdLoggingContext ( session . SessionId ) )
46
+ ( ( DistributedTransactionContext ) session . TransactionContext ) . IsInActiveTransaction = false ;
47
+
48
+ bool wasSuccessful = false ;
49
+ try
43
50
{
44
- ( ( DistributedTransactionContext ) session . TransactionContext ) . IsInActiveTransaction = false ;
45
-
46
- bool wasSuccessful = false ;
47
- try
48
- {
49
- wasSuccessful = e . Transaction . TransactionInformation . Status
50
- == TransactionStatus . Committed ;
51
- }
52
- catch ( ObjectDisposedException ode )
53
- {
54
- logger . Warn ( "Completed transaction was disposed, assuming transaction rollback" , ode ) ;
55
- }
56
- session . AfterTransactionCompletion ( wasSuccessful , null ) ;
57
- if ( transactionContext . ShouldCloseSessionOnDistributedTransactionCompleted )
58
- {
59
- session . CloseSessionFromDistributedTransaction ( ) ;
60
- }
61
- session . TransactionContext = null ;
51
+ wasSuccessful = e . Transaction . TransactionInformation . Status
52
+ == TransactionStatus . Committed ;
53
+ }
54
+ catch ( ObjectDisposedException ode )
55
+ {
56
+ logger . Warn ( "Completed transaction was disposed, assuming transaction rollback" , ode ) ;
57
+ }
58
+ session . AfterTransactionCompletion ( wasSuccessful , null ) ;
59
+ if ( transactionContext . ShouldCloseSessionOnDistributedTransactionCompleted )
60
+ {
61
+ session . CloseSessionFromDistributedTransaction ( ) ;
62
62
}
63
- } ;
63
+ session . TransactionContext = null ;
64
+ }
65
+
66
+ e . Transaction . TransactionCompleted -= handler ;
67
+ } ;
68
+
69
+ transactionContext . AmbientTransation . TransactionCompleted += handler ;
70
+
64
71
transactionContext . AmbientTransation . EnlistVolatile ( transactionContext ,
65
72
EnlistmentOptions . EnlistDuringPrepareRequired ) ;
66
73
}
0 commit comments