Skip to content

Commit

Permalink
add support CommandTimeout
Browse files Browse the repository at this point in the history
add support return DictionaryStringObject
  • Loading branch information
Ahoo-Wang committed Apr 28, 2019
1 parent 3ea23d0 commit 39bff0a
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build/version.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<VersionMajor>4</VersionMajor>
<VersionMinor>0</VersionMinor>
<VersionPatch>41</VersionPatch>
<VersionPatch>42</VersionPatch>
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion doc/Schema/SmartSql.Schema.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<metadata>
<id>SmartSql.Schema</id>
<title>SmartSql Schema for Intellisense(TM)</title>
<version>4.0.35</version>
<version>4.0.42</version>
<authors>Ahoo Wang</authors>
<owners>Ahoo Wang</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand Down
1 change: 1 addition & 0 deletions doc/Schema/SmartSqlMap.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@
<xs:attribute name="SourceChoice" type="DataSourceChoice" use="optional"/>
<xs:attribute name="Transaction" type="Transaction" use="optional"/>
<xs:attribute name="ReadDb" type="xs:string" use="optional"/>
<xs:attribute name="CommandTimeout" type="xs:int" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="Statements">
Expand Down
11 changes: 11 additions & 0 deletions src/SmartSql.Test.Performance/Query/QueryRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace SmartSql.Test.Performance.Query
{
public class QueryRequest
{
public int Taken { get; set; }
}
}
11 changes: 11 additions & 0 deletions src/SmartSql.Test.Unit/Deserializer/DynamicDeserializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ public void Query_Dynamic()
Assert.NotEqual(0, result.FirstOrDefault().Id);
}
[Fact]
public void Query_Dictionary()
{
var result = SqlMapper.Query<IDictionary<String,Object>>(new RequestContext
{
Scope = nameof(AllPrimitive),
SqlId = "Query",
Request = new { Taken = 10 }
});
Assert.NotEqual(0, result.FirstOrDefault()["Id"]);
}
[Fact]
public void Query_Dynamic_AsHashtable()
{
var result = SqlMapper.Query<dynamic>(new RequestContext
Expand Down
4 changes: 4 additions & 0 deletions src/SmartSql/Command/CommandExecuter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ private DbCommand CreateCmd(ExecutionContext executionContext)
dbCmd.CommandType = executionContext.Request.CommandType;
dbCmd.Transaction = dbSession.Transaction;
dbCmd.CommandText = executionContext.Request.RealSql;
if (executionContext.Request.CommandTimeout.HasValue)
{
dbCmd.CommandTimeout = executionContext.Request.CommandTimeout.Value;
}
foreach (var dbParam in executionContext.Request.Parameters.DbParameters.Values)
{
dbCmd.Parameters.Add(dbParam);
Expand Down
7 changes: 7 additions & 0 deletions src/SmartSql/ConfigBuilder/SqlMapBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ private void BuildStatement(XmlNode statementNode)
statementNode.Attributes.TryGetValueAsString("ParameterMap", out var parameterId, SmartSqlConfig.Properties);
statementNode.Attributes.TryGetValueAsString("ResultMap", out var resultMapId, SmartSqlConfig.Properties);
statementNode.Attributes.TryGetValueAsString("MultipleResultMap", out var multipleResultMapId, SmartSqlConfig.Properties);
int? commandTimeout=null;
if (statementNode.Attributes.TryGetValueAsInt32(nameof(Statement.CommandTimeout), out var cmdTimeout, SmartSqlConfig.Properties))
{
commandTimeout = cmdTimeout;
}

var statement = new Statement
{
Id = id,
Expand All @@ -387,6 +393,7 @@ private void BuildStatement(XmlNode statementNode)
CacheId = cacheId,
ParameterMapId = parameterId,
ResultMapId = resultMapId,
CommandTimeout = commandTimeout,
MultipleResultMapId = multipleResultMapId,
IncludeDependencies = new List<Include>()
};
Expand Down
1 change: 1 addition & 0 deletions src/SmartSql/Configuration/Statement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Statement
public DataSourceChoice? SourceChoice { get; set; }
public IsolationLevel? Transaction { get; set; }
public String ReadDb { get; set; }
public int? CommandTimeout { get; set; }
public String FullSqlId => $"{SqlMap.Scope}.{Id}";
public IList<ITag> SqlTags { get; set; }
#region Map
Expand Down
3 changes: 1 addition & 2 deletions src/SmartSql/Deserializer/DynamicDeserializer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using SmartSql.Data;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Threading.Tasks;
using SmartSql.Reflection.TypeConstants;
Expand All @@ -12,7 +11,7 @@ public class DynamicDeserializer : IDataReaderDeserializer
{
public bool CanDeserialize(ExecutionContext executionContext, Type resultType, bool isMultiple = false)
{
return resultType == CommonType.Object;
return resultType == CommonType.Object || resultType == CommonType.DictionaryStringObject;
}

public TResult ToSinge<TResult>(ExecutionContext executionContext)
Expand Down
1 change: 1 addition & 0 deletions src/SmartSql/Middlewares/InitializerMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private void InitByStatement(AbstractRequestContext requestContext, SqlMap sqlMa
requestContext.CommandType = requestContext.Statement.CommandType.Value;
}
requestContext.Transaction = requestContext.Transaction ?? requestContext.Statement.Transaction;
requestContext.CommandTimeout = requestContext.CommandTimeout ?? requestContext.Statement.CommandTimeout;
requestContext.ReadDb = requestContext.Statement.ReadDb;
requestContext.CacheId = requestContext.Statement.CacheId;
requestContext.Cache = requestContext.Statement.Cache;
Expand Down
3 changes: 2 additions & 1 deletion src/SmartSql/Reflection/TypeConstants/CommonType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public static class CommonType
public static readonly Type Task = typeof(Task);
public static readonly Type Void = typeof(void);
public static readonly Type ValueTuple = typeof(ValueTuple);

public static readonly Type DictionaryStringObject = typeof(IDictionary<String, object>);

public static bool IsValueTuple(Type type)
{
return type != null && type.ToString().StartsWith("System.ValueTuple");
Expand Down
2 changes: 0 additions & 2 deletions src/SmartSql/Reflection/TypeConstants/TypeHandlerCacheType.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using SmartSql.TypeHandlers;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace SmartSql.Reflection.TypeConstants
{
Expand Down
1 change: 1 addition & 0 deletions src/SmartSql/RequestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public abstract class AbstractRequestContext
public CommandType CommandType { get; set; } = CommandType.Text;
public IsolationLevel? Transaction { get; set; }
public String ReadDb { get; set; }
public int? CommandTimeout { get; set; }
public Statement Statement { get; internal set; }
public StringBuilder SqlBuilder { get; internal set; }
public bool IsStatementSql { get; internal set; } = true;
Expand Down

0 comments on commit 39bff0a

Please sign in to comment.