|
From: <jul...@us...> - 2010-07-15 10:01:48
|
Revision: 5005
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5005&view=rev
Author: julian-maughan
Date: 2010-07-15 10:01:40 +0000 (Thu, 15 Jul 2010)
Log Message:
-----------
Bugfix: When touching the identifier of a proxy object a call to the database is executed (ref. NH-2069)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Util/ReflectHelper.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
trunk/nhibernate/src/NHibernate.Test/UtilityTest/ReflectHelperFixture.cs
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITest.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITest2.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITestBase.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Test.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Test2.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/TestBase.cs
Modified: trunk/nhibernate/src/NHibernate/Util/ReflectHelper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Util/ReflectHelper.cs 2010-07-12 21:48:46 UTC (rev 5004)
+++ trunk/nhibernate/src/NHibernate/Util/ReflectHelper.cs 2010-07-15 10:01:40 UTC (rev 5005)
@@ -476,42 +476,6 @@
return SafeGetMethod(type, method, tps);
}
- /// <summary>
- /// Try to find a method in a serie of given types.
- /// </summary>
- /// <param name="types">The serie of types where find.</param>
- /// <param name="method">The method info.</param>
- /// <returns>The found method or null.</returns>
- /// <remarks>
- /// The <paramref name="method"/>, in general, become from another <see cref="Type"/>.
- /// </remarks>
- public static MethodInfo TryGetMethod(IEnumerable<System.Type> types, MethodInfo method)
- {
- // This method will be used when we support multiple proxy interfaces.
- if (types == null)
- {
- throw new ArgumentNullException("types");
- }
- if (method == null)
- {
- return null;
- }
-
- System.Type[] tps = GetMethodSignature(method);
- MethodInfo result = null;
-
- foreach (var type in types)
- {
- result = SafeGetMethod(type, method, tps);
- if (result != null)
- {
- return result;
- }
- }
-
- return result;
- }
-
private static System.Type[] GetMethodSignature(MethodInfo method)
{
var pi = method.GetParameters();
@@ -527,14 +491,39 @@
{
const BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
+ List<System.Type> typesToSearch = new List<System.Type>();
+ MethodInfo foundMethod = null;
+
try
- {
- return type.GetMethod(method.Name, bindingFlags, null, tps, null);
+ {
+ typesToSearch.Add(type);
+
+ if (type.IsInterface)
+ {
+ // Methods on parent interfaces are not actually inherited
+ // by child interfaces, so we have to use GetInterfaces to
+ // identify any parent interfaces that may contain the
+ // method implementation
+ System.Type[] inheritedInterfaces = type.GetInterfaces();
+ typesToSearch.AddRange(inheritedInterfaces);
+ }
+
+ foreach (System.Type typeToSearch in typesToSearch)
+ {
+ MethodInfo result = typeToSearch.GetMethod(method.Name, bindingFlags, null, tps, null);
+ if (result != null)
+ {
+ foundMethod = result;
+ break;
+ }
+ }
}
catch (Exception)
{
- return null;
+ throw;
}
+
+ return foundMethod;
}
internal static object GetConstantValue(string qualifiedName)
Property changes on: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069
___________________________________________________________________
Added: bugtraq:url
+ http://jira.nhibernate.org/browse/%BUGID%
Added: bugtraq:logregex
+ NH-\d+
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Fixture.cs 2010-07-15 10:01:40 UTC (rev 5005)
@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Transactions;
+using NHibernate;
+using NHibernate.Impl;
+using NHibernate.Proxy;
+using NHibernate.Criterion;
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH2069
+{
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+ protected override void OnSetUp()
+ {
+ using (var s = OpenSession())
+ using (s.BeginTransaction())
+ {
+ var test2 = new Test2();
+ test2.Cid = 5;
+ test2.Description = "Test 2: CID = 5";
+
+ var test = new Test();
+ test.Cid = 1;
+ test.Description = "Test: CID = 1";
+ test.Category = test2;
+
+ s.Save(test2);
+ s.Save(test);
+
+ s.Transaction.Commit();
+ }
+ }
+
+ protected override void OnTearDown()
+ {
+ using (var s = OpenSession())
+ using (s.BeginTransaction())
+ {
+ s.Delete("from Test");
+ s.Delete("from Test2");
+ s.Transaction.Commit();
+ }
+ }
+
+ [Test]
+ public void ProxyRemainsUninitializedWhenReferencingIdProperty()
+ {
+ using (ISession session = base.OpenSession())
+ {
+ ITest b = session.CreateQuery("from Test").UniqueResult<Test>();
+
+ Assert.IsNotNull(b);
+
+ INHibernateProxy proxy = b.Category as INHibernateProxy;
+
+ Assert.That(proxy, Is.Not.Null);
+
+ Assert.That(proxy.HibernateLazyInitializer.IsUninitialized, "Proxy should be uninitialized.");
+
+ long cid = b.Category.Cid;
+
+ Assert.That(proxy.HibernateLazyInitializer.IsUninitialized, "Proxy should still be uninitialized.");
+ }
+ }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITest.cs 2010-07-15 10:01:40 UTC (rev 5005)
@@ -0,0 +1,10 @@
+using System;
+
+namespace NHibernate.Test.NHSpecificTest.NH2069
+{
+ public interface ITest : ITestBase
+ {
+ string Description { get; set;}
+ ITest2 Category { get; set; }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITest2.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITest2.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITest2.cs 2010-07-15 10:01:40 UTC (rev 5005)
@@ -0,0 +1,9 @@
+using System;
+
+namespace NHibernate.Test.NHSpecificTest.NH2069
+{
+ public interface ITest2 : ITestBase
+ {
+ string Description { get; set; }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITestBase.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITestBase.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/ITestBase.cs 2010-07-15 10:01:40 UTC (rev 5005)
@@ -0,0 +1,9 @@
+using System;
+
+namespace NHibernate.Test.NHSpecificTest.NH2069
+{
+ public interface ITestBase
+ {
+ Int64 Cid { get; set; }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Mappings.hbm.xml 2010-07-15 10:01:40 UTC (rev 5005)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping
+ xmlns="urn:nhibernate-mapping-2.2"
+ assembly="NHibernate.Test"
+ namespace="NHibernate.Test.NHSpecificTest.NH2069"
+ default-lazy="true">
+
+ <class name="Test" table="Test" proxy="ITest">
+ <id column="cid" name="Cid" type="Int64" >
+ <generator class="native" />
+ </id>
+ <many-to-one name="Category" class="Test2" column="Test2_Cid" not-null="true"/>
+ <property name="Description" column="Description" type="String" length="255"/>
+ </class>
+
+ <class name="Test2" table="Test2" proxy="ITest2">
+ <id column="cid" name="Cid" type="Int64">
+ <generator class="native" />
+ </id>
+ <property name="Description" column="Description" type="String" length="255"/>
+ </class>
+
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Test.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Test.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Test.cs 2010-07-15 10:01:40 UTC (rev 5005)
@@ -0,0 +1,13 @@
+using System;
+
+namespace NHibernate.Test.NHSpecificTest.NH2069
+{
+ public class Test : TestBase, ITest
+ {
+ public Test() { }
+
+ public string Description { get; set; }
+
+ public ITest2 Category { get; set; }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Test2.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Test2.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/Test2.cs 2010-07-15 10:01:40 UTC (rev 5005)
@@ -0,0 +1,13 @@
+using System;
+
+namespace NHibernate.Test.NHSpecificTest.NH2069
+{
+ public class Test2 : ITest2
+ {
+ public Test2() { }
+
+ public Int64 Cid { get; set; } //When using this property it works fine.
+
+ public string Description { get; set; }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/TestBase.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/TestBase.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2069/TestBase.cs 2010-07-15 10:01:40 UTC (rev 5005)
@@ -0,0 +1,9 @@
+using System;
+
+namespace NHibernate.Test.NHSpecificTest.NH2069
+{
+ public class TestBase : ITestBase
+ {
+ public Int64 Cid { get; set; }
+ }
+}
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-12 21:48:46 UTC (rev 5004)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-07-15 10:01:40 UTC (rev 5005)
@@ -443,6 +443,13 @@
<Compile Include="NHSpecificTest\CriteriaQueryOnComponentCollection\Employee.cs" />
<Compile Include="NHSpecificTest\CriteriaQueryOnComponentCollection\Fixture.cs" />
<Compile Include="NHSpecificTest\CriteriaQueryOnComponentCollection\Money.cs" />
+ <Compile Include="NHSpecificTest\NH2069\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH2069\ITest.cs" />
+ <Compile Include="NHSpecificTest\NH2069\ITest2.cs" />
+ <Compile Include="NHSpecificTest\NH2069\ITestBase.cs" />
+ <Compile Include="NHSpecificTest\NH2069\Test.cs" />
+ <Compile Include="NHSpecificTest\NH2069\Test2.cs" />
+ <Compile Include="NHSpecificTest\NH2069\TestBase.cs" />
<Compile Include="NHSpecificTest\NH2189\Fixture.cs" />
<Compile Include="NHSpecificTest\NH2189\Model.cs" />
<Compile Include="NHSpecificTest\ElementsEnums\AbstractIntEnumsBagFixture.cs" />
@@ -2155,6 +2162,7 @@
<EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" />
<EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH2069\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2230\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2189\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2201\Mappings.hbm.xml" />
Modified: trunk/nhibernate/src/NHibernate.Test/UtilityTest/ReflectHelperFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/UtilityTest/ReflectHelperFixture.cs 2010-07-12 21:48:46 UTC (rev 5004)
+++ trunk/nhibernate/src/NHibernate.Test/UtilityTest/ReflectHelperFixture.cs 2010-07-15 10:01:40 UTC (rev 5005)
@@ -114,32 +114,8 @@
Assert.That(ReflectHelper.TryGetMethod(typeof(IMyBaseInterface), mng), Is.Not.Null);
Assert.That(ReflectHelper.TryGetMethod(typeof(IMyBaseInterface), mns), Is.Not.Null);
- mig = typeof(MyImplementation).GetMethod("get_Id", bf);
- mis = typeof(MyImplementation).GetMethod("set_Id", bf);
- mng = typeof(MyImplementation).GetMethod("get_Name", bf);
- mns = typeof(MyImplementation).GetMethod("set_Name", bf);
- MethodInfo mdg = typeof(MyImplementation).GetMethod("get_Description", bf);
- MethodInfo mds = typeof(MyImplementation).GetMethod("set_Description", bf);
- Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mig), Is.Not.Null);
- Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mis), Is.Null);
- Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mng), Is.Not.Null);
- Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mns), Is.Not.Null);
- Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mdg), Is.Not.Null);
- Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mds), Is.Null);
-
- MethodInfo mdig = typeof(MyDerivedImplementation).GetMethod("get_Id", bf);
- MethodInfo mdis = typeof(MyDerivedImplementation).GetMethod("set_Id", bf);
- MethodInfo mdng = typeof(MyDerivedImplementation).GetMethod("get_Name", bf);
- MethodInfo mdns = typeof(MyDerivedImplementation).GetMethod("set_Name", bf);
- MethodInfo mddg = typeof(MyDerivedImplementation).GetMethod("get_Description", bf);
- MethodInfo mdds = typeof(MyDerivedImplementation).GetMethod("set_Description", bf);
-
- Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mdig), Is.Not.Null);
- Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mdis), Is.Null);
- Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mdng), Is.Not.Null);
- Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mdns), Is.Not.Null);
- Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mddg), Is.Not.Null);
- Assert.That(ReflectHelper.TryGetMethod(new[] { typeof(IMyBaseInterface), typeof(IMyInterface) }, mdds), Is.Null);
+ mig = typeof(IMyBaseInterface).GetMethod("get_Id", bf);
+ Assert.That(ReflectHelper.TryGetMethod(typeof(IMyInterface), mig), Is.Not.Null);
}
[Test]
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|