generated from SwissLife-OSS/template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added explicit setting of client session handle via parameter. (#70)
- Loading branch information
Showing
10 changed files
with
1,989 additions
and
1,908 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,64 @@ | ||
using System.Transactions; | ||
using MongoDB.Driver; | ||
|
||
namespace MongoDB.Extensions.Transactions | ||
namespace MongoDB.Extensions.Transactions; | ||
|
||
public class MongoDbEnlistmentScope : IEnlistmentNotification | ||
{ | ||
public class MongoDbEnlistmentScope : IEnlistmentNotification | ||
{ | ||
public delegate void Unregister(); | ||
public delegate void Unregister(); | ||
|
||
private readonly Unregister _unregister; | ||
private readonly IClientSessionHandle _sessionHandle; | ||
|
||
private readonly Unregister _unregister; | ||
private readonly IClientSessionHandle _sessionHandle; | ||
public MongoDbEnlistmentScope( | ||
IClientSessionHandle sessionHandle, | ||
Unregister unregister) | ||
{ | ||
_sessionHandle = sessionHandle; | ||
_unregister = unregister; | ||
} | ||
|
||
public MongoDbEnlistmentScope(IClientSessionHandle sessionHandle, Unregister unregister) | ||
public void Commit(Enlistment enlistment) | ||
{ | ||
try | ||
{ | ||
_sessionHandle = sessionHandle; | ||
_unregister = unregister; | ||
_sessionHandle.CommitTransaction(); | ||
enlistment.Done(); | ||
} | ||
|
||
public void Commit(Enlistment enlistment) | ||
finally | ||
{ | ||
try | ||
{ | ||
_sessionHandle.CommitTransaction(); | ||
enlistment.Done(); | ||
} | ||
finally | ||
{ | ||
_unregister(); | ||
} | ||
_unregister(); | ||
} | ||
} | ||
|
||
public void InDoubt(Enlistment enlistment) | ||
public void InDoubt(Enlistment enlistment) | ||
{ | ||
try | ||
{ | ||
try | ||
{ | ||
_sessionHandle.AbortTransaction(); | ||
enlistment.Done(); | ||
} | ||
finally | ||
{ | ||
_unregister(); | ||
} | ||
_sessionHandle.AbortTransaction(); | ||
enlistment.Done(); | ||
} | ||
|
||
public void Prepare(PreparingEnlistment preparingEnlistment) | ||
finally | ||
{ | ||
preparingEnlistment.Prepared(); | ||
_unregister(); | ||
} | ||
} | ||
|
||
public void Prepare(PreparingEnlistment preparingEnlistment) | ||
{ | ||
preparingEnlistment.Prepared(); | ||
} | ||
|
||
public void Rollback(Enlistment enlistment) | ||
public void Rollback(Enlistment enlistment) | ||
{ | ||
try | ||
{ | ||
_sessionHandle.AbortTransaction(); | ||
enlistment.Done(); | ||
} | ||
finally | ||
{ | ||
try | ||
{ | ||
_sessionHandle.AbortTransaction(); | ||
enlistment.Done(); | ||
} | ||
finally | ||
{ | ||
_unregister(); | ||
} | ||
_unregister(); | ||
} | ||
} | ||
} |
Oops, something went wrong.