Browse Source

add and refactor transaction extension

master
Savorboard 6 years ago
parent
commit
5be6739cde
4 changed files with 33 additions and 24 deletions
  1. +18
    -5
      src/DotNetCore.CAP.MongoDB/ICapTransaction.MongoDB.cs
  2. +1
    -2
      src/DotNetCore.CAP.MySql/ICapTransaction.MySql.cs
  3. +7
    -8
      src/DotNetCore.CAP.PostgreSql/ICapTransaction.PostgreSql.cs
  4. +7
    -9
      src/DotNetCore.CAP.SqlServer/ICapTransaction.SqlServer.cs

+ 18
- 5
src/DotNetCore.CAP.MongoDB/ICapTransaction.MongoDB.cs View File

@@ -1,5 +1,4 @@
using System.Data;
using System.Diagnostics;
using System.Diagnostics;
using MongoDB.Driver;

// ReSharper disable once CheckNamespace
@@ -36,7 +35,7 @@ namespace DotNetCore.CAP

public override void Dispose()
{
(DbTransaction as IDbTransaction)?.Dispose();
(DbTransaction as IClientSessionHandle)?.Dispose();
}
}

@@ -49,11 +48,25 @@ namespace DotNetCore.CAP
{
dbTransaction.StartTransaction();
}
transaction.DbTransaction = dbTransaction;
transaction.AutoCommit = autoCommit;

return transaction;
}
}

public static IClientSessionHandle BeginAndJoinToTransaction(this IClientSessionHandle clientSessionHandle,
ICapPublisher publisher, bool autoCommit = false)
{
var capTrans = publisher.Transaction.Begin(clientSessionHandle, autoCommit);
return new CapMongoDbClientSessionHandle(capTrans);
}

public static IClientSessionHandle StartAndJoinToTransaction(this IMongoClient client,
ICapPublisher publisher, bool autoCommit = false)
{
var clientSessionHandle = client.StartSession();
return BeginAndJoinToTransaction(clientSessionHandle, publisher, autoCommit);
}
}
}

+ 1
- 2
src/DotNetCore.CAP.MySql/ICapTransaction.MySql.cs View File

@@ -55,7 +55,6 @@ namespace DotNetCore.CAP
public static ICapTransaction Begin(this ICapTransaction transaction,
IDbContextTransaction dbTransaction, bool autoCommit = false)
{

transaction.DbTransaction = dbTransaction;
transaction.AutoCommit = autoCommit;

@@ -66,7 +65,7 @@ namespace DotNetCore.CAP
ICapPublisher publisher, bool autoCommit = false)
{
var trans = database.BeginTransaction();
var capTrans = publisher.Transaction.Begin(trans);
var capTrans = publisher.Transaction.Begin(trans, autoCommit);
return new CapEFDbTransaction(capTrans);
}
}

+ 7
- 8
src/DotNetCore.CAP.PostgreSql/ICapTransaction.PostgreSql.cs View File

@@ -1,5 +1,6 @@
using System.Data;
using System.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;

// ReSharper disable once CheckNamespace
@@ -50,7 +51,7 @@ namespace DotNetCore.CAP
public static class CapTransactionExtensions
{
public static ICapTransaction Begin(this ICapTransaction transaction,
IDbTransaction dbTransaction, bool autoCommit = false)
IDbContextTransaction dbTransaction, bool autoCommit = false)
{
transaction.DbTransaction = dbTransaction;
transaction.AutoCommit = autoCommit;
@@ -58,14 +59,12 @@ namespace DotNetCore.CAP
return transaction;
}

public static ICapTransaction Begin(this ICapTransaction transaction,
IDbContextTransaction dbTransaction, bool autoCommit = false)
public static IDbContextTransaction BeginAndJoinToTransaction(this DatabaseFacade database,
ICapPublisher publisher, bool autoCommit = false)
{

transaction.DbTransaction = dbTransaction;
transaction.AutoCommit = autoCommit;

return transaction;
var trans = database.BeginTransaction();
var capTrans = publisher.Transaction.Begin(trans, autoCommit);
return new CapEFDbTransaction(capTrans);
}
}



+ 7
- 9
src/DotNetCore.CAP.SqlServer/ICapTransaction.SqlServer.cs View File

@@ -1,5 +1,6 @@
using System.Data;
using System.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;

// ReSharper disable once CheckNamespace
@@ -50,23 +51,20 @@ namespace DotNetCore.CAP
public static class CapTransactionExtensions
{
public static ICapTransaction Begin(this ICapTransaction transaction,
IDbTransaction dbTransaction, bool autoCommit = false)
IDbContextTransaction dbTransaction, bool autoCommit = false)
{

transaction.DbTransaction = dbTransaction;
transaction.AutoCommit = autoCommit;

return transaction;
}

public static ICapTransaction Begin(this ICapTransaction transaction,
IDbContextTransaction dbTransaction, bool autoCommit = false)
public static IDbContextTransaction BeginAndJoinToTransaction(this DatabaseFacade database,
ICapPublisher publisher, bool autoCommit = false)
{

transaction.DbTransaction = dbTransaction;
transaction.AutoCommit = autoCommit;

return transaction;
var trans = database.BeginTransaction();
var capTrans = publisher.Transaction.Begin(trans, autoCommit);
return new CapEFDbTransaction(capTrans);
}
}



Loading…
Cancel
Save