Преглед изворни кода

refactor extension methods

master
Savorboard пре 6 година
родитељ
комит
60c028f11c
6 измењених фајлова са 48 додато и 89 уклоњено
  1. +2
    -8
      src/DotNetCore.CAP.MongoDB/ICapTransaction.MongoDB.cs
  2. +23
    -1
      src/DotNetCore.CAP.MySql/ICapTransaction.MySql.cs
  3. +22
    -1
      src/DotNetCore.CAP.PostgreSql/ICapTransaction.PostgreSql.cs
  4. +1
    -1
      src/DotNetCore.CAP/ICapTransaction.Base.cs
  5. +0
    -38
      src/DotNetCore.CAP/Internal/RelationDbTransaction.cs
  6. +0
    -40
      src/DotNetCore.CAP/TransactionExtensions.cs

+ 2
- 8
src/DotNetCore.CAP.MongoDB/ICapTransaction.MongoDB.cs Прегледај датотеку

@@ -58,18 +58,12 @@ namespace DotNetCore.CAP
return transaction;
}

public static IClientSessionHandle BeginAndJoinToTransaction(this IClientSessionHandle clientSessionHandle,
public static IClientSessionHandle StartTransaction(this IMongoClient client,
ICapPublisher publisher, bool autoCommit = false)
{
var clientSessionHandle = client.StartSession();
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);
}
}
}

+ 23
- 1
src/DotNetCore.CAP.MySql/ICapTransaction.MySql.cs Прегледај датотеку

@@ -64,12 +64,34 @@ namespace DotNetCore.CAP
return transaction;
}

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

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

return transaction;
}

public static IDbContextTransaction BeginTransaction(this DatabaseFacade database,
ICapPublisher publisher, bool autoCommit = false)
{
var trans = database.BeginTransaction();
var capTrans = publisher.Transaction.Begin(trans, autoCommit);
return new CapEFDbTransaction(capTrans);
}

public static ICapTransaction BeginTransaction(this IDbConnection dbConnection,
ICapPublisher publisher, bool autoCommit = false)
{
if (dbConnection.State == ConnectionState.Closed)
{
dbConnection.Open();
}

var dbTransaction = dbConnection.BeginTransaction();
return publisher.Transaction.Begin(dbTransaction, autoCommit);
}
}
}

+ 22
- 1
src/DotNetCore.CAP.PostgreSql/ICapTransaction.PostgreSql.cs Прегледај датотеку

@@ -55,6 +55,15 @@ namespace DotNetCore.CAP

public static class CapTransactionExtensions
{
public static ICapTransaction Begin(this ICapTransaction transaction,
IDbTransaction dbTransaction, bool autoCommit = false)
{
transaction.DbTransaction = dbTransaction;
transaction.AutoCommit = autoCommit;

return transaction;
}

public static ICapTransaction Begin(this ICapTransaction transaction,
IDbContextTransaction dbTransaction, bool autoCommit = false)
{
@@ -64,7 +73,19 @@ namespace DotNetCore.CAP
return transaction;
}

public static IDbContextTransaction BeginAndJoinToTransaction(this DatabaseFacade database,
public static ICapTransaction BeginTransaction(this IDbConnection dbConnection,
ICapPublisher publisher, bool autoCommit = false)
{
if (dbConnection.State == ConnectionState.Closed)
{
dbConnection.Open();
}

var dbTransaction = dbConnection.BeginTransaction();
return publisher.Transaction.Begin(dbTransaction, autoCommit);
}

public static IDbContextTransaction BeginTransaction(this DatabaseFacade database,
ICapPublisher publisher, bool autoCommit = false)
{
var trans = database.BeginTransaction();


+ 1
- 1
src/DotNetCore.CAP/ICapTransaction.Base.cs Прегледај датотеку

@@ -19,7 +19,7 @@ namespace DotNetCore.CAP

public object DbTransaction { get; set; }

protected internal void AddToSent(CapPublishedMessage msg)
protected internal virtual void AddToSent(CapPublishedMessage msg)
{
_bufferList.Add(msg);
}


+ 0
- 38
src/DotNetCore.CAP/Internal/RelationDbTransaction.cs Прегледај датотеку

@@ -1,38 +0,0 @@
// Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Data;

namespace DotNetCore.CAP.Internal
{
internal class RelationDbTransaction : IDbTransaction
{
private readonly ICapTransaction _capTransaction;

public RelationDbTransaction(ICapTransaction capTransaction)
{
_capTransaction = capTransaction;
var dbTransaction = (IDbTransaction) capTransaction.DbTransaction;
Connection = dbTransaction.Connection;
IsolationLevel = dbTransaction.IsolationLevel;
}

public void Dispose()
{
_capTransaction.Dispose();
}

public void Commit()
{
_capTransaction.Commit();
}

public void Rollback()
{
_capTransaction.Rollback();
}

public IDbConnection Connection { get; }
public IsolationLevel IsolationLevel { get; }
}
}

+ 0
- 40
src/DotNetCore.CAP/TransactionExtensions.cs Прегледај датотеку

@@ -1,40 +0,0 @@
// Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Data;
using DotNetCore.CAP.Internal;

namespace DotNetCore.CAP
{
public static class TransactionExtensions
{
public static ICapTransaction Begin(this ICapTransaction transaction,
IDbTransaction dbTransaction, bool autoCommit = false)
{

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

return transaction;
}

public static IDbTransaction JoinToTransaction(this IDbTransaction dbTransaction,
ICapPublisher publisher, bool autoCommit = false)
{
dbTransaction = new RelationDbTransaction(publisher.Transaction.Begin(dbTransaction, autoCommit));
return dbTransaction;
}

public static IDbTransaction BeginAndJoinToTransaction(this IDbConnection dbConnection,
ICapPublisher publisher, bool autoCommit = false)
{
if (dbConnection.State == ConnectionState.Closed)
{
dbConnection.Open();
}

var dbTransaction = dbConnection.BeginTransaction();
return dbTransaction.JoinToTransaction(publisher, autoCommit);
}
}
}

Loading…
Откажи
Сачувај