Skip to content

Gh3334 2 #3338

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

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 185 additions & 0 deletions src/NHibernate.Test/Async/NHSpecificTest/GH3334/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
//------------------------------------------------------------------------------
// <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 System.Collections.Generic;
using System.Runtime.CompilerServices;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.GH3334
{
using System.Threading.Tasks;
[TestFixture]
public class FixtureAsync : BugTestCase
{
[OneTimeSetUp]
public void OneTimeSetUp()
{
using (var session = OpenSession())
using (var t = session.BeginTransaction())
{
var parent = new Entity
{
Name = "Parent1",
Children = { new ChildEntity { Name = "Child", Child = new GrandChildEntity { Name = "GrandChild" } } }
};
session.Save(parent);
parent = new Entity
{
Name = "Parent2",
Children = { new ChildEntity { Name = "Child", Child = new GrandChildEntity { Name = "XGrandChild" } } }
};
var other = new OtherEntity { Name = "ABC", Entities = {parent}};
parent.OtherEntity = other;
session.Save(parent);
session.Save(other);
t.Commit();
}

Sfi.Statistics.IsStatisticsEnabled = true;
}

[OneTimeTearDown]
public void OneTimeTearDown()
{
Sfi.Statistics.IsStatisticsEnabled = false;

using var session = OpenSession();
using var transaction = session.BeginTransaction();

session.CreateQuery("delete from ChildEntity").ExecuteUpdate();
session.CreateQuery("delete from GrandChildEntity").ExecuteUpdate();
session.CreateQuery("delete from Entity").ExecuteUpdate();
session.CreateQuery("delete from OtherEntity").ExecuteUpdate();

transaction.Commit();
}

public class TestCaseItem
{
public string Name { get; }
public string Hql { get; }
public int LineNumber { get; }

public TestCaseItem(string name, string hql, [CallerLineNumber] int lineNumber = 0)
{
Name = name;
Hql = hql;
LineNumber = lineNumber;
}

public override string ToString() => $"{LineNumber:0000}: {Name}";
}

public static IEnumerable<TestCaseItem> GetNoExceptionOnExecuteQueryTestCases()
{
/* does not work because of inner join or theta join created for many-to-one
@"
SELECT ROOT
FROM Entity AS ROOT
WHERE
EXISTS
(FROM ELEMENTS(ROOT.Children) AS child
WHERE
child.Child.Name like 'G%'
OR ROOT.OtherEntity.Name like 'A%'
)");*/

yield return new("Basic Elements case 1 FoundViaGrandChildG", @"
SELECT ROOT
FROM Entity AS ROOT
WHERE
EXISTS
(FROM ELEMENTS(ROOT.Children) AS child
LEFT JOIN child.Child AS grandChild
WHERE
grandChild.Name like 'G%'
)");
yield return new("Basic Elements case 2 FoundViaOtherEntityA", @"
SELECT ROOT
FROM Entity AS ROOT
WHERE
EXISTS
(FROM ELEMENTS(ROOT.OtherEntity) AS otherEntity
WHERE
otherEntity.Name like 'A%'
)");
yield return new("HQL Elements FoundViaGrandChildG", @"
SELECT ROOT
FROM Entity AS ROOT
WHERE
EXISTS
(FROM ELEMENTS(ROOT.Children) AS child
LEFT JOIN child.Child AS grandChild
LEFT JOIN ROOT.OtherEntity AS otherEntity
WHERE
grandChild.Name like 'G%'
OR otherEntity.Name like 'G%'
)");
yield return new("HQL Elements FoundViaOtherEntityA", @"
SELECT ROOT
FROM Entity AS ROOT
WHERE
EXISTS
(FROM ELEMENTS(ROOT.Children) AS child
LEFT JOIN child.Child AS grandChild
LEFT JOIN ROOT.OtherEntity AS otherEntity
WHERE
grandChild.Name like 'A%'
OR otherEntity.Name like 'A%'
)");
yield return new("HQL Entity FoundViaGrandChildG", @"
SELECT ROOT
FROM Entity AS ROOT
WHERE
EXISTS
(FROM ChildEntity AS child
LEFT JOIN child.Child AS grandChild
LEFT JOIN ROOT.OtherEntity AS otherEntity
WHERE
child.Parent = ROOT
AND (
grandChild.Name like 'G%'
OR otherEntity.Name like 'G%'
)
)");
yield return new("HQL Entity FoundViaOtherEntityA", @"
SELECT ROOT
FROM Entity AS ROOT
WHERE
EXISTS
(FROM ChildEntity AS child
LEFT JOIN child.Child AS grandChild
LEFT JOIN ROOT.OtherEntity AS otherEntity
WHERE
child.Parent = ROOT
AND (
grandChild.Name like 'A%'
OR otherEntity.Name like 'A%'
)
)");
}

[Test, TestCaseSource(nameof(GetNoExceptionOnExecuteQueryTestCases))]
public async Task NoExceptionOnExecuteQueryAsync(TestCaseItem testCase)
{
using var session = OpenSession();
using var _ = session.BeginTransaction();

var q = session.CreateQuery(testCase.Hql);
Assert.That(await (q.ListAsync()), Has.Count.EqualTo(1));
}

protected override bool CheckDatabaseWasCleaned()
{
// same set of objects for each test
return true;
}
}
}
33 changes: 33 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3334/Entity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Collections.Generic;

namespace NHibernate.Test.NHSpecificTest.GH3334
{
public class Entity
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual ISet<ChildEntity> Children { get; set; } = new HashSet<ChildEntity>();
public virtual OtherEntity OtherEntity { get; set; }
}

public class ChildEntity
{
public virtual int Id { get; set; }
public virtual Entity Parent { get; set; }
public virtual string Name { get; set; }
public virtual GrandChildEntity Child { get; set; }
}

public class GrandChildEntity
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}

public class OtherEntity
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual ISet<Entity> Entities { get; set; } = new HashSet<Entity>();
}
}
174 changes: 174 additions & 0 deletions src/NHibernate.Test/NHSpecificTest/GH3334/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.GH3334
{
[TestFixture]
public class Fixture : BugTestCase
{
[OneTimeSetUp]
public void OneTimeSetUp()
{
using (var session = OpenSession())
using (var t = session.BeginTransaction())
{
var parent = new Entity
{
Name = "Parent1",
Children = { new ChildEntity { Name = "Child", Child = new GrandChildEntity { Name = "GrandChild" } } }
};
session.Save(parent);
parent = new Entity
{
Name = "Parent2",
Children = { new ChildEntity { Name = "Child", Child = new GrandChildEntity { Name = "XGrandChild" } } }
};
var other = new OtherEntity { Name = "ABC", Entities = {parent}};
parent.OtherEntity = other;
session.Save(parent);
session.Save(other);
t.Commit();
}

Sfi.Statistics.IsStatisticsEnabled = true;
}

[OneTimeTearDown]
public void OneTimeTearDown()
{
Sfi.Statistics.IsStatisticsEnabled = false;

using var session = OpenSession();
using var transaction = session.BeginTransaction();

session.CreateQuery("delete from ChildEntity").ExecuteUpdate();
session.CreateQuery("delete from GrandChildEntity").ExecuteUpdate();
session.CreateQuery("delete from Entity").ExecuteUpdate();
session.CreateQuery("delete from OtherEntity").ExecuteUpdate();

transaction.Commit();
}

public class TestCaseItem
{
public string Name { get; }
public string Hql { get; }
public int LineNumber { get; }

public TestCaseItem(string name, string hql, [CallerLineNumber] int lineNumber = 0)
{
Name = name;
Hql = hql;
LineNumber = lineNumber;
}

public override string ToString() => $"{LineNumber:0000}: {Name}";
}

public static IEnumerable<TestCaseItem> GetNoExceptionOnExecuteQueryTestCases()
{
/* does not work because of inner join or theta join created for many-to-one
@"
SELECT ROOT
FROM Entity AS ROOT
WHERE
EXISTS
(FROM ELEMENTS(ROOT.Children) AS child
WHERE
child.Child.Name like 'G%'
OR ROOT.OtherEntity.Name like 'A%'
)");*/

yield return new("Basic Elements case 1 FoundViaGrandChildG", @"
SELECT ROOT
FROM Entity AS ROOT
WHERE
EXISTS
(FROM ELEMENTS(ROOT.Children) AS child
LEFT JOIN child.Child AS grandChild
WHERE
grandChild.Name like 'G%'
)");
yield return new("Basic Elements case 2 FoundViaOtherEntityA", @"
SELECT ROOT
FROM Entity AS ROOT
WHERE
EXISTS
(FROM ELEMENTS(ROOT.OtherEntity) AS otherEntity
WHERE
otherEntity.Name like 'A%'
)");
yield return new("HQL Elements FoundViaGrandChildG", @"
SELECT ROOT
FROM Entity AS ROOT
WHERE
EXISTS
(FROM ELEMENTS(ROOT.Children) AS child
LEFT JOIN child.Child AS grandChild
LEFT JOIN ROOT.OtherEntity AS otherEntity
WHERE
grandChild.Name like 'G%'
OR otherEntity.Name like 'G%'
)");
yield return new("HQL Elements FoundViaOtherEntityA", @"
SELECT ROOT
FROM Entity AS ROOT
WHERE
EXISTS
(FROM ELEMENTS(ROOT.Children) AS child
LEFT JOIN child.Child AS grandChild
LEFT JOIN ROOT.OtherEntity AS otherEntity
WHERE
grandChild.Name like 'A%'
OR otherEntity.Name like 'A%'
)");
yield return new("HQL Entity FoundViaGrandChildG", @"
SELECT ROOT
FROM Entity AS ROOT
WHERE
EXISTS
(FROM ChildEntity AS child
LEFT JOIN child.Child AS grandChild
LEFT JOIN ROOT.OtherEntity AS otherEntity
WHERE
child.Parent = ROOT
AND (
grandChild.Name like 'G%'
OR otherEntity.Name like 'G%'
)
)");
yield return new("HQL Entity FoundViaOtherEntityA", @"
SELECT ROOT
FROM Entity AS ROOT
WHERE
EXISTS
(FROM ChildEntity AS child
LEFT JOIN child.Child AS grandChild
LEFT JOIN ROOT.OtherEntity AS otherEntity
WHERE
child.Parent = ROOT
AND (
grandChild.Name like 'A%'
OR otherEntity.Name like 'A%'
)
)");
}

[Test, TestCaseSource(nameof(GetNoExceptionOnExecuteQueryTestCases))]
public void NoExceptionOnExecuteQuery(TestCaseItem testCase)
{
using var session = OpenSession();
using var _ = session.BeginTransaction();

var q = session.CreateQuery(testCase.Hql);
Assert.That(q.List(), Has.Count.EqualTo(1));
}

protected override bool CheckDatabaseWasCleaned()
{
// same set of objects for each test
return true;
}
}
}
Loading