diff --git a/lib/NHibernate21/net/2.0/LinFu.DynamicProxy.dll b/lib/NHibernate21/net/2.0/LinFu.DynamicProxy.dll deleted file mode 100644 index 22225220..00000000 Binary files a/lib/NHibernate21/net/2.0/LinFu.DynamicProxy.dll and /dev/null differ diff --git a/lib/NHibernate21/net/2.0/NHibernate.ByteCode.LinFu.dll b/lib/NHibernate21/net/2.0/NHibernate.ByteCode.LinFu.dll deleted file mode 100644 index 015189d9..00000000 Binary files a/lib/NHibernate21/net/2.0/NHibernate.ByteCode.LinFu.dll and /dev/null differ diff --git a/lib/NHibernate30/net/3.5/LinFu.DynamicProxy.dll b/lib/NHibernate30/net/3.5/LinFu.DynamicProxy.dll deleted file mode 100644 index 22225220..00000000 Binary files a/lib/NHibernate30/net/3.5/LinFu.DynamicProxy.dll and /dev/null differ diff --git a/lib/NHibernate30/net/3.5/NHibernate.ByteCode.LinFu.dll b/lib/NHibernate30/net/3.5/NHibernate.ByteCode.LinFu.dll deleted file mode 100644 index 2035ee6d..00000000 Binary files a/lib/NHibernate30/net/3.5/NHibernate.ByteCode.LinFu.dll and /dev/null differ diff --git a/src/Spring/Spring.Data.NHibernate20/Data/NHibernate/LocalSessionFactoryObject.cs b/src/Spring/Spring.Data.NHibernate20/Data/NHibernate/LocalSessionFactoryObject.cs index cdc6b309..acf94671 100644 --- a/src/Spring/Spring.Data.NHibernate20/Data/NHibernate/LocalSessionFactoryObject.cs +++ b/src/Spring/Spring.Data.NHibernate20/Data/NHibernate/LocalSessionFactoryObject.cs @@ -499,7 +499,24 @@ namespace Spring.Data.NHibernate if (this.hibernateProperties != null) { - if (config.GetProperty(Environment.ConnectionProvider) !=null && +#if NH_2_1 + // check whether proxy factory has been initialized + if (config.GetProperty(Environment.ProxyFactoryFactoryClass) == null + && !hibernateProperties.Contains(Environment.ProxyFactoryFactoryClass)) + { + // nothing set by user, lets use Spring.NET's proxy factory factory + #region Logging + if (log.IsInfoEnabled) + { + log.Info("Setting proxy factory to Spring provided one as user did not specify any"); + } + #endregion + config.Properties.Add( + Environment.ProxyFactoryFactoryClass, typeof(Bytecode.ProxyFactoryFactory).AssemblyQualifiedName); + } +#endif + + if (config.GetProperty(Environment.ConnectionProvider) != null && hibernateProperties.Contains(Environment.ConnectionProvider)) { #region Logging diff --git a/src/Spring/Spring.Data.NHibernate21/Data/NHibernate/Bytecode/BytecodeProvider.cs b/src/Spring/Spring.Data.NHibernate21/Data/NHibernate/Bytecode/BytecodeProvider.cs new file mode 100644 index 00000000..6de27b0c --- /dev/null +++ b/src/Spring/Spring.Data.NHibernate21/Data/NHibernate/Bytecode/BytecodeProvider.cs @@ -0,0 +1,95 @@ +#region License + +/* + * Copyright © 2002-2005 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 + +#region Imports + +using System; + +using NHibernate.Bytecode; +using NHibernate.Properties; +using NHibernate.Type; + +using Spring.Objects.Factory; + +#endregion + +namespace Spring.Data.NHibernate.Bytecode +{ + /// + /// + /// + /// Fabio Maulo + public class BytecodeProvider : IBytecodeProvider + { + private readonly IListableObjectFactory listableObjectFactory; + private readonly IObjectsFactory objectsFactory; + private readonly DefaultCollectionTypeFactory collectionTypefactory; + + /// + /// + /// + public BytecodeProvider(IListableObjectFactory listableObjectFactory) + { + this.listableObjectFactory = listableObjectFactory; + objectsFactory = new ObjectsFactory(listableObjectFactory); + collectionTypefactory = new DefaultCollectionTypeFactory(); + } + + /// + /// Retrieve the delegate for this provider + /// capable of generating reflection optimization components. + /// + /// The class to be reflected upon.All property getters to be accessed via reflection.All property setters to be accessed via reflection. + /// The reflection optimization delegate. + public IReflectionOptimizer GetReflectionOptimizer(Type clazz, IGetter[] getters, ISetter[] setters) + { + return new ReflectionOptimizer(listableObjectFactory, clazz, getters, setters); + } + + /// + /// The specific factory for this provider capable of + /// generating run-time proxies for lazy-loading purposes. + /// + public IProxyFactoryFactory ProxyFactoryFactory + { + get { return new ProxyFactoryFactory(); } + } + + /// + /// NHibernate's object instaciator. + /// + /// + /// For entities and its implementations. + /// + public IObjectsFactory ObjectsFactory + { + get { return objectsFactory; } + } + + /// + /// Instanciator of NHibernate's collections default types. + /// + public ICollectionTypeFactory CollectionTypeFactory + { + get { return collectionTypefactory; } + } + + } +} \ No newline at end of file diff --git a/src/Spring/Spring.Data.NHibernate21/Data/NHibernate/Bytecode/LazyInitializer.cs b/src/Spring/Spring.Data.NHibernate21/Data/NHibernate/Bytecode/LazyInitializer.cs new file mode 100644 index 00000000..036bab25 --- /dev/null +++ b/src/Spring/Spring.Data.NHibernate21/Data/NHibernate/Bytecode/LazyInitializer.cs @@ -0,0 +1,136 @@ +#if NH_2_1 +#region License + +/* + * Copyright © 2002-2005 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 + +#region Imports +using System; +using System.Reflection; + +using AopAlliance.Intercept; + +using NHibernate.Engine; +using NHibernate.Proxy.Poco; +using NHibernate.Type; + +using Spring.Aop; +using Spring.Reflection.Dynamic; + +#endregion + +namespace Spring.Data.NHibernate.Bytecode +{ + /// + /// + /// + /// Fabio Maulo + [Serializable] + public class LazyInitializer : BasicLazyInitializer, IMethodInterceptor, ITargetSource + { + private static readonly MethodInfo exceptionInternalPreserveStackTrace = + typeof(Exception).GetMethod("InternalPreserveStackTrace", BindingFlags.Instance | BindingFlags.NonPublic); + + /// + /// + /// + /// + /// + /// + /// + /// + /// + public LazyInitializer(string entityName, Type persistentClass, object id, MethodInfo getIdentifierMethod, + MethodInfo setIdentifierMethod, IAbstractComponentType componentIdType, + ISessionImplementor session) + : base( + entityName, persistentClass.IsInterface ? typeof(object) : persistentClass, id, getIdentifierMethod, + setIdentifierMethod, componentIdType, session) { } + + #region Implementation of IInterceptor + + /// + /// Implement this method to perform extra treatments before and after + /// the call to the supplied . + /// + /// + ///

+ /// Polite implementations would certainly like to invoke + /// . + ///

+ ///
+ /// + /// The method invocation that is being intercepted. + /// + /// + /// The result of the call to the + /// method of + /// the supplied ; this return value may + /// well have been intercepted by the interceptor. + /// + /// + /// If any of the interceptors in the chain or the target object itself + /// throws an exception. + /// + public object Invoke(IMethodInvocation invocation) + { + try + { + MethodInfo methodInfo = invocation.Method; + object returnValue = base.Invoke(methodInfo, invocation.Arguments, invocation.Proxy); + + if (returnValue != InvokeImplementation) + { + return returnValue; + } + + SafeMethod method = new SafeMethod(methodInfo); + return method.Invoke(GetImplementation(), invocation.Arguments); + } + catch (TargetInvocationException ex) + { + exceptionInternalPreserveStackTrace.Invoke(ex.InnerException, new Object[] { }); + throw ex.InnerException; + } + } + + #endregion + + #region Implementation of ITargetSource + + object ITargetSource.GetTarget() + { + return Target; + } + + void ITargetSource.ReleaseTarget(object target) { } + + Type ITargetSource.TargetType + { + get { return PersistentClass; } + } + + bool ITargetSource.IsStatic + { + get { return false; } + } + + #endregion + } +} +#endif \ No newline at end of file diff --git a/src/Spring/Spring.Data.NHibernate21/Data/NHibernate/Bytecode/ObjectsFactory.cs b/src/Spring/Spring.Data.NHibernate21/Data/NHibernate/Bytecode/ObjectsFactory.cs new file mode 100644 index 00000000..110d70c2 --- /dev/null +++ b/src/Spring/Spring.Data.NHibernate21/Data/NHibernate/Bytecode/ObjectsFactory.cs @@ -0,0 +1,84 @@ +#if NH_2_1 +#region License + +/* + * Copyright © 2002-2005 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 + +#region Imports + +using System; + +using NHibernate.Bytecode; + +using Spring.Objects.Factory; + +#endregion + +namespace Spring.Data.NHibernate.Bytecode +{ + /// + /// + /// + /// Fabio Maulo + public class ObjectsFactory : IObjectsFactory + { + private readonly IListableObjectFactory listableObjectFactory; + + /// + /// + /// + public ObjectsFactory(IListableObjectFactory listableObjectFactory) + { + this.listableObjectFactory = listableObjectFactory; + } + + /// + /// Creates an instance of the specified type. + /// + /// The type of object to create. + /// A reference to the created object. + public object CreateInstance(Type type) + { + string[] namesForType = listableObjectFactory.GetObjectNamesForType(type); + return namesForType.Length > 0 ? listableObjectFactory.GetObject(namesForType[0], type) : Activator.CreateInstance(type); + } + + /// + /// Creates an instance of the specified type. + /// + /// The type of object to create.true if a public or nonpublic default constructor can match; false if only a public default constructor can match. + /// A reference to the created object + public object CreateInstance(Type type, bool nonPublic) + { + string[] namesForType = listableObjectFactory.GetObjectNamesForType(type); + return namesForType.Length > 0 ? listableObjectFactory.GetObject(namesForType[0], type) : Activator.CreateInstance(type); + } + + /// + /// Creates an instance of the specified type using the constructor that best matches the specified parameters. + /// + /// The type of object to create.An array of constructor arguments. + /// A reference to the created object. + public object CreateInstance(Type type, params object[] ctorArgs) + { + return Activator.CreateInstance(type, ctorArgs); + } + + } +} +#endif \ No newline at end of file diff --git a/src/Spring/Spring.Data.NHibernate21/Data/NHibernate/Bytecode/ProxyFactory.cs b/src/Spring/Spring.Data.NHibernate21/Data/NHibernate/Bytecode/ProxyFactory.cs new file mode 100644 index 00000000..8e71d7f3 --- /dev/null +++ b/src/Spring/Spring.Data.NHibernate21/Data/NHibernate/Bytecode/ProxyFactory.cs @@ -0,0 +1,91 @@ +#if NH_2_1 +using System; + +#region License + +/* + * Copyright © 2002-2005 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 + +#region Imports + +using Common.Logging; + +using NHibernate; +using NHibernate.Engine; +using NHibernate.Proxy; + +#endregion + +namespace Spring.Data.NHibernate.Bytecode +{ + /// + /// A Spring for .NET backed implementation for creating + /// NHibernate proxies. + /// + /// + /// Erich Eichinger + public class ProxyFactory : AbstractProxyFactory + { + private static readonly ILog log = LogManager.GetLogger(typeof(ProxyFactory)); + + [Serializable] + private class SerializableProxyFactory : global::Spring.Aop.Framework.ProxyFactory + { + // ensure proxy types are generated as Serializable + public override bool IsSerializable + { + get { return true; } + } + } + + #region IProxyFactory Members + + /// + /// Creates a new proxy. + /// + /// The id value for the proxy to be generated. + /// The session to which the generated proxy will be associated. + /// The generated proxy. + /// Indicates problems generating requested proxy. + public override INHibernateProxy GetProxy(object id, ISessionImplementor session) + { + try + { + LazyInitializer initializer = new LazyInitializer(EntityName, PersistentClass.IsInterface ? typeof(object) : PersistentClass, + id, GetIdentifierMethod, SetIdentifierMethod, ComponentIdType, session); + + SerializableProxyFactory proxyFactory = new SerializableProxyFactory(); + proxyFactory.Interfaces = Interfaces; + proxyFactory.TargetSource = initializer; + proxyFactory.ProxyTargetType = IsClassProxy; + proxyFactory.AddAdvice(initializer); + + object proxyInstance = proxyFactory.GetProxy(); + return (INHibernateProxy)proxyInstance; + } + catch (Exception ex) + { + log.Error("Creating a proxy instance failed", ex); + throw new HibernateException("Creating a proxy instance failed", ex); + } + } + + #endregion + } +} +#endif \ No newline at end of file diff --git a/src/Spring/Spring.Data.NHibernate21/Data/NHibernate/Bytecode/ProxyFactoryFactory.cs b/src/Spring/Spring.Data.NHibernate21/Data/NHibernate/Bytecode/ProxyFactoryFactory.cs new file mode 100644 index 00000000..dbfda121 --- /dev/null +++ b/src/Spring/Spring.Data.NHibernate21/Data/NHibernate/Bytecode/ProxyFactoryFactory.cs @@ -0,0 +1,58 @@ +#if NH_2_1 +#region License + +/* + * Copyright © 2002-2005 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 + +#region Imports + +using NHibernate.Bytecode; +using NHibernate.Proxy; + +#endregion + +namespace Spring.Data.NHibernate.Bytecode +{ + /// + /// Creates a Spring for .NET backed instance. + /// + /// Erich Eichinger + public class ProxyFactoryFactory : IProxyFactoryFactory + { + #region IProxyFactoryFactory Members + + /// + /// Build a proxy factory specifically for handling runtime lazy loading. + /// + /// The lazy-load proxy factory. + public IProxyFactory BuildProxyFactory() + { + return new ProxyFactory(); + } + + /// + /// + public IProxyValidator ProxyValidator + { + get { return new DynProxyTypeValidator(); } + } + + #endregion + } +} +#endif \ No newline at end of file diff --git a/src/Spring/Spring.Data.NHibernate21/Data/NHibernate/Bytecode/ReflectionOptimizer.cs b/src/Spring/Spring.Data.NHibernate21/Data/NHibernate/Bytecode/ReflectionOptimizer.cs new file mode 100644 index 00000000..0161a04d --- /dev/null +++ b/src/Spring/Spring.Data.NHibernate21/Data/NHibernate/Bytecode/ReflectionOptimizer.cs @@ -0,0 +1,81 @@ +#if NH_2_1 +#region License + +/* + * Copyright © 2002-2005 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 + +#region Imports + +using System; + +using NHibernate.Properties; + +using Spring.Objects.Factory; + +#endregion + +namespace Spring.Data.NHibernate.Bytecode +{ + /// + /// + /// + /// Fabio Maulo + public class ReflectionOptimizer : global::NHibernate.Bytecode.Lightweight.ReflectionOptimizer + { + private readonly IListableObjectFactory listableObjectFactory; + + /// + /// + /// + /// + /// + /// + public ReflectionOptimizer(IListableObjectFactory listableObjectFactory, Type mappedType, IGetter[] getters, + ISetter[] setters) + : base(mappedType, getters, setters) + { + this.listableObjectFactory = listableObjectFactory; + } + + /// + /// Perform instantiation of an instance of the underlying class. + /// + /// The new instance. + public override object CreateInstance() + { + string[] namesForType = listableObjectFactory.GetObjectNamesForType(mappedType); + if (namesForType.Length > 0) + { + return listableObjectFactory.GetObject(namesForType[0], mappedType); + } + else + { + return base.CreateInstance(); + } + } + + /// + /// + /// + /// + protected override void ThrowExceptionForNoDefaultCtor(Type type) + { + } + } +} +#endif \ No newline at end of file diff --git a/src/Spring/Spring.Data.NHibernate21/Spring.Data.NHibernate21.2008.csproj b/src/Spring/Spring.Data.NHibernate21/Spring.Data.NHibernate21.2008.csproj index 87bc6616..ae440f17 100644 --- a/src/Spring/Spring.Data.NHibernate21/Spring.Data.NHibernate21.2008.csproj +++ b/src/Spring/Spring.Data.NHibernate21/Spring.Data.NHibernate21.2008.csproj @@ -148,6 +148,12 @@ Data\NHibernate\LocalSessionFactoryObject.cs + + + + + + diff --git a/test/Spring/Spring.Data.NHibernate.Tests/Data/NHibernate/LocalSessionFactoryObjectTests.cs b/test/Spring/Spring.Data.NHibernate.Tests/Data/NHibernate/LocalSessionFactoryObjectTests.cs index 6fc9cf4d..6c1569ac 100644 --- a/test/Spring/Spring.Data.NHibernate.Tests/Data/NHibernate/LocalSessionFactoryObjectTests.cs +++ b/test/Spring/Spring.Data.NHibernate.Tests/Data/NHibernate/LocalSessionFactoryObjectTests.cs @@ -24,7 +24,7 @@ using System.Collections; using System.IO; using NHibernate; #if NH_2_1 -using NHibernate.ByteCode.LinFu; +using Spring.Data.NHibernate.Bytecode; #endif using NHibernate.Cfg; using NHibernate.Connection; @@ -32,6 +32,7 @@ using NHibernate.Dialect; using NHibernate.Driver; using NUnit.Framework; + using Spring.Data.Common; #endregion @@ -57,9 +58,7 @@ namespace Spring.Data.NHibernate properties.Add(Environment.Dialect, typeof(MsSql2000Dialect).AssemblyQualifiedName); properties.Add(Environment.ConnectionDriver, typeof(SqlClientDriver).AssemblyQualifiedName); properties.Add(Environment.ConnectionProvider, typeof(DriverConnectionProvider).AssemblyQualifiedName); -#if NH_2_1 - properties.Add(Environment.ProxyFactoryFactoryClass, typeof(ProxyFactoryFactory).AssemblyQualifiedName); -#endif + sfo.HibernateProperties = properties; sfo.AfterPropertiesSet(); diff --git a/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Data/NHibernate/MultipleDbTests.xml b/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Data/NHibernate/MultipleDbTests.xml index a7a84679..ea2d13b2 100644 --- a/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Data/NHibernate/MultipleDbTests.xml +++ b/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Data/NHibernate/MultipleDbTests.xml @@ -29,9 +29,6 @@ - - @@ -56,9 +53,6 @@ - - diff --git a/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Data/NHibernate/NHDAOTests.xml b/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Data/NHibernate/NHDAOTests.xml index 65820aa1..a3db5357 100644 --- a/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Data/NHibernate/NHDAOTests.xml +++ b/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Data/NHibernate/NHDAOTests.xml @@ -33,9 +33,6 @@ - - diff --git a/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Data/NHibernate/dbProviderTemplateTests.xml b/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Data/NHibernate/dbProviderTemplateTests.xml index 270070b2..a1056203 100644 --- a/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Data/NHibernate/dbProviderTemplateTests.xml +++ b/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Data/NHibernate/dbProviderTemplateTests.xml @@ -55,9 +55,6 @@ --> - - diff --git a/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Data/NHibernate/templateTests.xml b/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Data/NHibernate/templateTests.xml index d14de685..e6a135ed 100644 --- a/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Data/NHibernate/templateTests.xml +++ b/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Data/NHibernate/templateTests.xml @@ -53,9 +53,6 @@ - - diff --git a/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Spring.Data.NHibernate21.Integration.Tests.2008.csproj b/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Spring.Data.NHibernate21.Integration.Tests.2008.csproj index c0056cfd..e106d4cb 100644 --- a/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Spring.Data.NHibernate21.Integration.Tests.2008.csproj +++ b/test/Spring/Spring.Data.NHibernate21.Integration.Tests/Spring.Data.NHibernate21.Integration.Tests.2008.csproj @@ -2,7 +2,7 @@ Debug AnyCPU - 9.0.21022 + 9.0.30729 2.0 {4A07E150-ED90-407C-8CAD-4760444DDFD9} Library @@ -36,10 +36,6 @@ False ..\..\..\lib\NHibernate21\net\2.0\Iesi.Collections.dll - - False - ..\..\..\lib\NHibernate21\net\2.0\LinFu.DynamicProxy.dll - False ..\..\..\lib\NHibernate21\net\2.0\log4net.dll @@ -48,10 +44,6 @@ False ..\..\..\lib\NHibernate21\net\2.0\NHibernate.dll - - False - ..\..\..\lib\NHibernate21\net\2.0\NHibernate.ByteCode.LinFu.dll - False ..\..\..\lib\Net\2.0\nunit.framework.dll diff --git a/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/AbstractInjectableUserTypeFixture.cs b/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/AbstractInjectableUserTypeFixture.cs new file mode 100644 index 00000000..e6f35d05 --- /dev/null +++ b/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/AbstractInjectableUserTypeFixture.cs @@ -0,0 +1,108 @@ +#if NH_2_1XX +using log4net.Config; + +using NHibernate.Bytecode; +using NHibernate.Cfg; +using NHibernate.Engine; +using NHibernate.Tool.hbm2ddl; + +using NUnit.Framework; + +namespace Spring.Data.NHibernate.Bytecode +{ + public abstract class AbstractInjectableUserTypeFixture + { + protected ISessionFactoryImplementor sessions; + + static AbstractInjectableUserTypeFixture() + { + XmlConfigurator.Configure(); + } + + /// + /// Initialize the ServiceLocator registering all services needed by this test. + /// + /// + /// Services needed, in this test, are: + /// + /// - uNhAddIns.Adapters.CommonTests.EnhancedBytecodeProvider.IDelimiter + /// Implementation: uNhAddIns.Adapters.CommonTests.EnhancedBytecodeProvider.ParenDelimiter + /// + /// - uNhAddIns.Adapters.CommonTests.EnhancedBytecodeProvider.InjectableStringUserType + /// + protected abstract void InitializeServiceLocator(); + + protected abstract IBytecodeProvider GetBytecodeProvider(); + + [Ignore("Work in progress")] + [TestFixtureSetUp] + public void CreateDb() + { + InitializeServiceLocator(); + var cfg = new Configuration(); + Environment.BytecodeProvider = GetBytecodeProvider(); + cfg.Configure(); + cfg.AddResource("uNhAddIns.Adapters.CommonTests.EnhancedBytecodeProvider.Foo.Spechbm.xml", + typeof(AbstractInjectableUserTypeFixture).Assembly); + new SchemaExport(cfg).Create(false, true); + sessions = (ISessionFactoryImplementor)cfg.BuildSessionFactory(); + } + + [Ignore("Work in progress")] + [TestFixtureTearDown] + public void CloseSessionFactory() + { + if (sessions != null) + { + sessions.Dispose(); + } + sessions = null; + } + + [Ignore("Work in progress")] + [Test] + public void SaveObjectWithStringChangedToUpper() + { + object savedId; + Foo f = new Foo { Description = "something" }; + + using (var s = sessions.OpenSession()) + using (var tx = s.BeginTransaction()) + { + savedId = s.Save(f); + tx.Commit(); + } + + using (var s = sessions.OpenSession()) + { + var upperFoo = s.Get(savedId); + + Assert.AreEqual("[something]", upperFoo.Description); + } + } + + [Ignore("Work in progress")] + [Test] + public void SaveNullPropertyAndGetItBack() + { + object savedId; + var f = new Foo(); + + using (var s = sessions.OpenSession()) + using (var tx = s.BeginTransaction()) + { + savedId = s.Save(f); + tx.Commit(); + } + + using (var s = sessions.OpenSession()) + { + var upperFoo = s.Get(savedId); + + Assert.IsNull(upperFoo.Description); + } + } + + } +} +#endif \ No newline at end of file diff --git a/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/Foo.Spechbm.xml b/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/Foo.Spechbm.xml new file mode 100644 index 00000000..31c08dbf --- /dev/null +++ b/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/Foo.Spechbm.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/Foo.cs b/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/Foo.cs new file mode 100644 index 00000000..d48d07e8 --- /dev/null +++ b/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/Foo.cs @@ -0,0 +1,9 @@ +#if NH_2_1XX +namespace Spring.Data.NHibernate.Bytecode +{ + public class Foo + { + public virtual string Description { get; set; } + } +} +#endif \ No newline at end of file diff --git a/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/IDelimiter.cs b/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/IDelimiter.cs new file mode 100644 index 00000000..be91aff4 --- /dev/null +++ b/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/IDelimiter.cs @@ -0,0 +1,25 @@ +#if NH_2_1XX +namespace Spring.Data.NHibernate.Bytecode +{ + public interface IDelimiter + { + string Delimit(string source); + } + + public class ParenDelimiter: IDelimiter + { + public string Delimit(string source) + { + return !source.StartsWith("[") ? string.Format("[{0}]", source) : source; + } + } + + public class NoOpDelimiter: IDelimiter + { + public string Delimit(string source) + { + return source; + } + } +} +#endif \ No newline at end of file diff --git a/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/InjectableStringUserType.cs b/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/InjectableStringUserType.cs new file mode 100644 index 00000000..eec8f25f --- /dev/null +++ b/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/InjectableStringUserType.cs @@ -0,0 +1,90 @@ +#if NH_2_1XX +using System.Data; +using NHibernate; +using NHibernate.SqlTypes; +using NHibernate.UserTypes; + +namespace Spring.Data.NHibernate.Bytecode +{ + public class InjectableStringUserType : IUserType + { + private readonly IDelimiter delimiter; + + public InjectableStringUserType(IDelimiter delimiter) + { + this.delimiter = delimiter; + } + + public object NullSafeGet(IDataReader rs, string[] names, object owner) + { + var resultString = (string)NHibernateUtil.String.NullSafeGet(rs, names[0]); + if (resultString != null) + return delimiter.Delimit(resultString); + return null; + } + + public void NullSafeSet(IDbCommand cmd, object value, int index) + { + if (value == null) + { + NHibernateUtil.String.NullSafeSet(cmd, null, index); + return; + } + + value = delimiter.Delimit((string)value); + + NHibernateUtil.String.NullSafeSet(cmd, value, index); + } + + public object DeepCopy(object value) + { + if (value == null) return null; + return string.Copy((string)value); + } + + public object Replace(object original, object target, object owner) + { + return original; + } + + public object Assemble(object cached, object owner) + { + return DeepCopy(cached); + } + + public object Disassemble(object value) + { + return DeepCopy(value); + } + + public SqlType[] SqlTypes + { + get + { + return new[] { new SqlType(DbType.String) }; + } + } + + public System.Type ReturnedType + { + get { return typeof(string); } + } + + public bool IsMutable + { + get { return false; } + } + + public new bool Equals(object x, object y) + { + if (x == null || y == null) return false; + return x.Equals(y); + } + + public int GetHashCode(object x) + { + return x.GetHashCode(); + } + } +} +#endif \ No newline at end of file diff --git a/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/InjectableUserTypeFixture.cs b/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/InjectableUserTypeFixture.cs new file mode 100644 index 00000000..866edd1b --- /dev/null +++ b/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/InjectableUserTypeFixture.cs @@ -0,0 +1,49 @@ +#if NH_2_1XX +using NHibernate.Bytecode; + +using NUnit.Framework; + +using Spring.Context; +using Spring.Context.Support; +using Spring.Objects.Factory.Config; +using Spring.Objects.Factory.Support; + +namespace Spring.Data.NHibernate.Bytecode +{ + //[TestFixture] + public class InjectableUserTypeFixture : AbstractInjectableUserTypeFixture + { + private IConfigurableListableObjectFactory objectFactory; + private static readonly IObjectDefinitionFactory objectDefinitionFactory = new DefaultObjectDefinitionFactory(); + + protected override void InitializeServiceLocator() + { + IConfigurableApplicationContext context = new StaticApplicationContext(); + objectFactory = context.ObjectFactory; + + Register(objectFactory); + RegisterPrototype(objectFactory); + } + + protected override IBytecodeProvider GetBytecodeProvider() + { + return new BytecodeProvider(objectFactory); + } + + private static void Register(IConfigurableListableObjectFactory confObjFactory) + { + var odb = ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory, typeof (TImplementation)). + SetAutowireMode(AutoWiringMode.Constructor); + confObjFactory.RegisterObjectDefinition(typeof (TSerivice).FullName, odb.ObjectDefinition); + } + + private static void RegisterPrototype(IConfigurableListableObjectFactory confObjFactory) + { + var odb = ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory, typeof(TImplementation)) + .SetSingleton(false).SetAutowireMode(AutoWiringMode.AutoDetect); + confObjFactory.RegisterObjectDefinition(typeof(TImplementation).FullName, odb.ObjectDefinition); + } + } +} + +#endif \ No newline at end of file diff --git a/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/Product.cs b/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/Product.cs new file mode 100644 index 00000000..fdb1832c --- /dev/null +++ b/test/Spring/Spring.Data.NHibernate21.Tests/Data/NHibernate/Bytecode/Product.cs @@ -0,0 +1,13 @@ +#if NH_2_1XX +using System; + +namespace Spring.Data.NHibernate.Bytecode +{ + public class Product + { + public virtual Guid Id { get; set; } + public virtual string Description { get; set; } + public virtual decimal Price { get; set; } + } +} +#endif \ No newline at end of file diff --git a/test/Spring/Spring.Data.NHibernate21.Tests/Spring.Data.NHibernate21.Tests.2008.csproj b/test/Spring/Spring.Data.NHibernate21.Tests/Spring.Data.NHibernate21.Tests.2008.csproj index eb1272b5..deb1756a 100644 --- a/test/Spring/Spring.Data.NHibernate21.Tests/Spring.Data.NHibernate21.Tests.2008.csproj +++ b/test/Spring/Spring.Data.NHibernate21.Tests/Spring.Data.NHibernate21.Tests.2008.csproj @@ -2,7 +2,7 @@ Debug AnyCPU - 9.0.21022 + 9.0.30729 2.0 {90FEE979-7367-4542-BCCB-BF634E04A9D3} Library @@ -36,10 +36,6 @@ False ..\..\..\lib\NHibernate21\net\2.0\Iesi.Collections.dll - - False - ..\..\..\lib\NHibernate21\net\2.0\LinFu.DynamicProxy.dll - False ..\..\..\lib\NHibernate21\net\2.0\log4net.dll @@ -48,10 +44,6 @@ False ..\..\..\lib\NHibernate21\net\2.0\NHibernate.dll - - False - ..\..\..\lib\NHibernate21\net\2.0\NHibernate.ByteCode.LinFu.dll - False ..\..\..\lib\net\2.0\nunit.framework.dll @@ -98,6 +90,12 @@ Data\NHibernate\TestObject.cs + + + + + + @@ -133,6 +131,9 @@ + + + - +