SPRNET-1042 - Specify location of additional DbProvider definitions in Spring XML database namespace

This commit is contained in:
markpollack
2010-06-10 21:47:46 +00:00
parent 30a4bf4146
commit 7d7cabb3bf
22 changed files with 678 additions and 173 deletions

View File

@@ -1,43 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns='http://www.springframework.net'>
<object id="MySqlPersonal" type="Spring.Data.Common.DbProvider, Spring.Data" lazy-init="true">
<constructor-arg name="dbMetaData">
<object type="Spring.Data.Common.DbMetadata">
<constructor-arg name="productName" value="MySQL, MySQL provider 1.0.7.30072" />
<constructor-arg name="assemblyName" value="MySql.Data, Version=1.0.7.30072, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
<constructor-arg name="connectionType" value="MySql.Data.MySqlClient.MySqlConnection"/>
<constructor-arg name="commandType" value="MySql.Data.MySqlClient.MySqlCommand"/>
<constructor-arg name="parameterType" value="MySql.Data.MySqlClient.MySqlParameter"/>
<constructor-arg name="dataAdapterType" value="MySql.Data.MySqlClient.MySqlDataAdapter"/>
<constructor-arg name="commandBuilderType" value="MySql.Data.MySqlClient.MySqlCommandBuilder"/>
<constructor-arg name="commandBuilderDeriveParametersMethod" value="DeriveParameters"/>
<constructor-arg name="parameterDbType" value="MySql.Data.MySqlClient.MySqlDbType"/>
<constructor-arg name="parameterDbTypeProperty" value="MySqlDbType"/>
<constructor-arg name="parameterIsNullableProperty" value="IsNullable"/>
<constructor-arg name="parameterNamePrefix" value="?"/>
<constructor-arg name="exceptionType" value="MySql.Data.MySqlClient.MySqlException"/>
<constructor-arg name="useParameterNamePrefixInParameterCollection" 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="Number.ToString()"/>
<property name="ErrorCodes.badSqlGrammarCodes">
<value>1054,1064,1146</value>
</property>
<property name="ErrorCodes.DataAccessResourceFailureCodes">
<value>1</value>
</property>
<property name="ErrorCodes.DataIntegrityViolationCodes">
<value>1062</value>
</property>
<property name="ErrorCodes.CannotAcquireLockCodes">
<value>1205</value>
</property>
<property name="ErrorCodes.DeadlockLoserCodes">
<value>1213</value>
</property>
</object>
</constructor-arg>
</object>
</objects>

View File

@@ -20,11 +20,12 @@
using System;
using System.Globalization;
using System.Reflection;
using System.Threading;
using NUnit.Framework;
using Spring.Context;
using Spring.Context.Support;
using Spring.Threading;
using Spring.Util;
namespace Spring.Data.Common
{
@@ -56,13 +57,21 @@ namespace Spring.Data.Common
#endregion
private static string altConfig = "assembly://Spring.Data.Tests/Spring.Data.Common/AdditionalProviders.xml";
private IApplicationContext ctx;
[SetUp]
public void Setup()
public void SetUp()
{
DbProviderFactory.DBPROVIDER_ADDITIONAL_RESOURCE_NAME = altConfig;
//Other tests in this assembly will have already initialized the internal context that is part of DbProviderFactory
//Reset it back to null so that tests for specifiying additional database providers will be able 're-initialize'
//the internal Context of DbProviderFactory.
//Spring.Objects.Factory.Xml.NamespaceParserRegistry.RegisterParser(typeof(Spring.Data.Config.DatabaseNamespaceParser));
if (DbProviderFactory.ApplicationContext != null)
{
FieldInfo fieldInfo = typeof (DbProviderFactory).GetField("ctx", BindingFlags.NonPublic | BindingFlags.Static);
fieldInfo.SetValue(null, null);
}
ctx = new XmlApplicationContext("assembly://Spring.Data.Tests/Spring.Data.Common/DbProviderFactoryTests.xml");
}
#if NET_2_0
@@ -83,16 +92,13 @@ namespace Spring.Data.Common
}
[Test]
[Ignore("Can't guarantee test order")]
public void AdditionalResourceName()
{
{
IDbProvider provider = DbProviderFactory.GetDbProvider("Test-SqlServer-2.0");
Assert.IsNotNull(provider);
}
[Test]
[Ignore("Can't guarantee test order")]
public void BadErrorExpression()
{
@@ -106,8 +112,8 @@ namespace Spring.Data.Common
public void DefaultInstanceWithSqlServer2005()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", false);
IApplicationContext ctx = DbProviderFactory.ApplicationContext;
Assert.IsNotNull(ctx);
//IApplicationContext ctx = DbProviderFactory.ApplicationContext;
//Assert.IsNotNull(ctx);
Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR", false);
IDbProvider provider = DbProviderFactory.GetDbProvider("SqlServer-2.0");
AssertIsSqlServer2005(provider);
@@ -150,8 +156,8 @@ namespace Spring.Data.Common
}
#endif
[Test]
[Ignore("until find out if can add oracle.dll to cvs repository")]
//[Test]
//Comment in for specific testing with oracle as can't put oracle client in public code repository
public void DefaultInstanceWithOracleClient20()
{
IDbProvider provider = DbProviderFactory.GetDbProvider("OracleODP-2.0");
@@ -181,11 +187,11 @@ namespace Spring.Data.Common
[Test]
public void TestDb2()
{
//Initialize internal application context. factory
DbProviderFactory.GetDbProvider("SqlServer-2.0");
IApplicationContext ctx = DbProviderFactory.ApplicationContext;
string[] dbProviderNames = ctx.GetObjectNamesForType(typeof(IDbProvider));
Console.WriteLine(
String.Format("{0} DbProviders Available. [{1}]", dbProviderNames.Length,
StringUtils.ArrayToCommaDelimitedString(dbProviderNames)));
Assert.IsTrue(dbProviderNames.Length > 0);
}

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns='http://www.springframework.net'
xmlns:db="http://www.springframework.net/database">
<db:additionalProviders resource="assembly://Spring.Data.Tests/Spring.Data.Common/AdditionalProviders.xml"/>
<db:provider id="DbProvider"
provider="System.Data.SqlClient"
connectionString="Data Source=SPRINGQA;Database=Spring;Trusted_Connection=False;User ID=springqa;Password=springqa"/>
</objects>

View File

@@ -226,9 +226,9 @@ namespace Spring.Data.Common
Exception e = new Exception("foo");
Expect.Call(dbProvider.ExtractError(e)).Return("badsql").Repeat.Once();
#if !NET_1_1
DbException dbException = (DbException) mocks.CreateMock(typeof (DbException));
#endif
MultiDelegatingDbProvider multiDbProvider = new MultiDelegatingDbProvider();
@@ -255,7 +255,9 @@ namespace Spring.Data.Common
Assert.IsNotNull(multiDbProvider.DbMetadata);
Assert.AreEqual("badsql", multiDbProvider.ExtractError(e));
#if !NET_1_1
Assert.IsTrue(multiDbProvider.IsDataAccessException(dbException));
#endif
Assert.IsFalse(multiDbProvider.IsDataAccessException(e));
mocks.VerifyAll();
}

View File

@@ -17,7 +17,7 @@
DelaySign = "false"
OutputType = "Library"
PreBuildEvent = ""
PostBuildEvent = ""
PostBuildEvent = 'echo copying "$(ProjectDir)$(TargetFileName).config" to "..\..\..\..\build\VS.Net.2003\Spring.Core.Tests\$(ConfigurationName)\$(TargetFileName).config"&#xd;&#xa;copy "$(ProjectDir)$(TargetFileName).config" ..\..\..\..\build\VS.Net.2003\Spring.Core.Tests\$(ConfigurationName)\$(TargetFileName).config'
RootNamespace = "Spring"
RunPostBuildEvent = "OnBuildSuccess"
StartupObject = ""
@@ -154,7 +154,7 @@
/>
<File
RelPath = "Spring.Data.Tests.dll.config"
BuildAction = "None"
BuildAction = "Content"
/>
<File
RelPath = "Dao\IncorrectResultSizeDataAccessExceptionTests.cs"
@@ -211,14 +211,33 @@
BuildAction = "Compile"
/>
<File
RelPath = "Data\Common\AdditonalProviders.xml"
RelPath = "Data\Common\AdditionalProviders.xml"
BuildAction = "EmbeddedResource"
/>
<File
RelPath = "Data\Common\DbParametersTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Data\Common\DbProviderFactoryTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Data\Common\DbProviderFactoryTests.xml"
BuildAction = "EmbeddedResource"
/>
<File
RelPath = "Data\Common\MultiDelegatingDbProviderTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Data\Common\UserCredentialsDbProviderTests.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Data\Core\ServiceDomainTransactionManagerTests.cs"
SubType = "Code"

View File

@@ -165,6 +165,7 @@
<ItemGroup>
<EmbeddedResource Include="Data\AutoDeclarativeTxTests.xml" />
<EmbeddedResource Include="Data\Common\AdditionalProviders.xml" />
<EmbeddedResource Include="Data\Common\DbProviderFactoryTests.xml" />
<Content Include="Spring.Data.Tests.dll.config" />
<EmbeddedResource Include="Transaction\Interceptor\MatchAlwaysTransactionAttributeSourceTests.xml" />
<EmbeddedResource Include="Transaction\Config\TxNamespaceParserTests.xml" />
@@ -175,6 +176,7 @@
<Compile Include="Dao\Attributes\PersistenceExceptionTranslationPostProcessorTests.cs" />
<Compile Include="Dao\Support\DataAccessUtilsTests.cs" />
<Compile Include="Data\Common\DbParametersTests.cs" />
<Compile Include="Data\Common\MultiDelegatingDbProviderTests.cs" />
<Compile Include="Data\Common\UserCredentialsDbProviderTests.cs" />
<Compile Include="Data\Core\ServiceDomainTransactionManagerTests.cs" />
<Compile Include="Data\Core\TxScopeTransactionManagerIntegrationTests.cs" />

View File

@@ -165,6 +165,7 @@
<ItemGroup>
<EmbeddedResource Include="Data\AutoDeclarativeTxTests.xml" />
<EmbeddedResource Include="Data\Common\AdditionalProviders.xml" />
<EmbeddedResource Include="Data\Common\DbProviderFactoryTests.xml" />
<Content Include="Spring.Data.Tests.dll.config" />
<Content Include="Transaction\Config\TxNamespaceParserTests_TxAttributeDriven.xml" />
<EmbeddedResource Include="Transaction\Interceptor\MatchAlwaysTransactionAttributeSourceTests.xml" />

View File

@@ -24,7 +24,9 @@ limitations under the License.
<sectionGroup name='spring'>
<section name='context' type='Spring.Context.Support.ContextHandler, Spring.Core'/>
<section name='objects' type='Spring.Context.Support.DefaultSectionHandler, Spring.Core' />
<section name='objects' type='Spring.Context.Support.DefaultSectionHandler, Spring.Core' />
<section name='parsers' type='Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core' />
</sectionGroup>
<!--
@@ -51,6 +53,11 @@ limitations under the License.
</objects>
<parsers>
<parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data" />
</parsers>
</spring>