Skip to content

Commit 01b7da5

Browse files
committed
WIP Table group joins support for subclasses with withClause in hql
1 parent 9427018 commit 01b7da5

File tree

13 files changed

+440
-137
lines changed

13 files changed

+440
-137
lines changed

src/NHibernate.Test/Async/Hql/Ast/WithClauseFixture.cs

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
//------------------------------------------------------------------------------
99

1010

11-
using System;
1211
using System.Collections;
13-
using NHibernate.Exceptions;
1412
using NHibernate.Hql.Ast.ANTLR;
1513
using NUnit.Framework;
1614

@@ -54,40 +52,30 @@ public async Task WithClauseFailsWithFetchAsync()
5452
}
5553

5654
[Test]
57-
public async Task ValidWithSemanticsAsync()
55+
public void ValidWithSemanticsAsync()
5856
{
5957
using (var s = OpenSession())
6058
{
61-
await (s.CreateQuery(
62-
"from Animal a inner join a.offspring o inner join o.mother as m inner join m.father as f with o.bodyWeight > 1").ListAsync());
63-
}
64-
}
65-
66-
[Test]
67-
public async Task InvalidWithSemanticsAsync()
68-
{
69-
using (ISession s = OpenSession())
70-
{
71-
// PROBLEM : f.bodyWeight is a reference to a column on the Animal table; however, the 'f'
72-
// alias relates to the Human.friends collection which the aonther Human entity. The issue
73-
// here is the way JoinSequence and Joinable (the persister) interact to generate the
74-
// joins relating to the sublcass/superclass tables
75-
Assert.ThrowsAsync<InvalidWithClauseException>(
59+
60+
Assert.Multiple(
7661
() =>
77-
s.CreateQuery("from Human h inner join h.friends as f with f.bodyWeight < :someLimit").SetDouble("someLimit", 1).ListAsync());
78-
79-
//The query below is no longer throw InvalidWithClauseException but generates "invalid" SQL to better support complex with join clauses.
80-
//Invalid SQL means that additional joins for "o.mother.father" are currently added after "offspring" join. Some DBs can process such query and some can't.
81-
try
82-
{
83-
await (s.CreateQuery("from Human h inner join h.offspring o with o.mother.father = :cousin")
84-
.SetInt32("cousin", 123)
85-
.ListAsync());
86-
}
87-
catch (GenericADOException)
88-
{
89-
//Apparently SQLite can process queries with wrong join orders
90-
}
62+
{
63+
return Task.FromResult<object>(Assert.DoesNotThrowAsync(
64+
() => s.CreateQuery(
65+
"from Animal a inner join a.offspring o inner join o.mother as m inner join m.father as f with o.bodyWeight > 1").ListAsync()
66+
));
67+
68+
return Task.FromResult<object>(Assert.DoesNotThrowAsync(
69+
() =>
70+
s.CreateQuery("from Human h inner join h.friends as f with f.bodyWeight < :someLimit").SetDouble("someLimit", 1).ListAsync(), "Failed query 1"));
71+
72+
return Task.FromResult<object>(Assert.DoesNotThrowAsync(
73+
() =>
74+
s.CreateQuery("from Human h inner join h.offspring o with o.mother.father = :cousin")
75+
.SetInt32("cousin", 123)
76+
.ListAsync(),
77+
"Failed query 2"));
78+
});
9179
}
9280
}
9381

src/NHibernate.Test/Hql/Ast/WithClauseFixture.cs

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
21
using System.Collections;
3-
using NHibernate.Exceptions;
42
using NHibernate.Hql.Ast.ANTLR;
53
using NUnit.Framework;
64

@@ -46,36 +44,26 @@ public void ValidWithSemantics()
4644
{
4745
using (var s = OpenSession())
4846
{
49-
s.CreateQuery(
50-
"from Animal a inner join a.offspring o inner join o.mother as m inner join m.father as f with o.bodyWeight > 1").List();
51-
}
52-
}
53-
54-
[Test]
55-
public void InvalidWithSemantics()
56-
{
57-
using (ISession s = OpenSession())
58-
{
59-
// PROBLEM : f.bodyWeight is a reference to a column on the Animal table; however, the 'f'
60-
// alias relates to the Human.friends collection which the aonther Human entity. The issue
61-
// here is the way JoinSequence and Joinable (the persister) interact to generate the
62-
// joins relating to the sublcass/superclass tables
63-
Assert.Throws<InvalidWithClauseException>(
47+
48+
Assert.Multiple(
6449
() =>
65-
s.CreateQuery("from Human h inner join h.friends as f with f.bodyWeight < :someLimit").SetDouble("someLimit", 1).List());
66-
67-
//The query below is no longer throw InvalidWithClauseException but generates "invalid" SQL to better support complex with join clauses.
68-
//Invalid SQL means that additional joins for "o.mother.father" are currently added after "offspring" join. Some DBs can process such query and some can't.
69-
try
70-
{
71-
s.CreateQuery("from Human h inner join h.offspring o with o.mother.father = :cousin")
72-
.SetInt32("cousin", 123)
73-
.List();
74-
}
75-
catch (GenericADOException)
76-
{
77-
//Apparently SQLite can process queries with wrong join orders
78-
}
50+
{
51+
Assert.DoesNotThrow(
52+
() => s.CreateQuery(
53+
"from Animal a inner join a.offspring o inner join o.mother as m inner join m.father as f with o.bodyWeight > 1").List()
54+
);
55+
56+
Assert.DoesNotThrow(
57+
() =>
58+
s.CreateQuery("from Human h inner join h.friends as f with f.bodyWeight < :someLimit").SetDouble("someLimit", 1).List(), "Failed query 1");
59+
60+
Assert.DoesNotThrow(
61+
() =>
62+
s.CreateQuery("from Human h inner join h.offspring o with o.mother.father = :cousin")
63+
.SetInt32("cousin", 123)
64+
.List(),
65+
"Failed query 2");
66+
});
7967
}
8068
}
8169

0 commit comments

Comments
 (0)