From 54ab38569b826a3a6decf4af30955ccada200468 Mon Sep 17 00:00:00 2001 From: markpollack Date: Sat, 9 Jul 2011 17:11:12 +0000 Subject: [PATCH] SPRNET-1408 - Add data providers in System.Data.dll to be accessed via Spring's IDbProvider interface. --- .../Spring.Data/Data/Common/dbproviders.xml | 108 ++++++++++++++ src/Spring/Spring.Data/Data/IAdoOperations.cs | 135 ++++++++++++++---- .../Spring.Core.Tests.2008.csproj | 8 -- .../Data/Common/DbProviderFactoryTests.cs | 41 +++++- 4 files changed, 251 insertions(+), 41 deletions(-) diff --git a/src/Spring/Spring.Data/Data/Common/dbproviders.xml b/src/Spring/Spring.Data/Data/Common/dbproviders.xml index cb8da207..71b0daec 100644 --- a/src/Spring/Spring.Data/Data/Common/dbproviders.xml +++ b/src/Spring/Spring.Data/Data/Common/dbproviders.xml @@ -87,6 +87,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + 156,170,207,208 + + + 229 + + + 544,2627,8114,8115 + + + 1205 + + + + + + @@ -257,6 +298,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + 156,170,207,208 + + + 229 + + + 2627,8114,8115 + + + 1205 + + + + + + @@ -1898,6 +1981,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Spring/Spring.Data/Data/IAdoOperations.cs b/src/Spring/Spring.Data/Data/IAdoOperations.cs index 46205db8..91fcb4eb 100644 --- a/src/Spring/Spring.Data/Data/IAdoOperations.cs +++ b/src/Spring/Spring.Data/Data/IAdoOperations.cs @@ -96,17 +96,15 @@ namespace Spring.Data object QueryWithResultSetExtractor(CommandType cmdType, string cmdText, IResultSetExtractor resultSetExtractor); - // Parameterized Queries - - - //only input parameters can be used... + // Parameterized Queries + // Only input parameters can be used... /// - /// Execute a query given IDbCommand's type and text with parameters set + /// Execute a query given the CommandType and text with parameters set /// via the command setter, processing a /// single result set with an instance of IResultSetExtractor - /// + /// /// The command type. /// The command text to execute. /// The result set extractor. @@ -114,16 +112,43 @@ namespace Spring.Data /// An arbitrary result object, as returned by the IResultSetExtractor /// /// If there is any problem executing the query. - /// + /// object QueryWithResultSetExtractor(CommandType cmdType, string cmdText, IResultSetExtractor resultSetExtractor, ICommandSetter commandSetter); - //only input parameters can be used. - object QueryWithResultSetExtractor(CommandType commandType, string cmdText, IResultSetExtractor resultSetExtractor, - string parameterName, Enum dbType, int size, object parameterValue); - - //iterate over one or more result sets and then assign output parameters. - object QueryWithResultSetExtractor(CommandType commandType, string cmdText, IResultSetExtractor resultSetExtractor, + /// + /// Execute a query given the CommandType and text specifying a single parameter and process a single result set with an + /// instance of IResultSetExtractor. + /// + /// Convention is to use 0 For the size if it does not make sense for the given data type + /// + /// The command type. + /// The command text to execute. + /// The result set extractor. + /// The name of the parameters + /// The enumeration of the parameter type + /// The size of the parmeter - e.g. string length. Use 0 if not relevant for specific data type + /// The value of the parameters + /// An arbitrary result object, as returned by the IResultSetExtractor + /// + /// If there is any problem executing the query. + /// + object QueryWithResultSetExtractor(CommandType cmdType, string cmdText, IResultSetExtractor resultSetExtractor, + string parameterName, Enum dbType, int size, object parameterValue); + + /// + /// Execute a query given the CommandType and text specifying a collection of parameters and process a single result set with an + /// instance of IResultSetExtractor. + /// + /// The command type. + /// The command text to execute. + /// The result set extractor. + /// The query parameters + /// An arbitrary result object, as returned by the IResultSetExtractor + /// + /// If there is any problem executing the query. + /// + object QueryWithResultSetExtractor(CommandType cmdType, string cmdText, IResultSetExtractor resultSetExtractor, IDbParameters parameters); @@ -138,8 +163,8 @@ namespace Spring.Data /// and process a single result set with an instance of ResultSetExtractorDelegate /// /// The type of command. - /// The command text. - /// Delegate that will extract all rows of a result set + /// The command text. + /// Delegate that will process all rows of a result set /// An arbitrary result object, as returned by the IResultSetExtractor /// /// If there is any problem executing the query. @@ -148,25 +173,73 @@ namespace Spring.Data // Parameterized Queries - - - //only input parameters can be used... - object QueryWithResultSetExtractorDelegate(CommandType commandType, string sql, ResultSetExtractorDelegate resultSetExtractorDelegate, - ICommandSetter commandSetter); - - //only input parameters can be used. - object QueryWithResultSetExtractorDelegate(CommandType commandType, string sql, ResultSetExtractorDelegate resultSetExtractorDelegate, - string parameterName, Enum dbType, int size, object parameterValue); - - //iterate over one or more result sets and then assign output parameters. - object QueryWithResultSetExtractorDelegate(CommandType commandType, string sql, ResultSetExtractorDelegate resultSetExtractorDelegate, - IDbParameters parameter); + // only input parameters can be used... + + /// + /// Execute a query given the CommandType and text with parameters set + /// via the command setter, processing a + /// single result set with an instance of IResultSetExtractor + /// + /// The command type. + /// The command text to execute. + /// Delegate that will process all rows of a result set + /// The command setter. + /// An arbitrary result object, as returned by the IResultSetExtractor + /// + /// If there is any problem executing the query. + /// + object QueryWithResultSetExtractorDelegate(CommandType cmdType, string cmdText, ResultSetExtractorDelegate resultSetExtractorDelegate, + ICommandSetter commandSetter); + + + /// + /// Execute a query given the CommandType and text specifying a single parameter and process a single result set with an + /// instance of IResultSetExtractor. + /// + /// Convention is to use 0 For the size if it does not make sense for the given data type + /// + /// The command type. + /// The command text to execute. + /// Delegate that will process all rows of a result set + /// The name of the parameters + /// The enumeration of the parameter type + /// The size of the parmeter - e.g. string length. Use 0 if not relevant for specific data type + /// The value of the parameters + /// An arbitrary result object, as returned by the IResultSetExtractor + /// + /// If there is any problem executing the query. + /// + object QueryWithResultSetExtractorDelegate(CommandType cmdType, string cmdText, ResultSetExtractorDelegate resultSetExtractorDelegate, + string parameterName, Enum dbType, int size, object parameterValue); + + /// + /// Execute a query given the CommandType and text specifying a collection of parameters and process a single result set with an + /// instance of IResultSetExtractor. + /// + /// The command type. + /// The command text to execute. + /// Delegate that will process all rows of a result set + /// The query parameters + /// An arbitrary result object, as returned by the IResultSetExtractor + /// + /// If there is any problem executing the query. + /// + object QueryWithResultSetExtractorDelegate(CommandType cmdType, string cmdText, ResultSetExtractorDelegate resultSetExtractorDelegate, + IDbParameters parameters); #endregion - #region Queries with RowMapperDelegate - + #region Queries with RowMapperDelegate + + /// + /// Execute a query given static SQL, mapping each row to a .NET object + /// via a RowMapper + /// + /// The type of command + /// SQL query to execute + /// delegate/lambda that will map one object per row + /// The result list containing mapped objects IList QueryWithRowMapperDelegate(CommandType cmdType, string cmdText, RowMapperDelegate rowMapperDelgate); IList QueryWithRowMapperDelegate(CommandType cmdType, string cmdText, RowMapperDelegate rowMapperDelgate, ICommandSetter commandSetter); @@ -186,7 +259,7 @@ namespace Spring.Data /// /// Execute a query given static SQL, mapping each row to a .NET object - /// iva a RowMapper + /// via a RowMapper /// /// The type of command /// SQL query to execute diff --git a/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj b/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj index d3676146..1a9aadd6 100644 --- a/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj +++ b/test/Spring/Spring.Core.Tests/Spring.Core.Tests.2008.csproj @@ -925,14 +925,6 @@ {AEB1578C-9018-4D49-B440-789F38DD2F29} Spring.Messaging.Nms.2008 - - {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - Spring.Services.2008 - - - {BF3AB954-8375-407C-9E98-4C51D8072784} - Spring.Template.Velocity.2008 - diff --git a/test/Spring/Spring.Data.Tests/Data/Common/DbProviderFactoryTests.cs b/test/Spring/Spring.Data.Tests/Data/Common/DbProviderFactoryTests.cs index a0188c56..4d6ba88a 100644 --- a/test/Spring/Spring.Data.Tests/Data/Common/DbProviderFactoryTests.cs +++ b/test/Spring/Spring.Data.Tests/Data/Common/DbProviderFactoryTests.cs @@ -109,7 +109,7 @@ namespace Spring.Data.Common } [Test] - public void DefaultInstanceWithSqlServer2005() + public void DefaultInstanceWithSqlServer20() { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", false); //IApplicationContext ctx = DbProviderFactory.ApplicationContext; @@ -155,7 +155,37 @@ namespace Spring.Data.Common Assert.AreEqual(":Foo", provider.CreateParameterName("Foo")); } #endif + +#if NET_4_0 + [Test] + public void DefaultInstanceWithSqlServer40() + { + IDbProvider provider = DbProviderFactory.GetDbProvider("SqlServer-4.0"); + AssertIsSqlServer40(provider); + Assert.IsNull(provider.ConnectionString); + Assert.IsNotNull(provider.CreateCommand()); + Assert.IsNotNull(provider.CreateCommandBuilder()); + Assert.IsNotNull(provider.CreateConnection()); + Assert.IsNotNull(provider.CreateDataAdapter()); + Assert.IsNotNull(provider.CreateParameter()); + Assert.AreEqual("@Foo", provider.CreateParameterName("Foo")); + } + + [Test] + public void DefaultInstanceWithOleDb40() + { + IDbProvider provider = DbProviderFactory.GetDbProvider("OleDb-4.0"); + Assert.AreEqual("OleDb, provider V4.0.0.0 in framework .NET V4", provider.DbMetadata.ProductName); + Assert.IsNotNull(provider.CreateCommand()); + Assert.IsNotNull(provider.CreateCommandBuilder()); + Assert.IsNotNull(provider.CreateConnection()); + Assert.IsNotNull(provider.CreateDataAdapter()); + Assert.IsNotNull(provider.CreateParameter()); + Assert.AreEqual("?", provider.CreateParameterName("Foo")); + } +#endif + //[Test] //Comment in for specific testing with oracle as can't put oracle client in public code repository public void DefaultInstanceWithOracleClient20() @@ -185,7 +215,7 @@ namespace Spring.Data.Common */ [Test] - public void TestDb2() + public void TestSqlServer20Names() { //Initialize internal application context. factory DbProviderFactory.GetDbProvider("SqlServer-2.0"); @@ -239,6 +269,13 @@ namespace Spring.Data.Common AssertCommonSqlServerErrorCodes(provider); } + private void AssertIsSqlServer40(IDbProvider provider) + { + Assert.AreEqual("Microsoft SQL Server, provider V4.0.0.0 in framework .NET V4.0", + provider.DbMetadata.ProductName); + AssertCommonSqlServerErrorCodes(provider); + } + private static void AssertCommonSqlServerErrorCodes(IDbProvider provider) { ErrorCodes codes = provider.DbMetadata.ErrorCodes;