Skip to content

Commit

Permalink
add support DyRepository.UseTransactionAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahoo-Wang committed Apr 18, 2019
1 parent d840e36 commit d83467b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/SmartSql.DyRepository/EmitRepositoryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ private static void EmitSetTransaction(ILGenerator ilGen, MethodInfo methodInfo)
{
ilGen.LoadLocalVar(0);
ilGen.LoadInt32(useTransactionAttribute.Level.GetHashCode());
ilGen.New(NullableType<IsolationLevel>.Ctor);
ilGen.Callvirt(RequestContextType.Method.SetTransaction);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/SmartSql/Reflection/TypeConstants/DataType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System;
using System.Collections;
using System.Data;
using System.Reflection;

namespace SmartSql.Reflection.TypeConstants
{
Expand Down
16 changes: 16 additions & 0 deletions src/SmartSql/Reflection/TypeConstants/NullableType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace SmartSql.Reflection.TypeConstants
{
public static class NullableType<TTarget> where TTarget : struct
{
public static Type TargetType = typeof(TTarget);
public static readonly Type Type = typeof(TTarget?);

public static readonly ConstructorInfo Ctor = Type.GetConstructor(new Type[] { TargetType });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static class Method
{
public static readonly MethodInfo SetDataSourceChoice = AbstractType.GetMethod("set_DataSourceChoice");
public static readonly MethodInfo SetCommandType = AbstractType.GetMethod("set_CommandType");
public static readonly MethodInfo SetTransaction = AbstractType.GetMethod("SetTransaction");
public static readonly MethodInfo SetTransaction = AbstractType.GetMethod("set_Transaction");
public static readonly MethodInfo SetScope = AbstractType.GetMethod("set_Scope");
public static readonly MethodInfo SetSqlId = AbstractType.GetMethod("set_SqlId");
public static readonly MethodInfo SetRequest = AbstractType.GetMethod("SetRequest");
Expand Down
5 changes: 0 additions & 5 deletions src/SmartSql/RequestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ public ResultMap GetCurrentResultMap()
MultipleResultMap.Results[ExecutionContext.DataReaderWrapper.ResultIndex]?.Map : ResultMap;
}

public void SetTransaction(IsolationLevel isolationLevel)
{
Transaction = isolationLevel;
}

public abstract void SetupParameters();
public abstract void SetRequest(object requestObj);
}
Expand Down

0 comments on commit d83467b

Please sign in to comment.