-
Notifications
You must be signed in to change notification settings - Fork 936
Port Hibernate's support subqueries in HQL as CASE statement alternatives #2106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
344821e
Port Hibernate's support subqueries in HQL as CASE statement alternat…
maca88 2644ef7
Fix broken test
maca88 e444607
Fix previously not supported test
maca88 66ac857
Merge branch 'master' into HHH-1689
maca88 006809b
Code review changes
maca88 a4be584
Merge branch 'master' into HHH-1689
hazzik d79fd24
Regenerate Async
hazzik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by AsyncGenerator. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
using NHibernate.Cfg.MappingSchema; | ||
using NHibernate.Mapping.ByCode; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.Hql | ||
{ | ||
using System.Threading.Tasks; | ||
using System.Threading; | ||
[TestFixture] | ||
public class SubQueryTestAsync : TestCaseMappingByCode | ||
{ | ||
protected override HbmMapping GetMappings() | ||
{ | ||
var mapper = new ModelMapper(); | ||
mapper.Class<Root>( | ||
rc => | ||
{ | ||
rc.Id(x => x.Id, m => m.Generator(Generators.Native)); | ||
rc.Property(x => x.RootName); | ||
rc.ManyToOne(x => x.Branch); | ||
}); | ||
|
||
mapper.Class<Branch>( | ||
rc => | ||
{ | ||
rc.Id(x => x.Id, m => m.Generator(Generators.Native)); | ||
rc.Property(x => x.BranchName); | ||
rc.Bag(x => x.Leafs, cm => cm.Cascade(Mapping.ByCode.Cascade.All), x => x.OneToMany()); | ||
}); | ||
mapper.Class<Leaf>( | ||
rc => | ||
{ | ||
rc.Id(x => x.Id, m => m.Generator(Generators.Native)); | ||
rc.Property(x => x.LeafName); | ||
}); | ||
|
||
return mapper.CompileMappingForAllExplicitlyAddedEntities(); | ||
} | ||
|
||
[TestCase("SELECT CASE WHEN l.id IS NOT NULL THEN (SELECT COUNT(r.id) FROM Root r) ELSE 0 END FROM Leaf l")] | ||
[TestCase("SELECT CASE WHEN (SELECT COUNT(r.id) FROM Root r) > 1 THEN 1 ELSE 0 END FROM Leaf l")] | ||
[TestCase("SELECT CASE WHEN l.id > 1 THEN 1 ELSE (SELECT COUNT(r.id) FROM Root r) END FROM Leaf l")] | ||
[TestCase("SELECT CASE (SELECT COUNT(r.id) FROM Root r) WHEN 1 THEN 1 ELSE 0 END FROM Leaf l")] | ||
[TestCase("SELECT CASE l.id WHEN (SELECT COUNT(r.id) FROM Root r) THEN 1 ELSE 0 END FROM Leaf l")] | ||
public async Task TestSubQueryAsync(string query, CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
if (!Dialect.SupportsScalarSubSelects) | ||
{ | ||
Assert.Ignore(Dialect.GetType().Name + " does not support scalar sub-queries"); | ||
} | ||
|
||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
// Simple syntax check | ||
await (session.CreateQuery(query).ListAsync(cancellationToken)); | ||
await (transaction.CommitAsync(cancellationToken)); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using NHibernate.Cfg.MappingSchema; | ||
using NHibernate.Mapping.ByCode; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.Hql | ||
{ | ||
[TestFixture] | ||
public class SubQueryTest : TestCaseMappingByCode | ||
{ | ||
protected override HbmMapping GetMappings() | ||
{ | ||
var mapper = new ModelMapper(); | ||
mapper.Class<Root>( | ||
rc => | ||
{ | ||
rc.Id(x => x.Id, m => m.Generator(Generators.Native)); | ||
rc.Property(x => x.RootName); | ||
rc.ManyToOne(x => x.Branch); | ||
}); | ||
|
||
mapper.Class<Branch>( | ||
rc => | ||
{ | ||
rc.Id(x => x.Id, m => m.Generator(Generators.Native)); | ||
rc.Property(x => x.BranchName); | ||
rc.Bag(x => x.Leafs, cm => cm.Cascade(Mapping.ByCode.Cascade.All), x => x.OneToMany()); | ||
}); | ||
mapper.Class<Leaf>( | ||
rc => | ||
{ | ||
rc.Id(x => x.Id, m => m.Generator(Generators.Native)); | ||
rc.Property(x => x.LeafName); | ||
}); | ||
|
||
return mapper.CompileMappingForAllExplicitlyAddedEntities(); | ||
} | ||
|
||
[TestCase("SELECT CASE WHEN l.id IS NOT NULL THEN (SELECT COUNT(r.id) FROM Root r) ELSE 0 END FROM Leaf l")] | ||
[TestCase("SELECT CASE WHEN (SELECT COUNT(r.id) FROM Root r) > 1 THEN 1 ELSE 0 END FROM Leaf l")] | ||
[TestCase("SELECT CASE WHEN l.id > 1 THEN 1 ELSE (SELECT COUNT(r.id) FROM Root r) END FROM Leaf l")] | ||
[TestCase("SELECT CASE (SELECT COUNT(r.id) FROM Root r) WHEN 1 THEN 1 ELSE 0 END FROM Leaf l")] | ||
[TestCase("SELECT CASE l.id WHEN (SELECT COUNT(r.id) FROM Root r) THEN 1 ELSE 0 END FROM Leaf l")] | ||
public void TestSubQuery(string query) | ||
{ | ||
if (!Dialect.SupportsScalarSubSelects) | ||
{ | ||
Assert.Ignore(Dialect.GetType().Name + " does not support scalar sub-queries"); | ||
} | ||
|
||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
// Simple syntax check | ||
session.CreateQuery(query).List(); | ||
transaction.Commit(); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace NHibernate.Test.Hql | ||
{ | ||
public class Root | ||
{ | ||
public virtual int Id { get; set; } | ||
|
||
public virtual string RootName { get; set; } | ||
|
||
public virtual Branch Branch { get; set; } | ||
} | ||
|
||
public class Branch | ||
{ | ||
public virtual int Id { get; set; } | ||
|
||
public virtual string BranchName { get; set; } | ||
|
||
public virtual IList<Leaf> Leafs { get; set; } | ||
} | ||
|
||
public class Leaf | ||
{ | ||
public virtual int Id { get; set; } | ||
|
||
public virtual string LeafName { get; set; } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.