|
|
@@ -3,6 +3,8 @@ |
|
|
|
|
|
|
|
using System.Data; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.EntityFrameworkCore.Infrastructure; |
|
|
|
using Microsoft.EntityFrameworkCore.Storage; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
@@ -33,6 +35,22 @@ namespace DotNetCore.CAP |
|
|
|
Flush(); |
|
|
|
} |
|
|
|
|
|
|
|
public override async Task CommitAsync(CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
Debug.Assert(DbTransaction != null); |
|
|
|
|
|
|
|
switch (DbTransaction) |
|
|
|
{ |
|
|
|
case IDbTransaction dbTransaction: |
|
|
|
dbTransaction.Commit(); |
|
|
|
break; |
|
|
|
case IDbContextTransaction dbContextTransaction: |
|
|
|
await dbContextTransaction.CommitAsync(cancellationToken); |
|
|
|
break; |
|
|
|
} |
|
|
|
Flush(); |
|
|
|
} |
|
|
|
|
|
|
|
public override void Rollback() |
|
|
|
{ |
|
|
|
Debug.Assert(DbTransaction != null); |
|
|
@@ -48,6 +66,21 @@ namespace DotNetCore.CAP |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public override async Task RollbackAsync(CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
Debug.Assert(DbTransaction != null); |
|
|
|
|
|
|
|
switch (DbTransaction) |
|
|
|
{ |
|
|
|
case IDbTransaction dbTransaction: |
|
|
|
dbTransaction.Rollback(); |
|
|
|
break; |
|
|
|
case IDbContextTransaction dbContextTransaction: |
|
|
|
await dbContextTransaction.RollbackAsync(cancellationToken); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public override void Dispose() |
|
|
|
{ |
|
|
|
(DbTransaction as IDbTransaction)?.Dispose(); |
|
|
|