SPRNET-1408 - Add data providers in System.Data.dll to be accessed via Spring's IDbProvider interface.

This commit is contained in:
markpollack
2011-07-09 17:11:12 +00:00
parent 795d8e1c6d
commit 54ab38569b
4 changed files with 251 additions and 41 deletions

View File

@@ -87,6 +87,47 @@
</object>
<object id="SqlServer-4.0" type="Spring.Data.Common.DbProvider, Spring.Data" singleton="false">
<constructor-arg name="dbMetaData">
<object type="Spring.Data.Common.DbMetadata">
<constructor-arg name="productName" value="Microsoft SQL Server, provider V4.0.0.0 in framework .NET V4.0" />
<constructor-arg name="assemblyName" value="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<constructor-arg name="connectionType" value="System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<constructor-arg name="commandType" value="System.Data.SqlClient.SqlCommand, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<constructor-arg name="parameterType" value="System.Data.SqlClient.SqlParameter, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<constructor-arg name="dataAdapterType" value="System.Data.SqlClient.SqlDataAdapter, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<constructor-arg name="commandBuilderType" value="System.Data.SqlClient.SqlCommandBuilder, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<constructor-arg name="commandBuilderDeriveParametersMethod" value="DeriveParameters"/>
<constructor-arg name="parameterDbType" value="System.Data.SqlDbType, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<constructor-arg name="parameterDbTypeProperty" value="SqlDbType"/>
<constructor-arg name="parameterIsNullableProperty" value="IsNullable"/>
<constructor-arg name="parameterNamePrefix" value="@"/>
<constructor-arg name="exceptionType" value="System.Data.SqlClient.SqlException, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<constructor-arg name="useParameterNamePrefixInParameterCollection" value="true"/>
<constructor-arg name="useParameterPrefixInSql" value="true"/>
<constructor-arg name="bindByName" value="true"/>
<!-- this is only true for .net 1.1 kept it here just in case we want to revert back to this strategy for
obtaining error codes-->
<constructor-arg name="errorCodeExceptionExpression" value="Errors[0].Number.ToString()"/>
<!-- TODO select form system db all errors that have 'incorrect syntax' at the start of the error string-->
<property name="ErrorCodes.BadSqlGrammarCodes">
<value>156,170,207,208</value>
</property>
<property name="ErrorCodes.PermissionDeniedCodes">
<value>229</value>
</property>
<property name="ErrorCodes.DataIntegrityViolationCodes">
<value>544,2627,8114,8115</value>
</property>
<property name="ErrorCodes.DeadlockLoserCodes">
<value>1205</value>
</property>
</object>
</constructor-arg>
</object>
<alias name="SqlServer-2.0" alias="System.Data.SqlClient"/>
@@ -257,6 +298,48 @@
</object>
<object id="OleDb-4.0" type="Spring.Data.Common.DbProvider, Spring.Data" singleton="false">
<constructor-arg name="dbMetaData">
<object type="Spring.Data.Common.DbMetadata">
<constructor-arg name="productName" value="OleDb, provider V4.0.0.0 in framework .NET V4"/>
<constructor-arg name="assemblyName" value="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<constructor-arg name="connectionType" value="System.Data.OleDb.OleDbConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<constructor-arg name="commandType" value="System.Data.OleDb.OleDbCommand, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<constructor-arg name="parameterType" value="System.Data.OleDb.OleDbParameter, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<constructor-arg name="dataAdapterType" value="System.Data.OleDb.OleDbDataAdapter, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<constructor-arg name="commandBuilderType" value="System.Data.OleDb.OleDbCommandBuilder, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<constructor-arg name="commandBuilderDeriveParametersMethod" value="DeriveParameters"/>
<constructor-arg name="parameterDbType" value="System.Data.OleDb.OleDbType, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<constructor-arg name="parameterDbTypeProperty" value="OleDbType"/>
<constructor-arg name="parameterIsNullableProperty" value="IsNullable"/>
<constructor-arg name="parameterNamePrefix" value="?"/>
<constructor-arg name="exceptionType" value="System.Data.OleDb.OleDbException, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<constructor-arg name="useParameterNamePrefixInParameterCollection" value="false"/>
<constructor-arg name="useParameterPrefixInSql" value="false"/>
<constructor-arg name="bindByName" value="false"/>
<!-- TODO should parse out high/low values in the native error...yuk!-->
<constructor-arg name="errorCodeExceptionExpression" value="Errors[0].NativeError.ToString()"/>
<!-- TODO where is the definitive list of the error. Anyway, until parse out high low error there isn't any
exception mapping yet for this provider.
-->
<property name="ErrorCodes.BadSqlGrammarCodes">
<value>156,170,207,208</value>
</property>
<property name="ErrorCodes.PermissionDeniedCodes">
<value>229</value>
</property>
<property name="ErrorCodes.DataIntegrityViolationCodes">
<value>2627,8114,8115</value>
</property>
<property name="ErrorCodes.DeadlockLoserCodes">
<value>1205</value>
</property>
</object>
</constructor-arg>
</object>
<alias name="OleDb-2.0" alias="System.Data.OleDb"/>
@@ -1898,6 +1981,31 @@
</object>
<object id="Odbc-4.0" type="Spring.Data.Common.DbProvider, Spring.Data" singleton="false">
<constructor-arg name="dbMetaData">
<object type="Spring.Data.Common.DbMetadata">
<constructor-arg name="productName" value="Microsoft ODBC, provider V4.0.0.0 in framework .NET V4"/>
<constructor-arg name="assemblyName" value="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<constructor-arg name="connectionType" value="System.Data.Odbc.OdbcConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<constructor-arg name="commandType" value="System.Data.Odbc.OdbcCommand, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<constructor-arg name="parameterType" value="System.Data.Odbc.OdbcParameter, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<constructor-arg name="dataAdapterType" value="System.Data.Odbc.OdbcDataAdapter, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<constructor-arg name="commandBuilderType" value="System.Data.Odbc.OdbcCommandBuilder, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<constructor-arg name="commandBuilderDeriveParametersMethod" value="DeriveParameters"/>
<constructor-arg name="parameterDbType" value="System.Data.Odbc.OdbcType, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<constructor-arg name="parameterDbTypeProperty" value="OdbcType"/>
<constructor-arg name="parameterIsNullableProperty" value="IsNullable"/>
<constructor-arg name="parameterNamePrefix" value="?"/>
<constructor-arg name="exceptionType" value="System.Data.Odbc.OdbcException, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<constructor-arg name="useParameterNamePrefixInParameterCollection" value="false"/>
<constructor-arg name="useParameterPrefixInSql" value="false"/>
<constructor-arg name="bindByName" value="false"/>
<constructor-arg name="errorCodeExceptionExpression" value="Errors[0].NativeError.ToString()"/>
</object>
</constructor-arg>
</object>
<alias name="Odbc-2.0" alias="System.Data.Odbc"/>
<object id="Cache-2.0.0.1" type="Spring.Data.Common.DbProvider, Spring.Data" singleton="false">

View File

@@ -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...
/// <summary>
/// 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
/// </summary>
/// </summary>
/// <param name="cmdType">The command type.</param>
/// <param name="cmdText">The command text to execute.</param>
/// <param name="resultSetExtractor">The result set extractor.</param>
@@ -114,16 +112,43 @@ namespace Spring.Data
/// <returns>An arbitrary result object, as returned by the IResultSetExtractor</returns>
/// <exception cref="Spring.Dao.DataAccessException">
/// If there is any problem executing the query.
/// </exception>
/// </exception>
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,
/// <summary>
/// Execute a query given the CommandType and text specifying a single parameter and process a single result set with an
/// instance of IResultSetExtractor.
/// </summary>
/// <remarks>Convention is to use 0 For the size if it does not make sense for the given data type
/// </remarks>
/// <param name="cmdType">The command type.</param>
/// <param name="cmdText">The command text to execute.</param>
/// <param name="resultSetExtractor">The result set extractor.</param>
/// <param name="parameterName">The name of the parameters</param>
/// <param name="dbType">The enumeration of the parameter type </param>
/// <param name="size">The size of the parmeter - e.g. string length. Use 0 if not relevant for specific data type</param>
/// <param name="parameterValue">The value of the parameters</param>
/// <returns>An arbitrary result object, as returned by the IResultSetExtractor</returns>
/// <exception cref="Spring.Dao.DataAccessException">
/// If there is any problem executing the query.
/// </exception>
object QueryWithResultSetExtractor(CommandType cmdType, string cmdText, IResultSetExtractor resultSetExtractor,
string parameterName, Enum dbType, int size, object parameterValue);
/// <summary>
/// Execute a query given the CommandType and text specifying a collection of parameters and process a single result set with an
/// instance of IResultSetExtractor.
/// </summary>
/// <param name="cmdType">The command type.</param>
/// <param name="cmdText">The command text to execute.</param>
/// <param name="resultSetExtractor">The result set extractor.</param>
/// <param name="parameters">The query parameters</param>
/// <returns>An arbitrary result object, as returned by the IResultSetExtractor</returns>
/// <exception cref="Spring.Dao.DataAccessException">
/// If there is any problem executing the query.
/// </exception>
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
/// </summary>
/// <param name="cmdType">The type of command.</param>
/// <param name="cmdText">The command text.</param>
/// <param name="resultSetExtractorDelegate">Delegate that will extract all rows of a result set</param>
/// <param name="cmdText">The command text.</param>
/// <param name="resultSetExtractorDelegate">Delegate that will process all rows of a result set</param>
/// <returns>An arbitrary result object, as returned by the IResultSetExtractor</returns>
/// <exception cref="Spring.Dao.DataAccessException">
/// 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...
/// <summary>
/// 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
/// </summary>
/// <param name="cmdType">The command type.</param>
/// <param name="cmdText">The command text to execute.</param>
/// <param name="resultSetExtractorDelegate">Delegate that will process all rows of a result set</param>
/// <param name="commandSetter">The command setter.</param>
/// <returns>An arbitrary result object, as returned by the IResultSetExtractor</returns>
/// <exception cref="Spring.Dao.DataAccessException">
/// If there is any problem executing the query.
/// </exception>
object QueryWithResultSetExtractorDelegate(CommandType cmdType, string cmdText, ResultSetExtractorDelegate resultSetExtractorDelegate,
ICommandSetter commandSetter);
/// <summary>
/// Execute a query given the CommandType and text specifying a single parameter and process a single result set with an
/// instance of IResultSetExtractor.
/// </summary>
/// <remarks>Convention is to use 0 For the size if it does not make sense for the given data type
/// </remarks>
/// <param name="cmdType">The command type.</param>
/// <param name="cmdText">The command text to execute.</param>
/// <param name="resultSetExtractorDelegate">Delegate that will process all rows of a result set</param>
/// <param name="parameterName">The name of the parameters</param>
/// <param name="dbType">The enumeration of the parameter type </param>
/// <param name="size">The size of the parmeter - e.g. string length. Use 0 if not relevant for specific data type</param>
/// <param name="parameterValue">The value of the parameters</param>
/// <returns>An arbitrary result object, as returned by the IResultSetExtractor</returns>
/// <exception cref="Spring.Dao.DataAccessException">
/// If there is any problem executing the query.
/// </exception>
object QueryWithResultSetExtractorDelegate(CommandType cmdType, string cmdText, ResultSetExtractorDelegate resultSetExtractorDelegate,
string parameterName, Enum dbType, int size, object parameterValue);
/// <summary>
/// Execute a query given the CommandType and text specifying a collection of parameters and process a single result set with an
/// instance of IResultSetExtractor.
/// </summary>
/// <param name="cmdType">The command type.</param>
/// <param name="cmdText">The command text to execute.</param>
/// <param name="resultSetExtractorDelegate">Delegate that will process all rows of a result set</param>
/// <param name="parameters">The query parameters</param>
/// <returns>An arbitrary result object, as returned by the IResultSetExtractor</returns>
/// <exception cref="Spring.Dao.DataAccessException">
/// If there is any problem executing the query.
/// </exception>
object QueryWithResultSetExtractorDelegate(CommandType cmdType, string cmdText, ResultSetExtractorDelegate resultSetExtractorDelegate,
IDbParameters parameters);
#endregion
#region Queries with RowMapperDelegate
#region Queries with RowMapperDelegate
/// <summary>
/// Execute a query given static SQL, mapping each row to a .NET object
/// via a RowMapper
/// </summary>
/// <param name="cmdType">The type of command</param>
/// <param name="cmdText">SQL query to execute</param>
/// <param name="rowMapperDelgate">delegate/lambda that will map one object per row</param>
/// <returns>The result list containing mapped objects</returns>
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
/// <summary>
/// Execute a query given static SQL, mapping each row to a .NET object
/// iva a RowMapper
/// via a RowMapper
/// </summary>
/// <param name="cmdType">The type of command</param>
/// <param name="cmdText">SQL query to execute</param>

View File

@@ -925,14 +925,6 @@
<Project>{AEB1578C-9018-4D49-B440-789F38DD2F29}</Project>
<Name>Spring.Messaging.Nms.2008</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\src\Spring\Spring.Services\Spring.Services.2008.csproj">
<Project>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Project>
<Name>Spring.Services.2008</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\src\Spring\Spring.Template.Velocity\Spring.Template.Velocity.2008.csproj">
<Project>{BF3AB954-8375-407C-9E98-4C51D8072784}</Project>
<Name>Spring.Template.Velocity.2008</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>

View File

@@ -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;