|
From: <fab...@us...> - 2010-07-20 17:45:14
|
Revision: 5020
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5020&view=rev
Author: fabiomaulo
Date: 2010-07-20 17:45:07 +0000 (Tue, 20 Jul 2010)
Log Message:
-----------
Fix NH-2093 (thanks to Johannes Gustafsson for the TEST)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Event/Default/AbstractSaveEventListener.cs
trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs
trunk/nhibernate/src/NHibernate/Intercept/DefaultFieldInterceptor.cs
trunk/nhibernate/src/NHibernate/Intercept/FieldInterceptionHelper.cs
trunk/nhibernate/src/NHibernate/Intercept/IFieldInterceptor.cs
trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs
trunk/nhibernate/src/NHibernate/Proxy/NHibernateProxyHelper.cs
trunk/nhibernate/src/NHibernate/Tuple/Entity/PocoEntityTuplizer.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Model.cs
Modified: trunk/nhibernate/src/NHibernate/Event/Default/AbstractSaveEventListener.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Event/Default/AbstractSaveEventListener.cs 2010-07-20 16:43:09 UTC (rev 5019)
+++ trunk/nhibernate/src/NHibernate/Event/Default/AbstractSaveEventListener.cs 2010-07-20 17:45:07 UTC (rev 5020)
@@ -292,7 +292,7 @@
{
if (FieldInterceptionHelper.IsInstrumented(entity))
{
- IFieldInterceptor interceptor = FieldInterceptionHelper.InjectFieldInterceptor(entity, persister.EntityName, null, null, source);
+ IFieldInterceptor interceptor = FieldInterceptionHelper.InjectFieldInterceptor(entity, persister.EntityName, persister.GetMappedClass(source.EntityMode), null, null, source);
interceptor.MarkDirty();
}
}
Modified: trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs 2010-07-20 16:43:09 UTC (rev 5019)
+++ trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs 2010-07-20 17:45:07 UTC (rev 5020)
@@ -16,17 +16,19 @@
private readonly ISet<string> unwrapProxyFieldNames;
private readonly ISet<string> loadedUnwrapProxyFieldNames = new HashedSet<string>();
private readonly string entityName;
+ private readonly System.Type mappedClass;
[NonSerialized]
private bool initializing;
private bool isDirty;
- protected internal AbstractFieldInterceptor(ISessionImplementor session, ISet<string> uninitializedFields, ISet<string> unwrapProxyFieldNames, string entityName)
+ protected internal AbstractFieldInterceptor(ISessionImplementor session, ISet<string> uninitializedFields, ISet<string> unwrapProxyFieldNames, string entityName, System.Type mappedClass)
{
this.session = session;
this.uninitializedFields = uninitializedFields;
this.unwrapProxyFieldNames = unwrapProxyFieldNames;
this.entityName = entityName;
+ this.mappedClass = mappedClass;
}
#region IFieldInterceptor Members
@@ -65,6 +67,16 @@
isDirty = false;
}
+ public string EntityName
+ {
+ get { return entityName; }
+ }
+
+ public System.Type MappedClass
+ {
+ get { return mappedClass; }
+ }
+
#endregion
public ISet<string> UninitializedFields
@@ -72,11 +84,6 @@
get { return uninitializedFields; }
}
- public string EntityName
- {
- get { return entityName; }
- }
-
public bool Initializing
{
get { return initializing; }
Modified: trunk/nhibernate/src/NHibernate/Intercept/DefaultFieldInterceptor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Intercept/DefaultFieldInterceptor.cs 2010-07-20 16:43:09 UTC (rev 5019)
+++ trunk/nhibernate/src/NHibernate/Intercept/DefaultFieldInterceptor.cs 2010-07-20 17:45:07 UTC (rev 5020)
@@ -5,8 +5,8 @@
{
public class DefaultFieldInterceptor : AbstractFieldInterceptor
{
- public DefaultFieldInterceptor(ISessionImplementor session, ISet<string> uninitializedFields, ISet<string> unwrapProxyFieldNames, string entityName)
- : base(session, uninitializedFields, unwrapProxyFieldNames, entityName)
+ public DefaultFieldInterceptor(ISessionImplementor session, ISet<string> uninitializedFields, ISet<string> unwrapProxyFieldNames, string entityName, System.Type mappedClass)
+ : base(session, uninitializedFields, unwrapProxyFieldNames, entityName, mappedClass)
{
}
}
Modified: trunk/nhibernate/src/NHibernate/Intercept/FieldInterceptionHelper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Intercept/FieldInterceptionHelper.cs 2010-07-20 16:43:09 UTC (rev 5019)
+++ trunk/nhibernate/src/NHibernate/Intercept/FieldInterceptionHelper.cs 2010-07-20 17:45:07 UTC (rev 5020)
@@ -33,6 +33,7 @@
}
public static IFieldInterceptor InjectFieldInterceptor(object entity, string entityName,
+ System.Type mappedClass,
ISet<string> uninitializedFieldNames,
ISet<string> unwrapProxyFieldNames,
ISessionImplementor session)
@@ -40,7 +41,7 @@
var fieldInterceptorAccessor = entity as IFieldInterceptorAccessor;
if (fieldInterceptorAccessor != null)
{
- var fieldInterceptorImpl = new DefaultFieldInterceptor(session, uninitializedFieldNames, unwrapProxyFieldNames, entityName);
+ var fieldInterceptorImpl = new DefaultFieldInterceptor(session, uninitializedFieldNames, unwrapProxyFieldNames, entityName, mappedClass);
fieldInterceptorAccessor.FieldInterceptor = fieldInterceptorImpl;
return fieldInterceptorImpl;
}
Modified: trunk/nhibernate/src/NHibernate/Intercept/IFieldInterceptor.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Intercept/IFieldInterceptor.cs 2010-07-20 16:43:09 UTC (rev 5019)
+++ trunk/nhibernate/src/NHibernate/Intercept/IFieldInterceptor.cs 2010-07-20 17:45:07 UTC (rev 5020)
@@ -29,5 +29,11 @@
/// <summary> Intercept field set/get </summary>
object Intercept(object target, string fieldName, object value);
+
+ /// <summary> Get the entity-name of the field DeclaringType.</summary>
+ string EntityName { get; }
+
+ /// <summary> Get the MappedClass (field container).</summary>
+ System.Type MappedClass { get; }
}
}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2010-07-20 16:43:09 UTC (rev 5019)
+++ trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2010-07-20 17:45:07 UTC (rev 5020)
@@ -3615,7 +3615,7 @@
}
else
{
- IFieldInterceptor fieldInterceptor = FieldInterceptionHelper.InjectFieldInterceptor(entity, EntityName, null, null, session);
+ IFieldInterceptor fieldInterceptor = FieldInterceptionHelper.InjectFieldInterceptor(entity, EntityName, GetMappedClass(session.EntityMode), null, null, session);
fieldInterceptor.MarkDirty();
}
}
Modified: trunk/nhibernate/src/NHibernate/Proxy/NHibernateProxyHelper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Proxy/NHibernateProxyHelper.cs 2010-07-20 16:43:09 UTC (rev 5019)
+++ trunk/nhibernate/src/NHibernate/Proxy/NHibernateProxyHelper.cs 2010-07-20 17:45:07 UTC (rev 5020)
@@ -1,3 +1,4 @@
+using NHibernate.Intercept;
using NHibernate.Persister.Entity;
namespace NHibernate.Proxy
@@ -44,7 +45,7 @@
/// </remarks>
public static System.Type GuessClass(object entity)
{
- INHibernateProxy proxy = entity as INHibernateProxy;
+ var proxy = entity as INHibernateProxy;
if (proxy != null)
{
ILazyInitializer li = proxy.HibernateLazyInitializer;
@@ -52,15 +53,15 @@
{
return li.PersistentClass;
}
- else
- {
- return li.GetImplementation().GetType();
- }
+ return li.GetImplementation().GetType();
}
- else
+ var fieldInterceptorAccessor = entity as IFieldInterceptorAccessor;
+ if (fieldInterceptorAccessor != null)
{
- return entity.GetType();
+ var fieldInterceptor = fieldInterceptorAccessor.FieldInterceptor;
+ return fieldInterceptor.MappedClass;
}
+ return entity.GetType();
}
}
}
Modified: trunk/nhibernate/src/NHibernate/Tuple/Entity/PocoEntityTuplizer.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Tuple/Entity/PocoEntityTuplizer.cs 2010-07-20 16:43:09 UTC (rev 5019)
+++ trunk/nhibernate/src/NHibernate/Tuple/Entity/PocoEntityTuplizer.cs 2010-07-20 17:45:07 UTC (rev 5020)
@@ -229,7 +229,7 @@
HashedSet<string> lazyProps = lazyPropertiesAreUnfetched && EntityMetamodel.HasLazyProperties ? lazyPropertyNames : null;
//TODO: if we support multiple fetch groups, we would need
// to clone the set of lazy properties!
- FieldInterceptionHelper.InjectFieldInterceptor(entity, EntityName, lazyProps, unwrapProxyPropertyNames, session);
+ FieldInterceptionHelper.InjectFieldInterceptor(entity, EntityName, this.MappedClass ,lazyProps, unwrapProxyPropertyNames, session);
}
}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Fixture.cs 2010-07-20 17:45:07 UTC (rev 5020)
@@ -0,0 +1,103 @@
+using System.Linq;
+using NHibernate.ByteCode.Castle;
+using NHibernate.Cfg;
+using NHibernate.Proxy;
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH2093
+ {
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+ protected override void Configure(Configuration configuration)
+ {
+ configuration.SetProperty(Environment.ProxyFactoryFactoryClass,
+ typeof(ProxyFactoryFactory).AssemblyQualifiedName);
+ }
+
+ [Test]
+ public void NHibernateProxyHelperReturnsCorrectType()
+ {
+ try
+ {
+ using (var s = OpenSession())
+ {
+ var person = new Person { Id = 1, Name = "Person1" };
+ var employee = new Employee { Id = 1, Name = "Emp1", Person = person };
+
+ s.Save(person);
+ s.Save(employee);
+
+ s.Flush();
+ }
+
+ using (var s = OpenSession())
+ {
+ var person = s.Load<Person>(1);
+
+ var type = NHibernateProxyHelper.GuessClass(person);
+
+ Assert.AreEqual(type, typeof(Person));
+ }
+
+ using (var s = OpenSession())
+ {
+ var person = s.Get<Person>(1);
+
+ var type = NHibernateProxyHelper.GuessClass(person);
+
+ Assert.AreEqual(type, typeof(Person));
+ }
+ }
+ finally
+ {
+ using (var s = OpenSession())
+ {
+ s.Delete("from Employee");
+ s.Delete("from Person");
+
+ s.Flush();
+ }
+ }
+ }
+
+ [Test]
+ public void CanUseFieldInterceptingProxyAsHQLArgument()
+ {
+ try
+ {
+ using (var s = OpenSession())
+ {
+ var person = new Person { Id = 1, Name = "Person1" };
+ var employee = new Employee { Id = 1, Name = "Emp1", Person = person };
+
+ s.Save(person);
+ s.Save(employee);
+
+ s.Flush();
+ }
+
+ using (var s = OpenSession())
+ {
+ var person = s.Get<Person>(1);
+
+ var list = s.CreateQuery("from Employee where Person = :p")
+ .SetEntity("p", person)
+ .List<Employee>();
+
+ Assert.AreEqual(list.Count, 1);
+ }
+ }
+ finally
+ {
+ using (var s = OpenSession())
+ {
+ s.Delete("from Employee");
+ s.Delete("from Person");
+
+ s.Flush();
+ }
+ }
+ }
+ }
+ }
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Mappings.hbm.xml 2010-07-20 17:45:07 UTC (rev 5020)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ assembly="NHibernate.Test"
+ namespace="NHibernate.Test.NHSpecificTest.NH2093">
+
+ <class name="Person">
+ <id name="Id"/>
+ <property name="Name"></property>
+ <property name="LazyField" lazy="true"></property>
+ </class>
+
+ <class name="Employee">
+ <id name="Id"/>
+ <property name="Name"></property>
+
+ <one-to-one name="Person" constrained="true" lazy="proxy"/>
+ </class>
+
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Model.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Model.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2093/Model.cs 2010-07-20 17:45:07 UTC (rev 5020)
@@ -0,0 +1,20 @@
+ using System.Collections.Generic;
+
+namespace NHibernate.Test.NHSpecificTest.NH2093
+ {
+ public class Person
+ {
+ public virtual int Id { get; set; }
+ public virtual string Name { get; set; }
+
+ public virtual string LazyField { get; set; }
+ }
+
+ public class Employee
+ {
+ public virtual int Id { get; set; }
+ public virtual string Name { get; set; }
+
+ public virtual Person Person { get; set; }
+ }
+ }
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-20 16:43:09 UTC (rev 5019)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-20 17:45:07 UTC (rev 5020)
@@ -457,6 +457,8 @@
<Compile Include="NHSpecificTest\NH2069\Test.cs" />
<Compile Include="NHSpecificTest\NH2069\Test2.cs" />
<Compile Include="NHSpecificTest\NH2069\TestBase.cs" />
+ <Compile Include="NHSpecificTest\NH2093\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH2093\Model.cs" />
<Compile Include="NHSpecificTest\NH2102\Fixture.cs" />
<Compile Include="NHSpecificTest\NH2102\Model.cs" />
<Compile Include="NHSpecificTest\NH2189\Fixture.cs" />
@@ -1689,11 +1691,6 @@
<Project>{5909BFE7-93CF-4E5F-BE22-6293368AF01D}</Project>
<Name>NHibernate</Name>
</ProjectReference>
- <Folder Include="Component" />
- <Folder Include="Component\Basic" />
- <Folder Include="NHSpecificTest\NH2061" />
- <Folder Include="NHSpecificTest\NH2195" />
- <Folder Include="TypedManyToOne" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="NHSpecificTest\NH386\Mappings.hbm.xml" />
@@ -2186,6 +2183,7 @@
<EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" />
<EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH2093\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2102\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2069\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2230\Mappings.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|