Skip to content

Commit

Permalink
1. optimized ITransaction Extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahoo-Wang committed Aug 23, 2018
1 parent b99d1d5 commit 76b98f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/SmartSql/SmartSql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<PackageProjectUrl>https://github.com/Ahoo-Wang/SmartSql</PackageProjectUrl>
<RepositoryUrl>https://github.com/Ahoo-Wang/SmartSql</RepositoryUrl>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
<Version>3.6.2</Version>
<Version>3.6.3</Version>
<PackageTags>orm sql read-write-separation cache redis dotnet-core cross-platform high-performance distributed-computing zookeeper</PackageTags>
<PackageReleaseNotes>
1. optimized code
</PackageReleaseNotes>
1. optimized ITransaction Extension
</PackageReleaseNotes>
<PackageIconUrl>https://raw.githubusercontent.com/Ahoo-Wang/SmartSql/master/SmartSql.png</PackageIconUrl>
<PackageLicenseUrl>https://raw.githubusercontent.com/Ahoo-Wang/SmartSql/master/LICENSE</PackageLicenseUrl>
</PropertyGroup>
Expand Down
32 changes: 16 additions & 16 deletions src/SmartSql/SmartSqlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,62 @@ namespace SmartSql
{
public static class SmartSqlExtensions
{
public static void TransactionWrap(this ISmartSqlMapper sqlMapper, Action handler)
public static void TransactionWrap(this ITransaction transaction, Action handler)
{
try
{
sqlMapper.BeginTransaction();
transaction.BeginTransaction();
handler();
sqlMapper.CommitTransaction();
transaction.CommitTransaction();
}
catch (Exception ex)
{
sqlMapper.RollbackTransaction();
transaction.RollbackTransaction();
throw ex;
}
}

public static void TransactionWrap(this ISmartSqlMapper sqlMapper, IsolationLevel isolationLevel, Action handler)
public static void TransactionWrap(this ITransaction transaction, IsolationLevel isolationLevel, Action handler)
{
try
{
sqlMapper.BeginTransaction(isolationLevel);
transaction.BeginTransaction(isolationLevel);
handler();
sqlMapper.CommitTransaction();
transaction.CommitTransaction();
}
catch (Exception ex)
{
sqlMapper.RollbackTransaction();
transaction.RollbackTransaction();
throw ex;
}
}

public async static Task TransactionWrapAsync(this ISmartSqlMapper sqlMapper, Func<Task> handler)
public async static Task TransactionWrapAsync(this ITransaction transaction, Func<Task> handler)
{
try
{
sqlMapper.BeginTransaction();
transaction.BeginTransaction();
await handler();
sqlMapper.CommitTransaction();
transaction.CommitTransaction();
}
catch (Exception ex)
{
sqlMapper.RollbackTransaction();
transaction.RollbackTransaction();
throw ex;
}
}

public async static Task TransactionWrapAsync(this ISmartSqlMapper sqlMapper, IsolationLevel isolationLevel, Func<Task> handler)
public async static Task TransactionWrapAsync(this ITransaction transaction, IsolationLevel isolationLevel, Func<Task> handler)
{
try
{
sqlMapper.BeginTransaction(isolationLevel);
transaction.BeginTransaction(isolationLevel);
await handler();
sqlMapper.CommitTransaction();
transaction.CommitTransaction();
}
catch (Exception ex)
{
sqlMapper.RollbackTransaction();
transaction.RollbackTransaction();
throw ex;
}
}
Expand Down

0 comments on commit 76b98f2

Please sign in to comment.