diff --git a/Spring.build b/Spring.build index 43f099c5..62ea88a7 100644 --- a/Spring.build +++ b/Spring.build @@ -1235,7 +1235,7 @@ Commandline Examples: file="src/Spring/Spring.Aop/Aop/Config/spring-aop-1.1.xsd"/> + file="src/Spring/Spring.Data/Data/Config/spring-database-1.3.xsd"/> diff --git a/doc/reference/src/dbprovider.xml b/doc/reference/src/dbprovider.xml index 8976e9cc..bdfee188 100644 --- a/doc/reference/src/dbprovider.xml +++ b/doc/reference/src/dbprovider.xml @@ -355,17 +355,20 @@ The default definitions of the providers are contained in the assembly resource - assembly://Spring.Data/Spring.Data.Common/dbproviders.xml. - Future additions to round out the database coverage are forthcoming. The - current crude mechanism to add additional providers, or to apply any - standard Spring IApplicationContext functionality, such - as applying AOP advice, is to set the public static property + assembly://Spring.Data/Spring.Data.Common/dbproviders.xml. If + the provider you want to use is not provided "out of the box" you can + provide additional definitions. To do this follow the format of object + definitions defined in the previously mentioned assembly resource. + + From Spring 1.3.1 an on you can specify the additional Spring + IResource location where additional providers are defined within Spring's + XML configuration file. See the next section for an example. + Alternatively, you can set the public static property DBPROVIDER_ADDITIONAL_RESOURCE_NAME in DbProviderFactory to a Spring resource location. The default value is file://dbProviders.xml. (That isn't a typo, - there is a difference in case with the name of the embedded resource). - This crude mechanism will eventually be replaced with one based on a - custom configuration section in App.config/Web.config. + there is a difference in case with the name of the embedded + resource). It may happen that the version number of an assembly you have downloaded is different than the one listed above. If it is a point @@ -403,6 +406,27 @@ <property name="DbProvider" ref="DbProvider"/> </object> +</objects> + + If you need to register an additional IDbProvider defintions from + your own configuration file, set the attribute 'additonalDbProviders' to + the IResource location of those definitions. Examples of the format for + additional provider definitions can be found within the Spring.Data + assembly, location + assembly://Spring.Data/Spring.Data.Common/dbproviders.xml. + Open it up in Visual Studio or Reflector to see the contents of the + dbproviders.xml file. + + <objects xmlns='http://www.springframework.net' + xmlns:db="http://www.springframework.net/database"> + + <db:additionalProviders resource="assembly://MyAssembly/MyAssembly.MyNamespace/AdditionalProviders.xml"/> + + <db:provider id="DbProvider" + provider="System.Data.SqlClient" + connectionString="Data Source=(local);Database=Spring;User ID=springqa;Password=springqa;Trusted_Connection=False"/> + + </objects> A custom namespace should be registered in the main application diff --git a/src/Spring/Spring.Core/Core/IO/AssemblyResource.cs b/src/Spring/Spring.Core/Core/IO/AssemblyResource.cs index 85fb917f..3fa3d067 100644 --- a/src/Spring/Spring.Core/Core/IO/AssemblyResource.cs +++ b/src/Spring/Spring.Core/Core/IO/AssemblyResource.cs @@ -247,7 +247,6 @@ namespace Spring.Core.IO } } -#if NET_2_0 /// /// Returns the handle for this resource. /// @@ -259,7 +258,7 @@ namespace Spring.Core.IO return new Uri(_fullResourceName); } } -#endif + #endregion /// diff --git a/src/Spring/Spring.Core/Expressions/PropertyOrFieldNode.cs b/src/Spring/Spring.Core/Expressions/PropertyOrFieldNode.cs index c2da3a68..86e5733f 100644 --- a/src/Spring/Spring.Core/Expressions/PropertyOrFieldNode.cs +++ b/src/Spring/Spring.Core/Expressions/PropertyOrFieldNode.cs @@ -44,8 +44,6 @@ namespace Spring.Expressions [Serializable] public class PropertyOrFieldNode : BaseNode { - //private static readonly Common.Logging.ILog Log = Common.Logging.LogManager.GetLogger(typeof(PropertyOrFieldNode)); - private const BindingFlags BINDING_FLAGS = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.IgnoreCase; diff --git a/src/Spring/Spring.Data/Data/Common/DbProviderConfigurer.cs b/src/Spring/Spring.Data/Data/Common/DbProviderConfigurer.cs new file mode 100644 index 00000000..c6595468 --- /dev/null +++ b/src/Spring/Spring.Data/Data/Common/DbProviderConfigurer.cs @@ -0,0 +1,102 @@ +#region License + +/* + * Copyright 2002-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#endregion + +using System; +using Common.Logging; +using Spring.Core; +using Spring.Core.IO; +using Spring.Objects.Factory.Config; + +namespace Spring.Data.Common +{ + /// + /// + /// + /// Mark Pollack + public class DbProviderConfigurer : IObjectFactoryPostProcessor, IOrdered + { + #region Fields + + private static readonly ILog log = LogManager.GetLogger(typeof(DbProviderConfigurer)); + + private int order = Int32.MinValue; + + private IResource providerResource; + + #endregion + + #region Constructor + /// + /// Initializes a new instance of the class. + /// + public DbProviderConfigurer() + { + } + #endregion + + #region Properties + + /// + /// Gets or sets the provider resource which contains additional IDbProvider definitions. + /// + /// The provider resource. + public IResource ProviderResource + { + get { return providerResource; } + set { providerResource = value; } + } + + #endregion + + #region Implementation of IObjectFactoryPostProcessor + + /// + /// Modify the application context's internal object factory after its + /// standard initialization. + /// + /// The object factory used by the application context. + /// + ///

+ /// All object definitions will have been loaded, but no objects will have + /// been instantiated yet. This allows for overriding or adding properties + /// even to eager-initializing objects. + ///

+ ///
+ /// + /// In case of errors. + /// + public void PostProcessObjectFactory(IConfigurableListableObjectFactory factory) + { + DbProviderFactory.DBPROVIDER_ADDITIONAL_RESOURCE_NAME = providerResource.Uri.AbsoluteUri; + } + + #endregion + + #region Implementation of IOrdered + + public int Order + { + get { return order; } + } + + #endregion + } + +} \ No newline at end of file diff --git a/src/Spring/Spring.Data/Data/Common/DbProviderFactory.cs b/src/Spring/Spring.Data/Data/Common/DbProviderFactory.cs index 682228d6..49c60e65 100644 --- a/src/Spring/Spring.Data/Data/Common/DbProviderFactory.cs +++ b/src/Spring/Spring.Data/Data/Common/DbProviderFactory.cs @@ -124,8 +124,6 @@ namespace Spring.Data.Common { try { - - //TODO get from well know location in app.config.... ConfigurableResourceLoader loader = new ConfigurableResourceLoader(DBPROVIDER_ADDITIONAL_RESOURCE_NAME); diff --git a/src/Spring/Spring.Data/Data/Common/DbProviderFactoryObject.cs b/src/Spring/Spring.Data/Data/Common/DbProviderFactoryObject.cs index b3bef15e..c18e624f 100644 --- a/src/Spring/Spring.Data/Data/Common/DbProviderFactoryObject.cs +++ b/src/Spring/Spring.Data/Data/Common/DbProviderFactoryObject.cs @@ -19,6 +19,7 @@ #endregion using System; +using Spring.Core.IO; using Spring.Objects.Factory; using Spring.Util; diff --git a/src/Spring/Spring.Data/Data/Config/DatabaseNamespaceParser.cs b/src/Spring/Spring.Data/Data/Config/DatabaseNamespaceParser.cs index cf1a2088..99443aed 100644 --- a/src/Spring/Spring.Data/Data/Config/DatabaseNamespaceParser.cs +++ b/src/Spring/Spring.Data/Data/Config/DatabaseNamespaceParser.cs @@ -44,15 +44,18 @@ namespace Spring.Data.Config NamespaceParser( Namespace = "http://www.springframework.net/database", SchemaLocationAssemblyHint = typeof(DatabaseNamespaceParser), - SchemaLocation = "/Spring.Data.Config/spring-database-1.1.xsd") - ] - public class DatabaseNamespaceParser : AbstractSingleObjectDefinitionParser + SchemaLocation = "/Spring.Data.Config/spring-database-1.3.xsd") + ] + public class DatabaseNamespaceParser : ObjectsNamespaceParser { private const string DatabaseTypePrefix = "database: "; static DatabaseNamespaceParser() - { + { + TypeRegistry.RegisterType( + DatabaseTypePrefix + DbProviderConfigurerConstants.DbProviderConfigurerElement, + typeof(DbProviderConfigurer)); TypeRegistry.RegisterType( DatabaseTypePrefix + DbProviderFactoryObjectConstants.DbProviderFactoryObjectElement, typeof (DbProviderFactoryObject)); @@ -63,55 +66,105 @@ namespace Spring.Data.Config ///
public DatabaseNamespaceParser() { - } - -// /// -// /// Parse the specified element and register any resulting -// /// IObjectDefinitions with the IObjectDefinitionRegistry that is -// /// embedded in the supplied ParserContext. -// /// -// /// The element to be parsed into one or more IObjectDefinitions -// /// The object encapsulating the current state of the parsing -// /// process. -// /// -// /// The primary IObjectDefinition (can be null as explained above) -// /// -// /// -// /// Implementations should return the primary IObjectDefinition -// /// that results from the parse phase if they wish to used nested -// /// inside (for example) a <property> tag. -// /// Implementations may return null if they will not -// /// be used in a nested scenario. -// /// -// /// -// [Obsolete("not used anymore - ObjectsNamespaceParser will be dropped with 2.x, use ObjectDefinitionParserHelper instead", false)] -// public override IObjectDefinition ParseElement(XmlElement element, ParserContext parserContext) -// { -// string id = GetAttributeValue(element, ObjectDefinitionConstants.IdAttribute); -// IConfigurableObjectDefinition databaseConfiguration = ParseDatabaseDefinition(element, id, parserContext); -// if (!StringUtils.HasText(id)) -// { -// id = ObjectDefinitionReaderUtils.GenerateObjectName(databaseConfiguration, parserContext.Registry); -// } -// #region Instrumentation -// -// if (log.IsDebugEnabled) -// { -// log.Debug( -// string.Format( -// CultureInfo.InvariantCulture, -// "Registering object definition with id '{0}'.", id)); -// } -// -// #endregion -// parserContext.Registry.RegisterObjectDefinition(id, databaseConfiguration); -// -// return null; -// } + } + + /// + /// Parse the specified element and register any resulting + /// IObjectDefinitions with the IObjectDefinitionRegistry that is + /// embedded in the supplied ParserContext. + /// + /// The element to be parsed into one or more IObjectDefinitions + /// The object encapsulating the current state of the parsing + /// process. + /// + /// The primary IObjectDefinition (can be null as explained above) + /// + /// + /// Implementations should return the primary IObjectDefinition + /// that results from the parse phase if they wish to used nested + /// inside (for example) a <property> tag. + /// Implementations may return null if they will not + /// be used in a nested scenario. + /// + /// + public override IObjectDefinition ParseElement(XmlElement element, ParserContext parserContext) + { + string name = element.GetAttribute(ObjectDefinitionConstants.IdAttribute); + IConfigurableObjectDefinition remotingDefinition = ParseDbProviderDefinition(element, name, parserContext); + if (!StringUtils.HasText(name)) + { + name = ObjectDefinitionReaderUtils.GenerateObjectName(remotingDefinition, parserContext.Registry); + } + parserContext.Registry.RegisterObjectDefinition(name, remotingDefinition); + + return null; + } + + + /// + /// Parses database provider definitions. + /// + /// Validator XML element. + /// The name of the object definition. + /// The parser context. + /// A database provider object definition. + private IConfigurableObjectDefinition ParseDbProviderDefinition( + XmlElement element, string name, ParserContext parserContext) + { + switch (element.LocalName) + { + case DbProviderConfigurerConstants.DbProviderConfigurerElement: + return ParseDbProviderConfigurer(element, name, parserContext); + case DbProviderFactoryObjectConstants.DbProviderFactoryObjectElement: + return ParseDbProviderFactoryObject(element, name, parserContext); + } + + return null; + } + + private IConfigurableObjectDefinition ParseDbProviderConfigurer(XmlElement element, string name, ParserContext parserContext) + { + string typeName = GetTypeName(element); + string resource = GetAttributeValue(element, DbProviderConfigurerConstants.ResourceAttribute); + + MutablePropertyValues propertyValues = new MutablePropertyValues(); + if (StringUtils.HasText(resource)) + { + propertyValues.Add("ProviderResource", resource); + } + IConfigurableObjectDefinition cod = parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition( + typeName, null, parserContext.ReaderContext.Reader.Domain); + cod.PropertyValues = propertyValues; + return cod; + } + + private IConfigurableObjectDefinition ParseDbProviderFactoryObject(XmlElement element, string name, ParserContext parserContext) + { + string typeName = GetTypeName(element); + + string providerNameAttribute = GetAttributeValue(element, DbProviderFactoryObjectConstants.ProviderNameAttribute); + string connectionString = GetAttributeValue(element, DbProviderFactoryObjectConstants.ConnectionStringAttribute); + + MutablePropertyValues propertyValues = new MutablePropertyValues(); + if (StringUtils.HasText(providerNameAttribute)) + { + propertyValues.Add("Provider", providerNameAttribute); + } + if (StringUtils.HasText(connectionString)) + { + propertyValues.Add("ConnectionString", connectionString); + } + IConfigurableObjectDefinition cod = parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition( + typeName, null, parserContext.ReaderContext.Reader.Domain); + cod.PropertyValues = propertyValues; + return cod; + + } + + /* protected override void DoParse(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder) { -// base.DoParse(element, parserContext, builder); switch (element.LocalName) { case DbProviderFactoryObjectConstants.DbProviderFactoryObjectElement: @@ -121,42 +174,41 @@ namespace Spring.Data.Config } } } - -// private IConfigurableObjectDefinition ParseDatabaseDefinition(XmlElement element, string name, ParserContext parserContext) -// { -// switch (element.LocalName) -// { -// case DbProviderFactoryObjectConstants.DbProviderFactoryObjectElement: -// return ParseDatabaseConfigurer(element, name, parserContext); -// } -// return null; -// } - + */ + + /* private void ParseDatabaseConfigurer(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder) - { -// string typeName = GetTypeName(element); + { string providerNameAttribute = GetAttributeValue(element, DbProviderFactoryObjectConstants.ProviderNameAttribute); - string connectionString = GetAttributeValue(element, DbProviderFactoryObjectConstants.ConnectionStringAttribute); + string connectionString = GetAttributeValue(element, DbProviderFactoryObjectConstants.ConnectionStringAttribute); -// MutablePropertyValues properties = new MutablePropertyValues(); if (StringUtils.HasText(providerNameAttribute)) { builder.AddPropertyValue("Provider", providerNameAttribute); -// properties.Add("Provider", providerNameAttribute); } if (StringUtils.HasText(connectionString)) { builder.AddPropertyValue("ConnectionString", connectionString); -// properties.Add("ConnectionString", connectionString); - } - -// IConfigurableObjectDefinition cod = parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition( -// typeName, null, parserContext.ReaderContext.Reader.Domain); -// cod.PropertyValues = properties; - -// return builder.ObjectDefinition; + } + } + */ + + /// + /// Gets the name of the object type for the specified element. + /// + /// The element. + /// The name of the object type. + private string GetTypeName(XmlElement element) + { + string typeName = GetAttributeValue(element, ObjectDefinitionConstants.TypeAttribute); + if (StringUtils.IsNullOrEmpty(typeName)) + { + return DatabaseTypePrefix + element.LocalName; + } + return typeName; } + /* protected override string GetObjectTypeName(XmlElement element) { string typeName = GetAttributeValue(element, ObjectDefinitionConstants.TypeAttribute); @@ -165,29 +217,20 @@ namespace Spring.Data.Config return DatabaseTypePrefix + element.LocalName; } return typeName; - } - -// /// -// /// Gets the name of the object type for the specified element. This has already been aliased -// /// in the static constructor. -// /// -// /// The element. -// /// The name of the object type. -// private string GetTypeName(XmlElement element) -// { -// string typeName = GetAttributeValue(element, ObjectDefinitionConstants.TypeAttribute); -// if (StringUtils.IsNullOrEmpty(typeName)) -// { -// return DatabaseTypePrefix + element.LocalName; -// } -// return typeName; -// } + }*/ private class DbProviderFactoryObjectConstants { public const string DbProviderFactoryObjectElement = "provider"; public const string ProviderNameAttribute = "provider"; - public const string ConnectionStringAttribute = "connectionString"; + public const string ConnectionStringAttribute = "connectionString"; + + } + + private class DbProviderConfigurerConstants + { + public const string DbProviderConfigurerElement = "additionalProviders"; + public const string ResourceAttribute = "resource"; } } } diff --git a/src/Spring/Spring.Data/Data/Config/spring-database-1.3.xsd b/src/Spring/Spring.Data/Data/Config/spring-database-1.3.xsd new file mode 100644 index 00000000..18dac604 --- /dev/null +++ b/src/Spring/Spring.Data/Data/Config/spring-database-1.3.xsd @@ -0,0 +1,304 @@ + + + + + + + + Spring.NET Database Framework Config Schema Definition + + Author: Mark Pollack + + This file defines a configuration schema for the database framework + object definitions. Using elements from this schema instead of the + standard object definitions can greatly simplify remoting configuration. + + + + + + Defines a DbProvider instance + + + + + The id of the DbProvider instance to be referenced. + + + + + The name of the database provider. + + + + + The database connection string. + + + + + + + + Defines location of configuration for that defines additional DbProviders + + + + + The Spring IResource location that contains additional IDbProvider definitions. + + + + + + + + + + + + + + + + + + Microsoft SQL Server, provider V1.0.5000.0 in framework .NET V1.1 + + + + + Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0 + + + + + Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0 + + + + + Microsoft SQL Server Compact Edition, provider V9.0.242.0 + + + + + Microsoft SQL Server Compact Edition, provider V3.5.1.0 + + + + + Microsoft SQL Server Compact Edition, provider V3.5.1.0 + + + + + OleDb, provider V1.0.5000.0 in framework .NET V1.1 + + + + + OleDb, provider V2.0.0.0 in framework .NET V2.0 + + + + + OleDb, provider V2.0.0.0 in framework .NET V2.0 + + + + + Oracle, Microsoft provider V2.0.0.0 + + + + + Oracle, Oracle provider V2.102.2.20 + + + + + Oracle, Oracle provider V2.102.2.20 + + + + + Oracle, Oracle provider V2.102.2.20 + + + + + Oracle, Oracle provider V2.111.7.20 + + + + + MySQL provider 1.0.7.3007 + + + + + MySQL provider 1.0.9.0 + + + + + MySQL provider 5.0.7.0 + + + + + MySQL provider 5.0.8.1 + + + + + MySQL provider 5.1.2.2 + + + + + MySQL provider 5.1.4.0 + + + + + MySQL provider 5.2.3.0 + + + + + MySQL provider 6.1.3.0 + + + + + MySQL provider 6.2.2.0 + + + + + MySQL provider 6.2.2.0 + + + + + Npgsql provider 1.0.0.0 + + + + + Npgsql provider beta-1 1.98.1.0 + + + + + Npgsql provider 2.0.0.0 + + + + + IBM DB2 Data Provider 9.1.0 for .NET Framework 1.1 + + + + + IBM DB2 Data Provider 9.1.0 for .NET Framework 2.0 + + + + + IBM DB2 Data Provider 9.1.0 for .NET Framework 2.0 + + + + + IBM iSeries DB2 Data Provider 10.0.0.0 + + + + + SQLite 1.0.43 provider + + + + + SQLite 1.0.44 provider + + + + + SQLite 1.0.47 provider + + + + + SQLite 1.0.56 provider + + + + + SQLite 1.0.65 provider + + + + + SQLite 1.0.65 provider + + + + + Firebird Server, provider V2.1.0.0 in framework .NET V2.0 + + + + + Firebird Server, provider V2.1.0.0 in framework .NET V2.0 + + + + + Sybase ASE 12.5, 1.1.411 provider + + + + + Sybase ASE 15, 1.15.152 provider + + + + + Sybase ADO.NET ASE 12.5 and ASE 15, 1.15.192.0 provider + + + + + Microsoft ODBC, provider V1.0.5000.0 in framework .NET V1.1 + + + + + Microsoft ODBC, provider V2.0.0.0 in framework .NET V2 + + + + + InterSystems CacheConnection Version 2.0.0.1 in framework .NET V2 + + + + + InterSystems CacheConnection Version 2.0.0.1 in framework .NET V2 + + + + + + + \ No newline at end of file diff --git a/src/Spring/Spring.Data/Data/Config/spring-database-1.3.xsx b/src/Spring/Spring.Data/Data/Config/spring-database-1.3.xsx new file mode 100644 index 00000000..ff71343b --- /dev/null +++ b/src/Spring/Spring.Data/Data/Config/spring-database-1.3.xsx @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/Spring/Spring.Data/Spring.Data.2003.csproj b/src/Spring/Spring.Data/Spring.Data.2003.csproj index b58bab18..90129591 100644 --- a/src/Spring/Spring.Data/Spring.Data.2003.csproj +++ b/src/Spring/Spring.Data/Spring.Data.2003.csproj @@ -438,6 +438,11 @@ SubType = "Code" BuildAction = "Compile" /> + + + @@ -317,6 +318,14 @@ Spring.Core.2005 + + + Designer + + + spring-database-1.3.xsd + + diff --git a/src/Spring/Spring.Data/Spring.Data.2008.csproj b/src/Spring/Spring.Data/Spring.Data.2008.csproj index 8a600a43..6d9714c8 100644 --- a/src/Spring/Spring.Data/Spring.Data.2008.csproj +++ b/src/Spring/Spring.Data/Spring.Data.2008.csproj @@ -137,6 +137,7 @@ + @@ -315,6 +316,9 @@ Spring.Core.2008 + + + diff --git a/src/Spring/Spring.Data/Spring.Data.build b/src/Spring/Spring.Data/Spring.Data.build index d2b4442b..5f6f26ae 100644 --- a/src/Spring/Spring.Data/Spring.Data.build +++ b/src/Spring/Spring.Data/Spring.Data.build @@ -28,6 +28,7 @@ + diff --git a/test/Spring/Spring.Data.Tests/Data/Common/AdditonalProviders.xml b/test/Spring/Spring.Data.Tests/Data/Common/AdditonalProviders.xml deleted file mode 100644 index 066dd068..00000000 --- a/test/Spring/Spring.Data.Tests/Data/Common/AdditonalProviders.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - 1054,1064,1146 - - - 1 - - - 1062 - - - 1205 - - - 1213 - - - - - \ No newline at end of file diff --git a/test/Spring/Spring.Data.Tests/Data/Common/DbProviderFactoryTests.cs b/test/Spring/Spring.Data.Tests/Data/Common/DbProviderFactoryTests.cs index 025acfa2..b6136204 100644 --- a/test/Spring/Spring.Data.Tests/Data/Common/DbProviderFactoryTests.cs +++ b/test/Spring/Spring.Data.Tests/Data/Common/DbProviderFactoryTests.cs @@ -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); } diff --git a/test/Spring/Spring.Data.Tests/Data/Common/DbProviderFactoryTests.xml b/test/Spring/Spring.Data.Tests/Data/Common/DbProviderFactoryTests.xml new file mode 100644 index 00000000..16bdd921 --- /dev/null +++ b/test/Spring/Spring.Data.Tests/Data/Common/DbProviderFactoryTests.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + diff --git a/test/Spring/Spring.Data.Tests/Data/Common/MultiDelegatingDbProviderTests.cs b/test/Spring/Spring.Data.Tests/Data/Common/MultiDelegatingDbProviderTests.cs index 5c57ee03..8b265fd5 100644 --- a/test/Spring/Spring.Data.Tests/Data/Common/MultiDelegatingDbProviderTests.cs +++ b/test/Spring/Spring.Data.Tests/Data/Common/MultiDelegatingDbProviderTests.cs @@ -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(); } diff --git a/test/Spring/Spring.Data.Tests/Spring.Data.Tests.2003.csproj b/test/Spring/Spring.Data.Tests/Spring.Data.Tests.2003.csproj index cd81d8f7..f76a4572 100644 --- a/test/Spring/Spring.Data.Tests/Spring.Data.Tests.2003.csproj +++ b/test/Spring/Spring.Data.Tests/Spring.Data.Tests.2003.csproj @@ -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" copy "$(ProjectDir)$(TargetFileName).config" ..\..\..\..\build\VS.Net.2003\Spring.Core.Tests\$(ConfigurationName)\$(TargetFileName).config' RootNamespace = "Spring" RunPostBuildEvent = "OnBuildSuccess" StartupObject = "" @@ -154,7 +154,7 @@ /> + + + + + @@ -175,6 +176,7 @@ + diff --git a/test/Spring/Spring.Data.Tests/Spring.Data.Tests.2008.csproj b/test/Spring/Spring.Data.Tests/Spring.Data.Tests.2008.csproj index 43a30026..c47162df 100644 --- a/test/Spring/Spring.Data.Tests/Spring.Data.Tests.2008.csproj +++ b/test/Spring/Spring.Data.Tests/Spring.Data.Tests.2008.csproj @@ -165,6 +165,7 @@ + diff --git a/test/Spring/Spring.Data.Tests/Spring.Data.Tests.dll.config b/test/Spring/Spring.Data.Tests/Spring.Data.Tests.dll.config index 259adbad..b3c71da2 100644 --- a/test/Spring/Spring.Data.Tests/Spring.Data.Tests.dll.config +++ b/test/Spring/Spring.Data.Tests/Spring.Data.Tests.dll.config @@ -24,7 +24,9 @@ limitations under the License.
-
+
+
+