Brought NHibernate proxy and byte code providers from NHibernate & unhAddins, set LocalSessionFactoryObject to use Spring proxy factory factory be default and thus removed LinFu dependency from NH 2.1 use
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -29,9 +29,6 @@
|
||||
|
||||
<entry key="connection.driver_class"
|
||||
value="NHibernate.Driver.SqlClientDriver"/>
|
||||
|
||||
<entry key="proxyfactory.factory_class"
|
||||
value="NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu"/>
|
||||
</dictionary>
|
||||
</property>
|
||||
|
||||
@@ -56,9 +53,6 @@
|
||||
|
||||
<entry key="connection.driver_class"
|
||||
value="NHibernate.Driver.SqlClientDriver"/>
|
||||
|
||||
<entry key="proxyfactory.factory_class"
|
||||
value="NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu"/>
|
||||
|
||||
</dictionary>
|
||||
</property>
|
||||
|
||||
@@ -33,9 +33,6 @@
|
||||
<entry key="connection.driver_class"
|
||||
value="NHibernate.Driver.SqlClientDriver"/>
|
||||
|
||||
<entry key="proxyfactory.factory_class"
|
||||
value="NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu"/>
|
||||
|
||||
</dictionary>
|
||||
</property>
|
||||
|
||||
|
||||
@@ -55,9 +55,6 @@
|
||||
<entry key="hibernate.dialect"
|
||||
value="NHibernate.Dialect.Oracle9Dialect"/>
|
||||
-->
|
||||
|
||||
<entry key="proxyfactory.factory_class"
|
||||
value="NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu"/>
|
||||
</dictionary>
|
||||
</property>
|
||||
|
||||
|
||||
@@ -53,9 +53,6 @@
|
||||
<entry key="connection.driver_class"
|
||||
value="NHibernate.Driver.SqlClientDriver"/>
|
||||
|
||||
<entry key="proxyfactory.factory_class"
|
||||
value="NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu"/>
|
||||
|
||||
</dictionary>
|
||||
</property>
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{4A07E150-ED90-407C-8CAD-4760444DDFD9}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
@@ -36,10 +36,6 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\NHibernate21\net\2.0\Iesi.Collections.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="LinFu.DynamicProxy, Version=1.0.3.14911, Culture=neutral, PublicKeyToken=62a6874124340d6e, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\NHibernate21\net\2.0\LinFu.DynamicProxy.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\NHibernate21\net\2.0\log4net.dll</HintPath>
|
||||
@@ -48,10 +44,6 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\NHibernate21\net\2.0\NHibernate.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NHibernate.ByteCode.LinFu, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\NHibernate21\net\2.0\NHibernate.ByteCode.LinFu.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=2.4.1.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\Net\2.0\nunit.framework.dll</HintPath>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the ServiceLocator registering all services needed by this test.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Services needed, in this test, are:
|
||||
///
|
||||
/// - uNhAddIns.Adapters.CommonTests.EnhancedBytecodeProvider.IDelimiter
|
||||
/// Implementation: uNhAddIns.Adapters.CommonTests.EnhancedBytecodeProvider.ParenDelimiter
|
||||
///
|
||||
/// - uNhAddIns.Adapters.CommonTests.EnhancedBytecodeProvider.InjectableStringUserType
|
||||
/// </remarks>
|
||||
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<Foo>(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<Foo>(savedId);
|
||||
|
||||
Assert.IsNull(upperFoo.Description);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
|
||||
assembly="uNhAddIns.Adapters.CommonTests"
|
||||
namespace="uNhAddIns.Adapters.CommonTests.EnhancedBytecodeProvider">
|
||||
|
||||
<typedef name="SpecialString"
|
||||
class="InjectableStringUserType"/>
|
||||
|
||||
<class name ="Foo">
|
||||
<id type="int">
|
||||
<generator class="hilo"/>
|
||||
</id>
|
||||
<property name="Description" type="SpecialString" />
|
||||
</class>
|
||||
</hibernate-mapping>
|
||||
@@ -0,0 +1,9 @@
|
||||
#if NH_2_1XX
|
||||
namespace Spring.Data.NHibernate.Bytecode
|
||||
{
|
||||
public class Foo
|
||||
{
|
||||
public virtual string Description { get; set; }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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<IDelimiter, ParenDelimiter>(objectFactory);
|
||||
RegisterPrototype<InjectableStringUserType>(objectFactory);
|
||||
}
|
||||
|
||||
protected override IBytecodeProvider GetBytecodeProvider()
|
||||
{
|
||||
return new BytecodeProvider(objectFactory);
|
||||
}
|
||||
|
||||
private static void Register<TSerivice, TImplementation>(IConfigurableListableObjectFactory confObjFactory)
|
||||
{
|
||||
var odb = ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory, typeof (TImplementation)).
|
||||
SetAutowireMode(AutoWiringMode.Constructor);
|
||||
confObjFactory.RegisterObjectDefinition(typeof (TSerivice).FullName, odb.ObjectDefinition);
|
||||
}
|
||||
|
||||
private static void RegisterPrototype<TImplementation>(IConfigurableListableObjectFactory confObjFactory)
|
||||
{
|
||||
var odb = ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory, typeof(TImplementation))
|
||||
.SetSingleton(false).SetAutowireMode(AutoWiringMode.AutoDetect);
|
||||
confObjFactory.RegisterObjectDefinition(typeof(TImplementation).FullName, odb.ObjectDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -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
|
||||
@@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{90FEE979-7367-4542-BCCB-BF634E04A9D3}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
@@ -36,10 +36,6 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\NHibernate21\net\2.0\Iesi.Collections.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="LinFu.DynamicProxy, Version=1.0.3.14911, Culture=neutral, PublicKeyToken=62a6874124340d6e, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\NHibernate21\net\2.0\LinFu.DynamicProxy.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="log4net, Version=1.2.9.0, Culture=neutral, PublicKeyToken=b32731d11ce58905">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\NHibernate21\net\2.0\log4net.dll</HintPath>
|
||||
@@ -48,10 +44,6 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\NHibernate21\net\2.0\NHibernate.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NHibernate.ByteCode.LinFu, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\NHibernate21\net\2.0\NHibernate.ByteCode.LinFu.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=2.2.7.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\net\2.0\nunit.framework.dll</HintPath>
|
||||
@@ -98,6 +90,12 @@
|
||||
<Compile Include="..\Spring.Data.NHibernate.Tests\Data\NHibernate\TestObject.cs">
|
||||
<Link>Data\NHibernate\TestObject.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Data\NHibernate\Bytecode\AbstractInjectableUserTypeFixture.cs" />
|
||||
<Compile Include="Data\NHibernate\Bytecode\Foo.cs" />
|
||||
<Compile Include="Data\NHibernate\Bytecode\IDelimiter.cs" />
|
||||
<Compile Include="Data\NHibernate\Bytecode\InjectableStringUserType.cs" />
|
||||
<Compile Include="Data\NHibernate\Bytecode\InjectableUserTypeFixture.cs" />
|
||||
<Compile Include="Data\NHibernate\Bytecode\Product.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Spring.Data.NHibernate21.Tests.dll.config">
|
||||
@@ -133,6 +131,9 @@
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Data\NHibernate\TestObject.hbm.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Data\NHibernate\Bytecode\Foo.Spechbm.xml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
|
||||
<!-- copy nh libs -->
|
||||
<copy todir="${current.bin.dir}" overwrite="true">
|
||||
<fileset basedir="${nh.lib.dir}">
|
||||
<fileset basedir="${nh21.lib.dir}">
|
||||
<include name="**/*.dll" />
|
||||
</fileset>
|
||||
</copy>
|
||||
|
||||
Reference in New Issue
Block a user