-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolved #7489: Async implementation for Transaction Commit/Rollback.
- Loading branch information
Showing
6 changed files
with
40 additions
and
61 deletions.
There are no files selected for viewing
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
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
27 changes: 12 additions & 15 deletions
27
framework/src/Volo.Abp.MongoDB/Volo/Abp/Uow/MongoDB/MongoDbTransactionApi.cs
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,42 +1,39 @@ | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MongoDB.Driver; | ||
using Volo.Abp.Threading; | ||
|
||
namespace Volo.Abp.Uow.MongoDB | ||
{ | ||
public class MongoDbTransactionApi : ITransactionApi, ISupportsRollback | ||
{ | ||
public IClientSessionHandle SessionHandle { get; } | ||
|
||
public MongoDbTransactionApi(IClientSessionHandle sessionHandle) | ||
protected ICancellationTokenProvider CancellationTokenProvider { get; } | ||
|
||
public MongoDbTransactionApi( | ||
IClientSessionHandle sessionHandle, | ||
ICancellationTokenProvider cancellationTokenProvider) | ||
{ | ||
SessionHandle = sessionHandle; | ||
CancellationTokenProvider = cancellationTokenProvider; | ||
} | ||
|
||
public async Task CommitAsync() | ||
{ | ||
await SessionHandle.CommitTransactionAsync(); | ||
} | ||
|
||
protected void Commit() | ||
{ | ||
SessionHandle.CommitTransaction(); | ||
await SessionHandle.CommitTransactionAsync(CancellationTokenProvider.Token); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
SessionHandle.Dispose(); | ||
} | ||
|
||
public void Rollback() | ||
{ | ||
SessionHandle.AbortTransaction(); | ||
} | ||
|
||
public async Task RollbackAsync(CancellationToken cancellationToken) | ||
{ | ||
await SessionHandle.AbortTransactionAsync(cancellationToken); | ||
await SessionHandle.AbortTransactionAsync( | ||
CancellationTokenProvider.FallbackToProvider(cancellationToken) | ||
); | ||
} | ||
} | ||
} |
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
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
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