-
Notifications
You must be signed in to change notification settings - Fork 931
Fix custom sql loader with composite id #452
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9f57e5a
Test case and fix for NH-3079 on branch master
hailtondecastro 162b079
Clean-up the test case
fredericDelaporte ca2fcb9
Refactor the fix
fredericDelaporte 979aa4d
Generate async code
fredericDelaporte 37d8795
Simplify FlattenTypesAndValues method
maca88 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
246 changes: 246 additions & 0 deletions
246
src/NHibernate.Test/Async/NHSpecificTest/NH3079/Fixture.cs
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,246 @@ | ||
| //------------------------------------------------------------------------------ | ||
| // <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.Linq; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace NHibernate.Test.NHSpecificTest.NH3079 | ||
| { | ||
| using System.Threading.Tasks; | ||
| [TestFixture] | ||
| public class FixtureAsync : BugTestCase | ||
| { | ||
| // Disable second level cache | ||
| protected override string CacheConcurrencyStrategy => null; | ||
|
|
||
| protected override void OnTearDown() | ||
| { | ||
| using (var s = OpenSession()) | ||
| using (var t = s.BeginTransaction()) | ||
| { | ||
| s.CreateQuery("delete from Employment").ExecuteUpdate(); | ||
|
|
||
| s.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
|
|
||
| t.Commit(); | ||
| } | ||
| } | ||
|
|
||
| protected override void OnSetUp() | ||
| { | ||
| using (var s = OpenSession()) | ||
| using (var t = s.BeginTransaction()) | ||
| { | ||
| var personList = new List<Person>(); | ||
| var employerList = new List<Employer>(); | ||
|
|
||
| // Global id to avoid false positive assertion with positional parameter | ||
| var gId = 1; | ||
|
|
||
| for (var i = 0; i < 3; i++) | ||
| { | ||
| var personCpId = new PersonCpId { IdA = gId++, IdB = gId++ }; | ||
| var personObj = new Person | ||
| { CpId = personCpId, Name = "PERSON_" + personCpId.IdA + "_" + personCpId.IdB }; | ||
| s.Save(personObj); | ||
| personList.Add(personObj); | ||
| } | ||
|
|
||
| for (var i = 0; i < 3; i++) | ||
| { | ||
| var employerCpId = new EmployerCpId { IdA = gId++, IdB = gId++ }; | ||
| var employerObj = new Employer | ||
| { CpId = employerCpId, Name = "EMPLOYER_" + employerCpId.IdA + "_" + employerCpId.IdB }; | ||
| s.Save(employerObj); | ||
| employerList.Add(employerObj); | ||
| } | ||
|
|
||
| var employmentIds = new[] | ||
| { | ||
| gId++, | ||
| gId++, | ||
| gId++, | ||
| gId++, | ||
| }; | ||
| var employmentNames = new[] | ||
| { | ||
| //P1 + E1 | ||
| "EMPLOYMENT_" + employmentIds[0] + "_" + | ||
| personList[0].CpId.IdA + "_" + personList[0].CpId.IdA + "_" + | ||
| employerList[0].CpId.IdA + "_" + employerList[0].CpId.IdB, | ||
| //P1 + E2 | ||
| "EMPLOYMENT_" + employmentIds[1] + "_" + | ||
| personList[0].CpId.IdA + "_" + personList[0].CpId.IdA + "_" + | ||
| employerList[1].CpId.IdA + "_" + employerList[1].CpId.IdB, | ||
| //P2 + E2 | ||
| "EMPLOYMENT_" + employmentIds[2] + "_" + | ||
| personList[1].CpId.IdA + "_" + personList[1].CpId.IdA + "_" + | ||
| employerList[1].CpId.IdA + "_" + employerList[1].CpId.IdB, | ||
| //P2 + E3 | ||
| "EMPLOYMENT_" + employmentIds[2] + "_" + | ||
| personList[1].CpId.IdA + "_" + personList[1].CpId.IdA + "_" + | ||
| employerList[2].CpId.IdA + "_" + employerList[2].CpId.IdB | ||
| }; | ||
| var employmentPersons = new[] | ||
| { | ||
| personList[0], | ||
| personList[0], | ||
| personList[1], | ||
| personList[1] | ||
| }; | ||
| var employmentEmployers = new[] | ||
| { | ||
| employerList[0], | ||
| employerList[1], | ||
| employerList[1], | ||
| employerList[2] | ||
| }; | ||
|
|
||
| for (var k = 0; k < employmentIds.Length; k++) | ||
| { | ||
| var employmentCpId = new EmploymentCpId | ||
| { | ||
| Id = employmentIds[k], | ||
| PersonObj = employmentPersons[k], | ||
| EmployerObj = employmentEmployers[k] | ||
| }; | ||
| var employmentObj = new Employment { CpId = employmentCpId, Name = employmentNames[k] }; | ||
| s.Save(employmentObj); | ||
| } | ||
|
|
||
| for (var i = 0; i < 3; i++) | ||
| { | ||
| var personNoComponentObj = new PersonNoComponent { IdA = gId++, IdB = gId++ }; | ||
| personNoComponentObj.Name = "PERSON_NO_COMPONENT_" + personNoComponentObj.IdA + "_" + | ||
| personNoComponentObj.IdB; | ||
| s.Save(personNoComponentObj); | ||
| } | ||
|
|
||
| t.Commit(); | ||
| } | ||
| } | ||
|
|
||
| // Test reproducing the problem. | ||
| [Test] | ||
| public async Task GetPersonTestAsync() | ||
| { | ||
| using (var session = OpenSession()) | ||
| { | ||
| var person1_2 = await (session.GetAsync<Person>(new PersonCpId { IdA = 1, IdB = 2 })); | ||
| Assert.That(person1_2.Name, Is.EqualTo("PERSON_1_2")); | ||
| Assert.That( | ||
| person1_2.EmploymentList.Select(e => e.Name), | ||
| Is.EquivalentTo(new[] { "EMPLOYMENT_13_1_1_7_8", "EMPLOYMENT_14_1_1_9_10" })); | ||
| } | ||
| } | ||
|
|
||
| // Test reproducing the problem. | ||
| [Test] | ||
| public async Task GetEmployerTestAsync() | ||
| { | ||
| using (var session = OpenSession()) | ||
| { | ||
| var employer7_8 = await (session.GetAsync<Employer>(new EmployerCpId { IdA = 7, IdB = 8 })); | ||
| Assert.That(employer7_8.Name, Is.EqualTo("EMPLOYER_7_8")); | ||
| Assert.That( | ||
| employer7_8.EmploymentList.Select(e => e.Name), | ||
| Is.EquivalentTo(new[] { "EMPLOYMENT_13_1_1_7_8" })); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task GetEmploymentTestAsync() | ||
| { | ||
| using (var session = OpenSession()) | ||
| { | ||
| var employment_13_1_2_7_8 = | ||
| await (session.GetAsync<Employment>( | ||
| new EmploymentCpId | ||
| { | ||
| Id = 13, | ||
| PersonObj = | ||
| new Person | ||
| { | ||
| CpId = new PersonCpId { IdA = 1, IdB = 2 } | ||
| }, | ||
| EmployerObj = | ||
| new Employer | ||
| { | ||
| CpId = new EmployerCpId { IdA = 7, IdB = 8 } | ||
| } | ||
| })); | ||
| Assert.That(employment_13_1_2_7_8.Name, Is.EqualTo("EMPLOYMENT_13_1_1_7_8")); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task HqlPersonPositionalAsync() | ||
| { | ||
| using (var session = OpenSession()) | ||
| { | ||
| var personList = | ||
| await (session | ||
| .GetNamedQuery("personPositional") | ||
| .SetParameter(0, new PersonCpId { IdA = 1, IdB = 2 }) | ||
| .SetParameter(1, new PersonCpId { IdA = 3, IdB = 4 }) | ||
| .ListAsync<Person>()); | ||
| Assert.That( | ||
| personList.Select(e => e.Name), | ||
| Is.EquivalentTo(new[] { "PERSON_1_2", "PERSON_3_4" })); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task HqlPersonNamedAsync() | ||
| { | ||
| using (var session = OpenSession()) | ||
| { | ||
| var personList = | ||
| await (session | ||
| .GetNamedQuery("personNamed") | ||
| .SetParameter("id1", new PersonCpId { IdA = 1, IdB = 2 }) | ||
| .SetParameter("id2", new PersonCpId { IdA = 3, IdB = 4 }) | ||
| .ListAsync<Person>()); | ||
| Assert.That( | ||
| personList.Select(e => e.Name), | ||
| Is.EquivalentTo(new[] { "PERSON_1_2", "PERSON_3_4" })); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task GetPersonNoComponentAsync() | ||
| { | ||
| using (var session = OpenSession()) | ||
| { | ||
| var person17_18 = | ||
| await (session.GetAsync<PersonNoComponent>(new PersonNoComponent { IdA = 17, IdB = 18 })); | ||
| Assert.That(person17_18.Name, Is.EqualTo("PERSON_NO_COMPONENT_17_18")); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task SqlPersonNoComponentAsync() | ||
| { | ||
| using (var session = OpenSession()) | ||
| { | ||
| var personList = | ||
| await (session | ||
| .GetNamedQuery("personNoComponentSql") | ||
| .SetParameter(0, new PersonNoComponent { IdA = 17, IdB = 18 }) | ||
| .SetParameter(1, new PersonNoComponent { IdA = 19, IdB = 20 }) | ||
| .ListAsync<PersonNoComponent>()); | ||
| Assert.That( | ||
| personList.Select(e => e.Name), | ||
| Is.EquivalentTo(new[] { "PERSON_NO_COMPONENT_17_18", "PERSON_NO_COMPONENT_19_20" })); | ||
| } | ||
| } | ||
| } | ||
| } |
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,13 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace NHibernate.Test.NHSpecificTest.NH3079 | ||
| { | ||
| public class Employer | ||
| { | ||
| public virtual EmployerCpId CpId { get; set; } | ||
|
|
||
| public virtual string Name { get; set; } | ||
|
|
||
| public virtual ICollection<Employment> EmploymentList { 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| namespace NHibernate.Test.NHSpecificTest.NH3079 | ||
| { | ||
| public class EmployerCpId | ||
| { | ||
| public virtual int IdA { get; set; } | ||
|
|
||
| public virtual int IdB { get; set; } | ||
|
|
||
| public override bool Equals(object obj) | ||
| { | ||
| if (!(obj is EmployerCpId objCpId)) | ||
| return false; | ||
|
|
||
| return IdA == objCpId.IdA && IdB == objCpId.IdB; | ||
| } | ||
|
|
||
| public override int GetHashCode() | ||
| { | ||
| return IdA.GetHashCode() ^ IdB.GetHashCode(); | ||
| } | ||
| } | ||
| } |
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,9 @@ | ||
| namespace NHibernate.Test.NHSpecificTest.NH3079 | ||
| { | ||
| public class Employment | ||
| { | ||
| public virtual EmploymentCpId CpId { get; set; } | ||
|
|
||
| public virtual string Name { get; set; } | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
src/NHibernate.Test/NHSpecificTest/NH3079/EmploymentCpId.cs
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,25 @@ | ||
| namespace NHibernate.Test.NHSpecificTest.NH3079 | ||
| { | ||
| public class EmploymentCpId | ||
| { | ||
| public virtual int Id { get; set; } | ||
|
|
||
| public virtual Person PersonObj { get; set; } | ||
|
|
||
| public virtual Employer EmployerObj { get; set; } | ||
|
|
||
| public override bool Equals(object obj) | ||
| { | ||
| if (!(obj is EmploymentCpId objCpId)) | ||
| return false; | ||
|
|
||
| return Id == objCpId.Id && PersonObj.CpId == objCpId.PersonObj.CpId && | ||
| EmployerObj.CpId == objCpId.EmployerObj.CpId; | ||
| } | ||
|
|
||
| public override int GetHashCode() | ||
| { | ||
| return Id.GetHashCode() ^ PersonObj.CpId.GetHashCode() ^ EmployerObj.CpId.GetHashCode(); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not ignoring it would cause an interface change by adding an async counterpart to a method belonging to an interface.
Moreover it generates an async counterpart due to a second level cache check, which would incurs IO only if a distributed cache is enabled.
There is also an
IType.GetPropertyValuecall which has an async counterpart, but it is called only on component types which currently have a fully synchronous implementation for it.