|
From: <ric...@us...> - 2010-05-29 19:25:38
|
Revision: 4985
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4985&view=rev
Author: ricbrown
Date: 2010-05-29 19:25:32 +0000 (Sat, 29 May 2010)
Log Message:
-----------
Fix NH-2189 (Fetch Join Not Consistently Working With Future)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Impl/MultiCriteriaImpl.cs
trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2189/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2189/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2189/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2189/Model.cs
Modified: trunk/nhibernate/src/NHibernate/Impl/MultiCriteriaImpl.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/MultiCriteriaImpl.cs 2010-05-27 14:18:07 UTC (rev 4984)
+++ trunk/nhibernate/src/NHibernate/Impl/MultiCriteriaImpl.cs 2010-05-29 19:25:32 UTC (rev 4985)
@@ -241,7 +241,7 @@
object o =
loader.GetRowFromResultSet(reader, session, queryParameters, loader.GetLockModes(queryParameters.LockModes),
- null, hydratedObjects[i], keys, false);
+ null, hydratedObjects[i], keys, true);
if (createSubselects[i])
{
subselectResultKeys[i].Add(keys);
Modified: trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs 2010-05-27 14:18:07 UTC (rev 4984)
+++ trunk/nhibernate/src/NHibernate/Impl/MultiQueryImpl.cs 2010-05-29 19:25:32 UTC (rev 4985)
@@ -530,7 +530,7 @@
optionalObjectKey,
hydratedObjects[i],
keys,
- false);
+ true);
tempResults.Add(result);
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2189/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2189/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2189/Fixture.cs 2010-05-29 19:25:32 UTC (rev 4985)
@@ -0,0 +1,155 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using NHibernate.Criterion;
+using NUnit.Framework;
+
+namespace NHibernate.Test.NHSpecificTest.NH2189
+{
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+ private Guid _policy2Id;
+
+ protected override void OnSetUp()
+ {
+ base.OnSetUp();
+
+ using (ISession s = sessions.OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ TeamMember tm1 = new TeamMember() { Name = "Joe" };
+ TeamMember tm2 = new TeamMember() { Name = "Bill" };
+
+ s.Save(tm1);
+ s.Save(tm2);
+
+ var policy1 = new Policy() { PolicyNumber = 5 };
+ policy1.Tasks.Add(new Task() { Policy = policy1, TaskName = "Task1", TeamMember = tm1 });
+
+ var policy2 = new Policy() { PolicyNumber = 5 };
+ policy2.Tasks.Add(new Task() { Policy = policy2, TaskName = "Task2", TeamMember = tm2 });
+ policy2.Tasks.Add(new Task() { Policy = policy2, TaskName = "Task3", TeamMember = tm2 });
+
+ s.Save(policy1);
+ s.Save(policy2);
+ _policy2Id = policy2.Id;
+
+ tx.Commit();
+ }
+ }
+
+ protected override void OnTearDown()
+ {
+ using (ISession s = sessions.OpenSession())
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ s.Delete("FROM Task");
+ s.Delete("FROM Policy");
+ s.Delete("FROM TeamMember");
+ tx.Commit();
+ }
+
+ base.OnTearDown();
+ }
+
+ [Test]
+ public void FutureQueryReturnsExistingProxy()
+ {
+ using (ISession s = sessions.OpenSession())
+ using (ITransaction t = s.BeginTransaction())
+ {
+ Policy policyProxy = s.Load<Policy>(_policy2Id);
+ Assert.That(NHibernateUtil.IsInitialized(policyProxy), Is.False);
+
+ IEnumerable<Policy> futurePolicy =
+ s.CreateQuery("FROM Policy p where p.Id = :id")
+ .SetParameter("id", _policy2Id)
+ .Future<Policy>();
+
+ Policy queriedPolicy = futurePolicy.ElementAt(0);
+ Assert.That(NHibernateUtil.IsInitialized(queriedPolicy));
+ Assert.That(queriedPolicy, Is.SameAs(policyProxy));
+ }
+ }
+
+ [Test]
+ public void FutureCriteriaReturnsExistingProxy()
+ {
+ using (ISession s = sessions.OpenSession())
+ using (ITransaction t = s.BeginTransaction())
+ {
+ Policy policyProxy = s.Load<Policy>(_policy2Id);
+ Assert.That(NHibernateUtil.IsInitialized(policyProxy), Is.False);
+
+ IEnumerable<Policy> futurePolicy =
+ s.CreateCriteria<Policy>()
+ .Add(Restrictions.Eq("Id", _policy2Id))
+ .Future<Policy>();
+
+ Policy queriedPolicy = futurePolicy.ElementAt(0);
+ Assert.That(NHibernateUtil.IsInitialized(queriedPolicy));
+ Assert.That(queriedPolicy, Is.SameAs(policyProxy));
+ }
+ }
+
+ [Test]
+ public void FutureQueryEagerLoadUsesAlreadyLoadedEntity()
+ {
+ using (ISession s = sessions.OpenSession())
+ using (ITransaction t = s.BeginTransaction())
+ {
+ Policy policy2 = s.CreateQuery("SELECT p FROM Policy p " +
+ "LEFT JOIN FETCH p.Tasks t " +
+ "WHERE p.Id = :id")
+ .SetParameter("id", _policy2Id)
+ .UniqueResult<Policy>();
+
+ Assert.That(NHibernateUtil.IsInitialized(policy2.Tasks));
+ Assert.That(NHibernateUtil.IsInitialized(policy2.Tasks.ElementAt(0)));
+ Assert.That(NHibernateUtil.IsInitialized(policy2.Tasks.ElementAt(1)));
+
+ IEnumerable<Task> tasks = s.CreateQuery("SELECT t FROM Task t " +
+ "INNER JOIN FETCH t.TeamMember ORDER BY t.TaskName")
+ .Future<Task>();
+
+ Assert.That(tasks.Count(), Is.EqualTo(3));
+
+ Assert.That(NHibernateUtil.IsInitialized(tasks.ElementAt(0).TeamMember), Is.True, "Task1 TeamMember not initialized");
+ Assert.That(NHibernateUtil.IsInitialized(tasks.ElementAt(1).TeamMember), Is.True, "Task2 TeamMember not initialized");
+ Assert.That(NHibernateUtil.IsInitialized(tasks.ElementAt(2).TeamMember), Is.True, "Task3 TeamMember not initialized");
+ }
+ }
+
+ [Test]
+ public void FutureCriteriaEagerLoadUsesAlreadyLoadedEntity()
+ {
+ using (ISession s = sessions.OpenSession())
+ using (ITransaction t = s.BeginTransaction())
+ {
+ Policy policy2 =
+ s.CreateCriteria<Policy>()
+ .Add(Restrictions.Eq("Id", _policy2Id))
+ .SetFetchMode("Tasks", FetchMode.Eager)
+ .UniqueResult<Policy>();
+
+ Assert.That(NHibernateUtil.IsInitialized(policy2.Tasks));
+ Assert.That(NHibernateUtil.IsInitialized(policy2.Tasks.ElementAt(0)));
+ Assert.That(NHibernateUtil.IsInitialized(policy2.Tasks.ElementAt(1)));
+
+ IEnumerable<Task> tasks =
+ s.CreateCriteria<Task>()
+ .SetFetchMode("TeamMember", FetchMode.Eager)
+ .AddOrder(Order.Asc("TaskName"))
+ .Future<Task>();
+
+ Assert.That(tasks.Count(), Is.EqualTo(3));
+
+ Assert.That(NHibernateUtil.IsInitialized(tasks.ElementAt(0).TeamMember), Is.True, "Task1 TeamMember not initialized");
+ Assert.That(NHibernateUtil.IsInitialized(tasks.ElementAt(1).TeamMember), Is.True, "Task2 TeamMember not initialized");
+ Assert.That(NHibernateUtil.IsInitialized(tasks.ElementAt(2).TeamMember), Is.True, "Task3 TeamMember not initialized");
+ }
+ }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2189/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2189/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2189/Mappings.hbm.xml 2010-05-29 19:25:32 UTC (rev 4985)
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ assembly="NHibernate.Test"
+ namespace="NHibernate.Test.NHSpecificTest.NH2189">
+
+ <class name="Policy">
+ <id name="Id">
+ <generator class="guid.comb" />
+ </id>
+ <property name="PolicyNumber" />
+ <set name="Tasks" inverse="true" cascade="save-update">
+ <key column="PolicyId" />
+ <one-to-many class="Task" />
+ </set>
+ </class>
+
+ <class name="Task">
+ <id name="Id">
+ <generator class="guid.comb" />
+ </id>
+ <property name="TaskName" />
+ <many-to-one name="Policy" column="PolicyId" />
+ <many-to-one name="TeamMember" column="TeamMemberId" />
+ </class>
+
+ <class name="TeamMember">
+ <id name="Id">
+ <generator class="guid.comb" />
+ </id>
+ <property name="Name" />
+ </class>
+
+</hibernate-mapping>
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2189/Model.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2189/Model.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2189/Model.cs 2010-05-29 19:25:32 UTC (rev 4985)
@@ -0,0 +1,31 @@
+using Iesi.Collections.Generic;
+using System;
+
+namespace NHibernate.Test.NHSpecificTest.NH2189
+{
+ public class Policy
+ {
+ public Policy()
+ {
+ Tasks = new HashedSet<Task>();
+ }
+
+ public virtual Guid Id { get; protected set; }
+ public virtual int PolicyNumber { get; set; }
+ public virtual ISet<Task> Tasks { get; protected set; }
+ }
+
+ public class Task
+ {
+ public virtual Guid Id { get; protected set; }
+ public virtual string TaskName { get; set; }
+ public virtual Policy Policy { get; set; }
+ public virtual TeamMember TeamMember { get; set; }
+ }
+
+ public class TeamMember
+ {
+ public virtual Guid Id { get; protected set; }
+ public virtual string Name { get; set; }
+ }
+}
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-05-27 14:18:07 UTC (rev 4984)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-05-29 19:25:32 UTC (rev 4985)
@@ -437,6 +437,8 @@
<Compile Include="NHSpecificTest\CriteriaQueryOnComponentCollection\Employee.cs" />
<Compile Include="NHSpecificTest\CriteriaQueryOnComponentCollection\Fixture.cs" />
<Compile Include="NHSpecificTest\CriteriaQueryOnComponentCollection\Money.cs" />
+ <Compile Include="NHSpecificTest\NH2189\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH2189\Model.cs" />
<Compile Include="NHSpecificTest\ElementsEnums\AbstractIntEnumsBagFixture.cs" />
<Compile Include="NHSpecificTest\ElementsEnums\IntEnumsBagNoNameFixture.cs" />
<Compile Include="NHSpecificTest\ElementsEnums\IntEnumsBagPartialNameFixture.cs" />
@@ -2139,6 +2141,7 @@
<EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" />
<EmbeddedResource Include="CollectionTest\NullableValueTypeElementMapFixture.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH2189\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2201\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2192\Mappings.hbm.xml" />
<EmbeddedResource Include="ListIndex\SimpleOneToMany.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|