|
From: <fab...@us...> - 2009-10-18 18:10:50
|
Revision: 4784
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4784&view=rev
Author: fabiomaulo
Date: 2009-10-18 18:10:42 +0000 (Sun, 18 Oct 2009)
Log Message:
-----------
Merge r4783 (fix NH-1785)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaJoinWalker.cs
trunk/nhibernate/src/NHibernate/Loader/JoinWalker.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1785/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1785/Domain.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1785/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1785/Mappings.hbm.xml
Modified: trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaJoinWalker.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaJoinWalker.cs 2009-10-18 18:08:11 UTC (rev 4783)
+++ trunk/nhibernate/src/NHibernate/Loader/Criteria/CriteriaJoinWalker.cs 2009-10-18 18:10:42 UTC (rev 4784)
@@ -1,4 +1,3 @@
-using System;
using System.Collections.Generic;
using Iesi.Collections.Generic;
using log4net;
@@ -58,22 +57,21 @@
userAliases = ArrayHelper.ToStringArray(userAliasList);
}
- protected override void InitAll(SqlString whereString, SqlString orderByString, LockMode lockMode)
+ protected override void WalkEntityTree(IOuterJoinLoadable persister, string alias, string path, int currentDepth)
{
- // NH different behavior (NH-1760)
- WalkCompositeComponentIdTree();
- base.InitAll(whereString, orderByString, lockMode);
+ // NH different behavior (NH-1476, NH-1760, NH-1785)
+ base.WalkEntityTree(persister, alias, path, currentDepth);
+ WalkCompositeComponentIdTree(persister, alias, path);
}
- private void WalkCompositeComponentIdTree()
+ private void WalkCompositeComponentIdTree(IOuterJoinLoadable persister, string alias, string path)
{
- IType type = Persister.IdentifierType;
- string propertyName = Persister.IdentifierPropertyName;
+ IType type = persister.IdentifierType;
+ string propertyName = persister.IdentifierPropertyName;
if (type != null && type.IsComponentType && !(type is EmbeddedComponentType))
{
- ILhsAssociationTypeSqlInfo associationTypeSQLInfo = JoinHelper.GetIdLhsSqlInfo(Alias, Persister, Factory);
- WalkComponentTree((IAbstractComponentType) type, 0, Alias, SubPath(string.Empty, propertyName), 0,
- associationTypeSQLInfo);
+ ILhsAssociationTypeSqlInfo associationTypeSQLInfo = JoinHelper.GetIdLhsSqlInfo(alias, persister, Factory);
+ WalkComponentTree((IAbstractComponentType)type, 0, alias, SubPath(path, propertyName), 0, associationTypeSQLInfo);
}
}
Modified: trunk/nhibernate/src/NHibernate/Loader/JoinWalker.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Loader/JoinWalker.cs 2009-10-18 18:08:11 UTC (rev 4783)
+++ trunk/nhibernate/src/NHibernate/Loader/JoinWalker.cs 2009-10-18 18:10:42 UTC (rev 4784)
@@ -237,7 +237,7 @@
/// For an entity class, add to a list of associations to be fetched
/// by outerjoin
/// </summary>
- private void WalkEntityTree(IOuterJoinLoadable persister, string alias, string path, int currentDepth)
+ protected virtual void WalkEntityTree(IOuterJoinLoadable persister, string alias, string path, int currentDepth)
{
int n = persister.CountSubclassProperties();
for (int i = 0; i < n; i++)
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1785/Domain.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1785/Domain.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1785/Domain.cs 2009-10-18 18:10:42 UTC (rev 4784)
@@ -0,0 +1,59 @@
+using System;
+using Iesi.Collections.Generic;
+
+namespace NHibernate.Test.NHSpecificTest.NH1785
+{
+ public class Entity1
+ {
+ public virtual Guid Id { get; set; }
+ public virtual ISet<Entity2> Entities2 { get; set; }
+ }
+
+ public class Entity2Id
+ {
+ public virtual Entity1 Entity1 { get; set; }
+ public virtual Entity3 Entity3 { get; set; }
+
+ public bool Equals(Entity2Id other)
+ {
+ if (ReferenceEquals(null, other))
+ {
+ return false;
+ }
+ if (ReferenceEquals(this, other))
+ {
+ return true;
+ }
+ return Equals(other.Entity1, Entity1) && Equals(other.Entity3, Entity3);
+ }
+
+ public override bool Equals(object obj)
+ {
+ return Equals(obj as Entity2Id);
+ }
+
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ return ((Entity1 != null ? Entity1.GetHashCode() : 0) * 397) ^ (Entity3 != null ? Entity3.GetHashCode() : 0);
+ }
+ }
+ }
+
+ public class Entity2
+ {
+ public virtual Entity2Id Id { get; set; }
+ }
+
+ public class Entity3
+ {
+ public virtual Guid Id { get; set; }
+ public virtual Entity4 Entity4 { get; set; }
+ }
+
+ public class Entity4
+ {
+ public virtual Guid Id { get; set; }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1785/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1785/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1785/Fixture.cs 2009-10-18 18:10:42 UTC (rev 4784)
@@ -0,0 +1,43 @@
+using System;
+using NHibernate.Criterion;
+using NHibernate.SqlCommand;
+using NUnit.Framework;
+using System.Text.RegularExpressions;
+
+namespace NHibernate.Test.NHSpecificTest.NH1785
+{
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+ [Test]
+ public void Bug()
+ {
+ using (var session = OpenSession())
+ {
+ ICriteria criteria = session.CreateCriteria(typeof (Entity1));
+ criteria.CreateAlias("Entities2", "ent2", JoinType.InnerJoin);
+ criteria.CreateAlias("ent2.Id.Entity3", "ent3", JoinType.InnerJoin);
+ criteria.CreateAlias("ent3.Entity4", "ent4", JoinType.InnerJoin);
+ criteria.Add(Restrictions.Eq("ent4.Id", Guid.NewGuid()));
+ Assert.DoesNotThrow(() => criteria.List<Entity1>());
+ }
+ }
+
+ [Test]
+ public void ShouldNotContainJoinWhereNotRequired()
+ {
+ using (var session = OpenSession())
+ {
+ using (var ls = new SqlLogSpy())
+ {
+ ICriteria criteria = session.CreateCriteria(typeof(Entity1));
+ criteria.CreateAlias("Entities2", "ent2", JoinType.InnerJoin);
+ criteria.List<Entity1>();
+ var sql = ls.GetWholeLog();
+ var rx = new Regex(@"\bjoin\b");
+ Assert.That(rx.Matches(sql).Count, Is.EqualTo(1));
+ }
+ }
+ }
+ }
+}
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1785/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1785/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1785/Mappings.hbm.xml 2009-10-18 18:10:42 UTC (rev 4784)
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ assembly="NHibernate.Test"
+ namespace="NHibernate.Test.NHSpecificTest.NH1785">
+
+ <class name="Entity1" table="Entity1">
+ <id name="Id" type="Guid" column="id">
+ <generator class="guid" />
+ </id>
+ <set name="Entities2" lazy="true" inverse="true" table="Entity2">
+ <key column="id">
+ </key>
+ <one-to-many class="Entity2"/>
+ </set>
+ </class>
+
+ <class name="Entity2" table="Entity2">
+ <composite-id class="Entity2Id" name="Id">
+ <key-many-to-one name="Entity1" class="Entity1" column="id1" />
+ <key-many-to-one name="Entity3" class="Entity3" column="id3" />
+ </composite-id>
+ </class>
+
+ <class name="Entity3" table="Entity3">
+ <id name="Id" type="Guid" column="id">
+ <generator class="guid" />
+ </id>
+ <many-to-one name="Entity4" class="Entity4" column="entity4_id" />
+ </class>
+
+ <class name="Entity4" table="Entity4">
+ <id name="Id" type="Guid" column="id">
+ <generator class="guid" />
+ </id>
+ </class>
+</hibernate-mapping>
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-10-18 18:08:11 UTC (rev 4783)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-10-18 18:10:42 UTC (rev 4784)
@@ -397,6 +397,8 @@
<Compile Include="NHSpecificTest\Futures\FutureQueryOverFixture.cs" />
<Compile Include="NHSpecificTest\NH1255\Domain.cs" />
<Compile Include="NHSpecificTest\NH1255\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH1785\Domain.cs" />
+ <Compile Include="NHSpecificTest\NH1785\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1895\DomainClasses.cs" />
<Compile Include="NHSpecificTest\NH1895\SampleTest.cs" />
<Compile Include="NHSpecificTest\NH1922\Fixture.cs" />
@@ -2044,6 +2046,7 @@
<EmbeddedResource Include="CfgTest\Loquacious\EntityToCache.hbm.xml" />
<EmbeddedResource Include="DriverTest\SqlServerCeEntity.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH1785\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1255\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1895\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1985\Mappings.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|