SPRNET-1571 SPRNET-1572 set OracleCommand's BindByName to true

* add native ODP.NET 12 provider
* add managed ODP.NET 12 provider
This commit is contained in:
Marko Lahma
2014-03-14 13:19:59 +02:00
parent 0311d3694d
commit e9ade58ee7
6 changed files with 275 additions and 64 deletions

View File

@@ -23,7 +23,9 @@ using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using System.Threading;
using NUnit.Framework;
using Spring.Context;
using Spring.Context.Support;
using Spring.Threading;
@@ -41,7 +43,7 @@ namespace Spring.Data.Common
public class AsyncTestDbProviderFactory : AsyncTestTask
{
private string providerName;
private readonly string providerName;
public AsyncTestDbProviderFactory(int iterations, string providerName)
: base(iterations)
@@ -66,12 +68,12 @@ namespace Spring.Data.Common
//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));
//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);
}
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");
}
@@ -82,17 +84,16 @@ namespace Spring.Data.Common
AsyncTestTask t2 = new AsyncTestDbProviderFactory(1000, "SqlServer-2.0").Start();
AsyncTestTask t3 = new AsyncTestDbProviderFactory(1000, "SqlServer-2.0").Start();
AsyncTestTask t4 = new AsyncTestDbProviderFactory(1000, "SqlServer-2.0").Start();
t1.AssertNoException();
t2.AssertNoException();
t3.AssertNoException();
t4.AssertNoException();
}
[Test]
public void AdditionalResourceName()
{
{
IDbProvider provider = DbProviderFactory.GetDbProvider("Test-SqlServer-2.0");
Assert.IsNotNull(provider);
}
@@ -100,11 +101,10 @@ namespace Spring.Data.Common
[Test]
public void BadErrorExpression()
{
IDbProvider provider = DbProviderFactory.GetDbProvider("Test-SqlServer-2.0-BadErrorCodeExpression");
Assert.IsNotNull(provider);
string errorCode = provider.ExtractError(new Exception("foo"));
Assert.AreEqual("156",errorCode);
Assert.AreEqual("156", errorCode);
}
[Test]
@@ -126,8 +126,7 @@ namespace Spring.Data.Common
Assert.IsNotNull(provider.CreateParameter());
Assert.AreEqual("@Foo", provider.CreateParameterName("Foo"));
}
[Test]
public void DefaultInstanceWithOleDb20()
{
@@ -140,7 +139,7 @@ namespace Spring.Data.Common
Assert.IsNotNull(provider.CreateParameter());
Assert.AreEqual("?", provider.CreateParameterName("Foo"));
}
[Test]
public void DefaultInstanceWithMicrsoftOracleClient20()
{
@@ -155,7 +154,7 @@ namespace Spring.Data.Common
}
#if NET_4_0
[Test]
public void DefaultInstanceWithSqlServer40()
{
@@ -184,19 +183,82 @@ namespace Spring.Data.Common
}
#endif
//[Test]
//Comment in for specific testing with oracle as can't put oracle client in public code repository
public void DefaultInstanceWithOracleClient20()
[Test]
public void DefaultInstanceWithOracleClient10_20()
{
IDbProvider provider = DbProviderFactory.GetDbProvider("OracleODP-2.0");
Assert.AreEqual("Oracle, Oracle provider V2.102.2.20", provider.DbMetadata.ProductName);
Assert.IsNotNull(provider.CreateCommand());
if (Type.GetType("Oracle.DataAccess.Client.OracleConnection, Oracle.DataAccess, Version=2.102.2.20, Culture=neutral, PublicKeyToken=89b483f429c47342") == null)
{
Assert.Inconclusive("oracle data access libs not found, skipping test");
}
AssertOracleProvider("OracleODP-2.0", "Oracle, Oracle provider V2.102.2.20");
}
[Test]
public void DefaultInstanceWithOracleClient11_20()
{
if (Type.GetType("Oracle.DataAccess.Client.OracleConnection, Oracle.DataAccess, Version=2.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342") == null)
{
Assert.Inconclusive("oracle data access libs not found, skipping test");
}
AssertOracleProvider("OracleODP-11-2.0", "Oracle, Oracle provider V2.112.3.0");
}
[Test]
public void DefaultInstanceWithOracleClient12_20()
{
if (Type.GetType("Oracle.DataAccess.Client.OracleConnection, Oracle.DataAccess, Version=2.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342") == null)
{
Assert.Inconclusive("oracle data access libs not found, skipping test");
}
AssertOracleProvider("OracleODP-12-2.0", "Oracle, Oracle provider V2.121.1.0");
}
[Test]
public void DefaultInstanceWithOracleClient12_40()
{
if (Type.GetType("Oracle.DataAccess.Client.OracleConnection, Oracle.DataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342") == null)
{
Assert.Inconclusive("oracle data access libs not found, skipping test");
}
AssertOracleProvider("OracleODP-12-4.0", "Oracle, Oracle provider V4.121.1.0");
}
[Test]
public void DefaultInstanceWithOracleManagedClient11_40()
{
if (Type.GetType("Oracle.ManagedDataAccess.Client.OracleConnection, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342") == null)
{
Assert.Inconclusive("oracle data access libs not found, skipping test");
}
AssertOracleProvider("OracleODP-Managed-12-4.0", "Oracle, Oracle Managed provider V4.121.1.0");
}
private static void AssertOracleProvider(string providerName, string productName)
{
IDbProvider provider = DbProviderFactory.GetDbProvider(providerName);
Assert.AreEqual(productName, provider.DbMetadata.ProductName);
var command = provider.CreateCommand();
Assert.IsNotNull(command);
// check if parameter has readable BindByName property
var property = command.GetType().GetProperty("BindByName");
if (property != null)
{
var bindByNameValue = property.GetValue(command, null);
Assert.That(bindByNameValue, Is.EqualTo(provider.DbMetadata.BindByName), "BindByName had wrong value");
}
Assert.IsNotNull(provider.CreateCommandBuilder());
Assert.IsNotNull(provider.CreateConnection());
Assert.IsNotNull(provider.CreateDataAdapter());
Assert.IsNotNull(provider.CreateParameter());
Assert.AreEqual(":Foo", provider.CreateParameterName("Foo"));
Assert.AreEqual(":Foo", provider.CreateParameterName("Foo"));
}
/*
@@ -218,22 +280,21 @@ namespace Spring.Data.Common
//Initialize internal application context. factory
DbProviderFactory.GetDbProvider("SqlServer-2.0");
IApplicationContext ctx = DbProviderFactory.ApplicationContext;
IList<string> dbProviderNames = ctx.GetObjectNamesForType(typeof(IDbProvider));
Assert.IsTrue(dbProviderNames.Count > 0);
IList<string> dbProviderNames = ctx.GetObjectNamesForType(typeof (IDbProvider));
Assert.IsTrue(dbProviderNames.Count > 0);
}
private void AssertIsSqlServer2005(IDbProvider provider)
{
Assert.AreEqual("Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0",
provider.DbMetadata.ProductName);
provider.DbMetadata.ProductName);
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);
provider.DbMetadata.ProductName);
AssertCommonSqlServerErrorCodes(provider);
}
@@ -248,4 +309,4 @@ namespace Spring.Data.Common
Assert.IsFalse(Array.IndexOf(codes.BadSqlGrammarCodes, "1xx56") >= 0);
}
}
}
}

View File

@@ -84,6 +84,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Oracle.ManagedDataAccess">
<HintPath>..\..\..\packages\odp.net.managed.121.1.1\lib\net40\Oracle.ManagedDataAccess.dll</HintPath>
</Reference>
<Reference Include="Rhino.Mocks, Version=2.9.6.40380, Culture=neutral, PublicKeyToken=0b3305902db7183f">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\Net\2.0\Rhino.Mocks.dll</HintPath>

View File

@@ -2,4 +2,5 @@
<packages>
<package id="Common.Logging" version="2.1.2" targetFramework="net40" />
<package id="NUnit" version="2.6.3" targetFramework="net40" />
<package id="odp.net.managed" version="121.1.1" targetFramework="net40" />
</packages>