diff --git a/src/Susanoo.Core.Tests/Dynamic/DynamicTypeTest.cs b/src/Susanoo.Core.Tests/Dynamic/DynamicTypeTest.cs index 11dc248..cd06ea1 100644 --- a/src/Susanoo.Core.Tests/Dynamic/DynamicTypeTest.cs +++ b/src/Susanoo.Core.Tests/Dynamic/DynamicTypeTest.cs @@ -4,6 +4,7 @@ using System.Data; using System.Linq; using NUnit.Framework; +using Susanoo.Pipeline.Command.ResultSets.Processing.Deserialization; #endregion @@ -18,12 +19,15 @@ public class DynamicTypeTest [Test] public void DynamicRowPerformance() { - var results = CommandManager.DefineCommand("SELECT * FROM #DataTypeTable;", CommandType.Text) - .DefineResults() - .Realize("DynamicDataTypeTest") - .Execute(_databaseManager); - - Assert.IsNotNull(results); + for (int i = 0; i < 500; i ++) + { + var results = CommandManager.DefineCommand("SELECT * FROM #DataTypeTable;", CommandType.Text) + .DefineResults() + .Realize() + .Execute(_databaseManager); + + Assert.IsNotNull(results); + } } [Test(Description = "Tests that dynamic results correctly map data to CLR types.")] @@ -31,7 +35,7 @@ public void DynamicResultDataTypes() { var results = CommandManager.DefineCommand("SELECT * FROM #DataTypeTable;", CommandType.Text) .DefineResults() - .Realize("DynamicDataTypeTest") + .Realize() .Execute(_databaseManager); Assert.IsNotNull(results); diff --git a/src/Susanoo.Core.Tests/Static/MultipleResults/IdenticalResults.cs b/src/Susanoo.Core.Tests/Static/MultipleResults/IdenticalResults.cs index c6df181..7823281 100644 --- a/src/Susanoo.Core.Tests/Static/MultipleResults/IdenticalResults.cs +++ b/src/Susanoo.Core.Tests/Static/MultipleResults/IdenticalResults.cs @@ -231,7 +231,7 @@ public void IdenticalResults7Test() } [Test(Description = "Tests that attempting to get less results than available works fine.")] - public void LessResultsAreAvailableTest() + public void LessResultsThanAvailableTest() { var results = CommandManager.DefineCommand("SELECT * FROM #DataTypeTable;" + @@ -259,7 +259,7 @@ public void LessResultsAreAvailableTest() } [Test(Description = "Tests that attempting to get more results than available provides null for the additional results.")] - public void MoreResultsAreAvailableTest() + public void MoreResultsThanAvailableTest() { var results = CommandManager.DefineCommand("SELECT * FROM #DataTypeTable;" + diff --git a/src/Susanoo.Core.Tests/Static/SingleResult/StaticTypeTest.cs b/src/Susanoo.Core.Tests/Static/SingleResult/StaticTypeTest.cs index fec7702..0fe68c4 100644 --- a/src/Susanoo.Core.Tests/Static/SingleResult/StaticTypeTest.cs +++ b/src/Susanoo.Core.Tests/Static/SingleResult/StaticTypeTest.cs @@ -23,12 +23,15 @@ public class StaticTypeTest [Test] public void StaticRowPerformance() { - var results = CommandManager.DefineCommand("SELECT * FROM #DataTypeTable;", CommandType.Text) - .DefineResults() - .Realize("StaticDataTypeTest") - .Execute(_databaseManager); + for (int i = 0; i < 500; i ++) + { + var results = CommandManager.DefineCommand("SELECT * FROM #DataTypeTable;", CommandType.Text) + .DefineResults() + .Realize() + .Execute(_databaseManager); - Assert.IsNotNull(results); + Assert.IsNotNull(results); + } } @@ -37,7 +40,7 @@ public void StaticResultDataTypes() { var results = CommandManager.DefineCommand("SELECT * FROM #DataTypeTable;", CommandType.Text) .DefineResults() - .Realize("StaticDataTypeTest") + .Realize() .Execute(_databaseManager); Assert.IsNotNull(results); diff --git a/src/Susanoo.Core/Pipeline/Command/CommandExpression.cs b/src/Susanoo.Core/Pipeline/Command/CommandExpression.cs index ae40b6c..db183ed 100644 --- a/src/Susanoo.Core/Pipeline/Command/CommandExpression.cs +++ b/src/Susanoo.Core/Pipeline/Command/CommandExpression.cs @@ -452,19 +452,20 @@ public ICommandResultExpression private void ComputeHash() { - var hashText = new StringBuilder(CommandText); - - hashText.Append(DbCommandType); - hashText.Append(_explicitInclusionMode); - hashText.Append(_nullValueMode); - hashText.Append(_constantParameters.Aggregate(string.Empty, (p, c) => p + c.Key)); - hashText.Append(_parameterInclusions.Aggregate(string.Empty, (p, c) => p + c.Key)); - hashText.Append(_parameterExclusions.Aggregate(string.Empty, (p, c) => p + c)); - - //string resultBeforeHash = hashText.ToString(); - //BigInteger hashCode = HashBuilder.Compute(resultBeforeHash); + //This is faster than string builder and less resource intensive + var strings = + string.Concat(_constantParameters.Select(c => c.Key) + .Concat(_parameterInclusions.Select(c => c.Key)) + .Concat(_parameterExclusions) + .Concat(new [] + { + CommandText, + DbCommandType.ToString(), + _explicitInclusionMode.ToString(), + _nullValueMode.ToString() + })); - _cacheHash = HashBuilder.Compute(hashText.ToString()); + _cacheHash = HashBuilder.Compute(strings); } /// diff --git a/src/Susanoo.Core/Pipeline/Command/ResultSets/CommandResultExpression.cs b/src/Susanoo.Core/Pipeline/Command/ResultSets/CommandResultExpression.cs index edc3693..22fb8b7 100644 --- a/src/Susanoo.Core/Pipeline/Command/ResultSets/CommandResultExpression.cs +++ b/src/Susanoo.Core/Pipeline/Command/ResultSets/CommandResultExpression.cs @@ -121,7 +121,8 @@ internal CommandResultExpression(ICommandExpression command, /// The cache hash. public override BigInteger CacheHash { - get { return (base.CacheHash * 31) ^ typeof(TResult).AssemblyQualifiedName.GetHashCode(); } + get { return (base.CacheHash * 31) ^ typeof(TResult).AssemblyQualifiedName.GetHashCode() + ^ this.GetType().AssemblyQualifiedName.GetHashCode(); } } /// @@ -215,7 +216,8 @@ public override BigInteger CacheHash { return (base.CacheHash * 31) ^ typeof(TResult1).AssemblyQualifiedName.GetHashCode() - ^ typeof(TResult2).AssemblyQualifiedName.GetHashCode(); + ^ typeof(TResult2).AssemblyQualifiedName.GetHashCode() + ^ this.GetType().AssemblyQualifiedName.GetHashCode(); } } @@ -285,9 +287,10 @@ public override BigInteger CacheHash get { return (base.CacheHash * 31) - ^ HashBuilder.Compute(typeof(TResult1).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult2).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult3).AssemblyQualifiedName); + ^ typeof(TResult1).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult2).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult3).AssemblyQualifiedName.GetHashCode() + ^ this.GetType().AssemblyQualifiedName.GetHashCode(); } } @@ -359,10 +362,11 @@ public override BigInteger CacheHash get { return (base.CacheHash * 31) - ^ HashBuilder.Compute(typeof(TResult1).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult2).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult3).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult4).AssemblyQualifiedName); + ^ typeof(TResult1).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult2).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult3).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult4).AssemblyQualifiedName.GetHashCode() + ^ this.GetType().AssemblyQualifiedName.GetHashCode(); } } @@ -438,11 +442,12 @@ public override BigInteger CacheHash get { return (base.CacheHash * 31) - ^ HashBuilder.Compute(typeof(TResult1).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult2).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult3).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult4).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult5).AssemblyQualifiedName); + ^ typeof(TResult1).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult2).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult3).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult4).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult5).AssemblyQualifiedName.GetHashCode() + ^ this.GetType().AssemblyQualifiedName.GetHashCode(); } } @@ -524,12 +529,13 @@ public override BigInteger CacheHash get { return (base.CacheHash * 31) - ^ HashBuilder.Compute(typeof(TResult1).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult2).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult3).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult4).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult5).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult6).AssemblyQualifiedName); + ^ typeof(TResult1).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult2).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult3).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult4).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult5).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult6).AssemblyQualifiedName.GetHashCode() + ^ this.GetType().AssemblyQualifiedName.GetHashCode(); } } @@ -617,13 +623,14 @@ public override BigInteger CacheHash get { return (base.CacheHash * 31) - ^ HashBuilder.Compute(typeof(TResult1).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult2).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult3).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult4).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult5).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult6).AssemblyQualifiedName) - ^ HashBuilder.Compute(typeof(TResult7).AssemblyQualifiedName); + ^ typeof(TResult1).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult2).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult3).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult4).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult5).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult6).AssemblyQualifiedName.GetHashCode() + ^ typeof(TResult7).AssemblyQualifiedName.GetHashCode() + ^ this.GetType().AssemblyQualifiedName.GetHashCode(); } } diff --git a/src/Susanoo.Core/Pipeline/Command/ResultSets/CommandResultImplementor.cs b/src/Susanoo.Core/Pipeline/Command/ResultSets/CommandResultImplementor.cs index c6ced8f..3c7e37e 100644 --- a/src/Susanoo.Core/Pipeline/Command/ResultSets/CommandResultImplementor.cs +++ b/src/Susanoo.Core/Pipeline/Command/ResultSets/CommandResultImplementor.cs @@ -18,13 +18,14 @@ namespace Susanoo.Pipeline.Command.ResultSets public class CommandResultImplementor : ICommandResultImplementor { private readonly IDictionary _mappingContainer; - + private readonly IDictionary _mappingContainerRuntime; /// /// Initializes a new instance of the class. /// public CommandResultImplementor() { _mappingContainer = new Dictionary(); + _mappingContainerRuntime = new Dictionary(); } /// @@ -33,7 +34,11 @@ public CommandResultImplementor() /// The cache hash. public BigInteger CacheHash { - get { return _mappingContainer.Aggregate(default(BigInteger), (p, c) => (p * 31) ^ c.Value.CacheHash); } + get + { + return _mappingContainer.Aggregate(default(BigInteger), + (p, c) => ((p * 31) ^ c.Value.CacheHash)); + } } /// @@ -48,11 +53,14 @@ public IResultMappingExport RetrieveExporter(Type resultType) IResultMappingExport value; if (!_mappingContainer.TryGetValue(resultType, out value)) { - result = new DefaultResultMapping(resultType); - _mappingContainer.Add(resultType, result); + if (!_mappingContainerRuntime.TryGetValue(resultType, out value)) + { + result = new DefaultResultMapping(resultType); + _mappingContainerRuntime.Add(resultType, result); + } } - return result; + return result ?? value; } /// diff --git a/src/Susanoo.Core/Pipeline/Command/ResultSets/Mapping/DefaultResultMapping.cs b/src/Susanoo.Core/Pipeline/Command/ResultSets/Mapping/DefaultResultMapping.cs index cfe2a5c..91c835e 100644 --- a/src/Susanoo.Core/Pipeline/Command/ResultSets/Mapping/DefaultResultMapping.cs +++ b/src/Susanoo.Core/Pipeline/Command/ResultSets/Mapping/DefaultResultMapping.cs @@ -49,7 +49,7 @@ public void MapDeclarativeProperties() /// The cache hash. public BigInteger CacheHash { - get { return _mappingActions.Aggregate(HashBuilder.Seed, (i, pair) => (i * 31) ^ pair.Value.CacheHash); } + get { return -1; } } /// diff --git a/src/Susanoo.Core/Pipeline/Command/ResultSets/Processing/Deserialization/BuiltInTypeDeserializer.cs b/src/Susanoo.Core/Pipeline/Command/ResultSets/Processing/Deserialization/BuiltInTypeDeserializer.cs index 8d94aff..4c564b4 100644 --- a/src/Susanoo.Core/Pipeline/Command/ResultSets/Processing/Deserialization/BuiltInTypeDeserializer.cs +++ b/src/Susanoo.Core/Pipeline/Command/ResultSets/Processing/Deserialization/BuiltInTypeDeserializer.cs @@ -17,7 +17,7 @@ public static class BuiltInTypeDeserializer /// dynamic. public static IEnumerable Deserialize(IDataReader reader, ColumnChecker checker) { - var resultSet = new List(); + var resultSet = new ListResult(); var fieldCount = reader.FieldCount; if (fieldCount > 0) @@ -25,11 +25,11 @@ public static IEnumerable Deserialize(IDataReader reader, Colu while (reader.Read()) { - resultSet.Add(reader.GetValue(0)); + resultSet.Add((TResult)reader.GetValue(0)); } } - return resultSet.Cast(); + return resultSet; } } } \ No newline at end of file diff --git a/src/Susanoo.Core/Pipeline/Command/ResultSets/Processing/Deserialization/ComplexTypeDeserializer.cs b/src/Susanoo.Core/Pipeline/Command/ResultSets/Processing/Deserialization/ComplexTypeDeserializer.cs index 3a11414..9ce6607 100644 --- a/src/Susanoo.Core/Pipeline/Command/ResultSets/Processing/Deserialization/ComplexTypeDeserializer.cs +++ b/src/Susanoo.Core/Pipeline/Command/ResultSets/Processing/Deserialization/ComplexTypeDeserializer.cs @@ -167,7 +167,10 @@ public static Func> Compile (IEnumerable)(result(reader, columnMeta)); + Func> typedResult = + (reader, columnMeta) => (IEnumerable)(result.Invoke(reader, columnMeta)); + + return typedResult; } } } \ No newline at end of file diff --git a/src/Susanoo.Core/Pipeline/Command/ResultSets/Processing/Deserialization/DynamicRow.cs b/src/Susanoo.Core/Pipeline/Command/ResultSets/Processing/Deserialization/DynamicRow.cs index 47384b9..a7c0a50 100644 --- a/src/Susanoo.Core/Pipeline/Command/ResultSets/Processing/Deserialization/DynamicRow.cs +++ b/src/Susanoo.Core/Pipeline/Command/ResultSets/Processing/Deserialization/DynamicRow.cs @@ -25,6 +25,15 @@ public DynamicRow(ColumnChecker columns) _values = new object[_columns.Count]; } + /// + /// Initializes a new instance of the class. + /// + public DynamicRow() + { + _columns = new ColumnChecker(); + _values = new object[_columns.Count]; + } + /// /// Initializes a new instance of the class. /// diff --git a/src/Susanoo.Core/Pipeline/Command/ResultSets/Processing/Deserialization/DynamicRowDeserializer.cs b/src/Susanoo.Core/Pipeline/Command/ResultSets/Processing/Deserialization/DynamicRowDeserializer.cs index 8cc4d79..1f44c34 100644 --- a/src/Susanoo.Core/Pipeline/Command/ResultSets/Processing/Deserialization/DynamicRowDeserializer.cs +++ b/src/Susanoo.Core/Pipeline/Command/ResultSets/Processing/Deserialization/DynamicRowDeserializer.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System.Collections; +using System.Collections.Generic; using System.Data; namespace Susanoo.Pipeline.Command.ResultSets.Processing.Deserialization @@ -16,7 +17,9 @@ public static class DynamicRowDeserializer /// dynamic. public static IEnumerable Deserialize(IDataReader reader, ColumnChecker checker) { - var resultSet = new ListResult(); + IList resultSet = new ListResult(); + + checker = checker ?? new ColumnChecker(); var fieldCount = reader.FieldCount; @@ -46,9 +49,9 @@ public static IEnumerable Deserialize(IDataReader reader, Colu resultSet.Add(new DynamicRow(checker, values)); } - resultSet.BuildReport(checker); + ((ListResult)resultSet).BuildReport(checker); - return resultSet as IEnumerable; + return (IEnumerable) resultSet; } } } \ No newline at end of file