From cbcf12bd1124e0a3f0b2e4942e7c8d333ec7fc70 Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Fri, 22 Feb 2019 16:10:38 +0200 Subject: [PATCH 1/8] Proper dispose in unstable MySql test --- .../Async/Legacy/FooBarTest.cs | 745 +++++++++--------- src/NHibernate.Test/Legacy/FooBarTest.cs | 745 +++++++++--------- 2 files changed, 748 insertions(+), 742 deletions(-) diff --git a/src/NHibernate.Test/Async/Legacy/FooBarTest.cs b/src/NHibernate.Test/Async/Legacy/FooBarTest.cs index 282c2b6754f..0802496aa74 100644 --- a/src/NHibernate.Test/Async/Legacy/FooBarTest.cs +++ b/src/NHibernate.Test/Async/Legacy/FooBarTest.cs @@ -435,467 +435,470 @@ private static bool ContainsSingleObject(IEnumerable enumerable, object obj) [Test] public async Task QueryAsync() { - ISession s = OpenSession(); - ITransaction txn = s.BeginTransaction(); - Foo foo = new Foo(); - await (s.SaveAsync(foo)); - Foo foo2 = new Foo(); - await (s.SaveAsync(foo2)); - foo.TheFoo = foo2; - - IList list = await (s.CreateQuery("from Foo foo inner join fetch foo.TheFoo").ListAsync()); - Foo foof = (Foo) list[0]; - Assert.IsTrue(NHibernateUtil.IsInitialized(foof.TheFoo)); - - list = await (s.CreateQuery("from Baz baz left outer join fetch baz.FooToGlarch").ListAsync()); + Foo foo = null; + using (var s = OpenSession()) + using (var txn = s.BeginTransaction()) + { + foo = new Foo(); + await (s.SaveAsync(foo)); + Foo foo2 = new Foo(); + await (s.SaveAsync(foo2)); + foo.TheFoo = foo2; - list = await (s.CreateQuery("select foo, bar from Foo foo left outer join foo.TheFoo bar where foo = ?") - .SetEntity(0, foo).ListAsync()); + IList list = await (s.CreateQuery("from Foo foo inner join fetch foo.TheFoo").ListAsync()); + Foo foof = (Foo) list[0]; + Assert.IsTrue(NHibernateUtil.IsInitialized(foof.TheFoo)); - object[] row1 = (object[]) list[0]; - Assert.IsTrue(row1[0] == foo && row1[1] == foo2); + list = await (s.CreateQuery("from Baz baz left outer join fetch baz.FooToGlarch").ListAsync()); - await (s.CreateQuery("select foo.TheFoo.TheFoo.String from foo in class Foo where foo.TheFoo = 'bar'").ListAsync()); - await (s.CreateQuery("select foo.TheFoo.TheFoo.TheFoo.String from foo in class Foo where foo.TheFoo.TheFoo = 'bar'").ListAsync()); - await (s.CreateQuery("select foo.TheFoo.TheFoo.String from foo in class Foo where foo.TheFoo.TheFoo.TheFoo.String = 'bar'"). - ListAsync()); - // if( !( dialect is Dialect.HSQLDialect ) ) - // { - await (s.CreateQuery("select foo.String from foo in class Foo where foo.TheFoo.TheFoo.TheFoo = foo.TheFoo.TheFoo").ListAsync()); - // } - await (s.CreateQuery( - "select foo.String from foo in class Foo where foo.TheFoo.TheFoo = 'bar' and foo.TheFoo.TheFoo.TheFoo = 'baz'").ListAsync - ()); - await (s.CreateQuery( - "select foo.String from foo in class Foo where foo.TheFoo.TheFoo.TheFoo.String = 'a' and foo.TheFoo.String = 'b'"). - ListAsync()); + list = await (s.CreateQuery("select foo, bar from Foo foo left outer join foo.TheFoo bar where foo = ?") + .SetEntity(0, foo).ListAsync()); - await (s.CreateQuery("from bar in class Bar, foo in elements(bar.Baz.FooArray)").ListAsync()); + object[] row1 = (object[]) list[0]; + Assert.IsTrue(row1[0] == foo && row1[1] == foo2); - if (Dialect is DB2Dialect) - { - await (s.CreateQuery("from foo in class Foo where lower( foo.TheFoo.String ) = 'foo'").ListAsync()); - await (s.CreateQuery("from foo in class Foo where lower( (foo.TheFoo.String || 'foo') || 'bar' ) = 'foo'").ListAsync()); - await (s.CreateQuery("from foo in class Foo where repeat( (foo.TheFoo.STring || 'foo') || 'bar', 2 ) = 'foo'").ListAsync()); + await (s.CreateQuery("select foo.TheFoo.TheFoo.String from foo in class Foo where foo.TheFoo = 'bar'").ListAsync()); + await (s.CreateQuery("select foo.TheFoo.TheFoo.TheFoo.String from foo in class Foo where foo.TheFoo.TheFoo = 'bar'").ListAsync()); + await (s.CreateQuery("select foo.TheFoo.TheFoo.String from foo in class Foo where foo.TheFoo.TheFoo.TheFoo.String = 'bar'"). + ListAsync()); + // if( !( dialect is Dialect.HSQLDialect ) ) + // { + await (s.CreateQuery("select foo.String from foo in class Foo where foo.TheFoo.TheFoo.TheFoo = foo.TheFoo.TheFoo").ListAsync()); + // } await (s.CreateQuery( - "From foo in class Bar where foo.TheFoo.Integer is not null and repeat( (foo.TheFoo.String || 'foo') || 'bar', (5+5)/2 ) = 'foo'") - .ListAsync()); + "select foo.String from foo in class Foo where foo.TheFoo.TheFoo = 'bar' and foo.TheFoo.TheFoo.TheFoo = 'baz'").ListAsync + ()); await (s.CreateQuery( - "From foo in class Bar where foo.TheFoo.Integer is not null or repeat( (foo.TheFoo.String || 'foo') || 'bar', (5+5)/2 ) = 'foo'") - .ListAsync()); - } + "select foo.String from foo in class Foo where foo.TheFoo.TheFoo.TheFoo.String = 'a' and foo.TheFoo.String = 'b'"). + ListAsync()); - if (Dialect is MsSql2000Dialect) - { - await (s.CreateQuery("select baz from Baz as baz join baz.FooArray foo group by baz order by sum(foo.Float)").EnumerableAsync()); - } + await (s.CreateQuery("from bar in class Bar, foo in elements(bar.Baz.FooArray)").ListAsync()); + + if (Dialect is DB2Dialect) + { + await (s.CreateQuery("from foo in class Foo where lower( foo.TheFoo.String ) = 'foo'").ListAsync()); + await (s.CreateQuery("from foo in class Foo where lower( (foo.TheFoo.String || 'foo') || 'bar' ) = 'foo'").ListAsync()); + await (s.CreateQuery("from foo in class Foo where repeat( (foo.TheFoo.STring || 'foo') || 'bar', 2 ) = 'foo'").ListAsync()); + await (s.CreateQuery( + "From foo in class Bar where foo.TheFoo.Integer is not null and repeat( (foo.TheFoo.String || 'foo') || 'bar', (5+5)/2 ) = 'foo'") + .ListAsync()); + await (s.CreateQuery( + "From foo in class Bar where foo.TheFoo.Integer is not null or repeat( (foo.TheFoo.String || 'foo') || 'bar', (5+5)/2 ) = 'foo'") + .ListAsync()); + } - await (s.CreateQuery("from Foo as foo where foo.Component.Glarch.Name is not null").ListAsync()); - await (s.CreateQuery("from Foo as foo left outer join foo.Component.Glarch as glarch where glarch.Name = 'foo'").ListAsync()); + if (Dialect is MsSql2000Dialect) + { + await (s.CreateQuery("select baz from Baz as baz join baz.FooArray foo group by baz order by sum(foo.Float)").EnumerableAsync()); + } - list = await (s.CreateQuery("from Foo").ListAsync()); - Assert.AreEqual(2, list.Count); - Assert.IsTrue(list[0] is FooProxy); - list = await (s.CreateQuery("from Foo foo left outer join foo.TheFoo").ListAsync()); - Assert.AreEqual(2, list.Count); - Assert.IsTrue(((object[]) list[0])[0] is FooProxy); + await (s.CreateQuery("from Foo as foo where foo.Component.Glarch.Name is not null").ListAsync()); + await (s.CreateQuery("from Foo as foo left outer join foo.Component.Glarch as glarch where glarch.Name = 'foo'").ListAsync()); - await (s.CreateQuery("From Foo, Bar").ListAsync()); - await (s.CreateQuery("from Baz baz left join baz.FooToGlarch, Bar bar join bar.TheFoo").ListAsync()); - await (s.CreateQuery("from Baz baz left join baz.FooToGlarch join baz.FooSet").ListAsync()); - await (s.CreateQuery("from Baz baz left join baz.FooToGlarch join fetch baz.FooSet foo left join fetch foo.TheFoo").ListAsync()); + list = await (s.CreateQuery("from Foo").ListAsync()); + Assert.AreEqual(2, list.Count); + Assert.IsTrue(list[0] is FooProxy); + list = await (s.CreateQuery("from Foo foo left outer join foo.TheFoo").ListAsync()); + Assert.AreEqual(2, list.Count); + Assert.IsTrue(((object[]) list[0])[0] is FooProxy); - list = - await (s.CreateQuery( - "from foo in class NHibernate.DomainModel.Foo where foo.String='osama bin laden' and foo.Boolean = true order by foo.String asc, foo.Component.Count desc") - .ListAsync()); - Assert.AreEqual(0, list.Count, "empty query"); - IEnumerable enumerable = - await (s.CreateQuery( - "from foo in class NHibernate.DomainModel.Foo where foo.String='osama bin laden' order by foo.String asc, foo.Component.Count desc") - .EnumerableAsync()); - Assert.IsTrue(IsEmpty(enumerable), "empty enumerator"); + await (s.CreateQuery("From Foo, Bar").ListAsync()); + await (s.CreateQuery("from Baz baz left join baz.FooToGlarch, Bar bar join bar.TheFoo").ListAsync()); + await (s.CreateQuery("from Baz baz left join baz.FooToGlarch join baz.FooSet").ListAsync()); + await (s.CreateQuery("from Baz baz left join baz.FooToGlarch join fetch baz.FooSet foo left join fetch foo.TheFoo").ListAsync()); - list = await (s.CreateQuery("select foo.TheFoo from foo in class NHibernate.DomainModel.Foo").ListAsync()); - Assert.AreEqual(1, list.Count, "query"); - Assert.AreEqual(foo.TheFoo, list[0], "returned object"); - foo.TheFoo.TheFoo = foo; - foo.String = "fizard"; + list = + await (s.CreateQuery( + "from foo in class NHibernate.DomainModel.Foo where foo.String='osama bin laden' and foo.Boolean = true order by foo.String asc, foo.Component.Count desc") + .ListAsync()); + Assert.AreEqual(0, list.Count, "empty query"); + IEnumerable enumerable = + await (s.CreateQuery( + "from foo in class NHibernate.DomainModel.Foo where foo.String='osama bin laden' order by foo.String asc, foo.Component.Count desc") + .EnumerableAsync()); + Assert.IsTrue(IsEmpty(enumerable), "empty enumerator"); - if (Dialect.SupportsSubSelects && TestDialect.SupportsOperatorSome) - { - if (!(Dialect is FirebirdDialect)) - { - list = await (s.CreateQuery( - "from foo in class NHibernate.DomainModel.Foo where ? = some elements(foo.Component.ImportantDates)"). - SetDateTime(0, DateTime.Today).ListAsync()); - - Assert.AreEqual(2, list.Count, "component query"); - } + list = await (s.CreateQuery("select foo.TheFoo from foo in class NHibernate.DomainModel.Foo").ListAsync()); + Assert.AreEqual(1, list.Count, "query"); + Assert.AreEqual(foo.TheFoo, list[0], "returned object"); + foo.TheFoo.TheFoo = foo; + foo.String = "fizard"; - if (Dialect.SupportsScalarSubSelects) + if (Dialect.SupportsSubSelects && TestDialect.SupportsOperatorSome) { - list = - await (s.CreateQuery("from foo in class NHibernate.DomainModel.Foo where size(foo.Component.ImportantDates) = 3").ListAsync()); + if (!(Dialect is FirebirdDialect)) + { + list = await (s.CreateQuery( + "from foo in class NHibernate.DomainModel.Foo where ? = some elements(foo.Component.ImportantDates)"). + SetDateTime(0, DateTime.Today).ListAsync()); + + Assert.AreEqual(2, list.Count, "component query"); + } + + if (Dialect.SupportsScalarSubSelects) + { + list = + await (s.CreateQuery("from foo in class NHibernate.DomainModel.Foo where size(foo.Component.ImportantDates) = 3").ListAsync()); + Assert.AreEqual(2, list.Count, "component query"); + list = await (s.CreateQuery("from foo in class Foo where 0 = size(foo.Component.ImportantDates)").ListAsync()); + Assert.AreEqual(0, list.Count, "component query"); + } + list = await (s.CreateQuery("from foo in class Foo where exists elements(foo.Component.ImportantDates)").ListAsync()); Assert.AreEqual(2, list.Count, "component query"); - list = await (s.CreateQuery("from foo in class Foo where 0 = size(foo.Component.ImportantDates)").ListAsync()); - Assert.AreEqual(0, list.Count, "component query"); - } - list = await (s.CreateQuery("from foo in class Foo where exists elements(foo.Component.ImportantDates)").ListAsync()); - Assert.AreEqual(2, list.Count, "component query"); - await (s.CreateQuery("from foo in class Foo where not exists (from bar in class Bar where bar.id = foo.id)").ListAsync()); + await (s.CreateQuery("from foo in class Foo where not exists (from bar in class Bar where bar.id = foo.id)").ListAsync()); - await (s.CreateQuery( - "select foo.TheFoo from foo in class Foo where foo = some(select x from x in class Foo where x.Long > foo.TheFoo.Long)") - .ListAsync()); - await (s.CreateQuery( - "from foo in class Foo where foo = some(select x from x in class Foo where x.Long > foo.TheFoo.Long) and foo.TheFoo.String='baz'") - .ListAsync()); - await (s.CreateQuery( - "from foo in class Foo where foo.TheFoo.String='baz' and foo = some(select x from x in class Foo where x.Long>foo.TheFoo.Long)") - .ListAsync()); - await (s.CreateQuery("from foo in class Foo where foo = some(select x from x in class Foo where x.Long > foo.TheFoo.Long)") - .ListAsync()); + await (s.CreateQuery( + "select foo.TheFoo from foo in class Foo where foo = some(select x from x in class Foo where x.Long > foo.TheFoo.Long)") + .ListAsync()); + await (s.CreateQuery( + "from foo in class Foo where foo = some(select x from x in class Foo where x.Long > foo.TheFoo.Long) and foo.TheFoo.String='baz'") + .ListAsync()); + await (s.CreateQuery( + "from foo in class Foo where foo.TheFoo.String='baz' and foo = some(select x from x in class Foo where x.Long>foo.TheFoo.Long)") + .ListAsync()); + await (s.CreateQuery("from foo in class Foo where foo = some(select x from x in class Foo where x.Long > foo.TheFoo.Long)") + .ListAsync()); - await (s.CreateQuery( - "select foo.String, foo.Date, foo.TheFoo.String, foo.id from foo in class Foo, baz in class Baz where foo in elements(baz.FooArray) and foo.String like 'foo'") - .EnumerableAsync()); - } + await (s.CreateQuery( + "select foo.String, foo.Date, foo.TheFoo.String, foo.id from foo in class Foo, baz in class Baz where foo in elements(baz.FooArray) and foo.String like 'foo'") + .EnumerableAsync()); + } - list = await (s.CreateQuery("from foo in class Foo where foo.Component.Count is null order by foo.Component.Count").ListAsync()); - Assert.AreEqual(0, list.Count, "component query"); + list = await (s.CreateQuery("from foo in class Foo where foo.Component.Count is null order by foo.Component.Count").ListAsync()); + Assert.AreEqual(0, list.Count, "component query"); - list = await (s.CreateQuery("from foo in class Foo where foo.Component.Name='foo'").ListAsync()); - Assert.AreEqual(2, list.Count, "component query"); + list = await (s.CreateQuery("from foo in class Foo where foo.Component.Name='foo'").ListAsync()); + Assert.AreEqual(2, list.Count, "component query"); - list = - await (s.CreateQuery( - "select distinct foo.Component.Name, foo.Component.Name from foo in class Foo where foo.Component.Name='foo'").ListAsync - ()); - Assert.AreEqual(1, list.Count, "component query"); + list = + await (s.CreateQuery( + "select distinct foo.Component.Name, foo.Component.Name from foo in class Foo where foo.Component.Name='foo'").ListAsync + ()); + Assert.AreEqual(1, list.Count, "component query"); - list = - await (s.CreateQuery("select distinct foo.Component.Name, foo.id from foo in class Foo where foo.Component.Name='foo'"). - ListAsync()); - Assert.AreEqual(2, list.Count, "component query"); + list = + await (s.CreateQuery("select distinct foo.Component.Name, foo.id from foo in class Foo where foo.Component.Name='foo'"). + ListAsync()); + Assert.AreEqual(2, list.Count, "component query"); - list = await (s.CreateQuery("select foo.TheFoo from foo in class Foo").ListAsync()); - Assert.AreEqual(2, list.Count, "query"); + list = await (s.CreateQuery("select foo.TheFoo from foo in class Foo").ListAsync()); + Assert.AreEqual(2, list.Count, "query"); - list = await (s.CreateQuery("from foo in class Foo where foo.id=?").SetString(0, foo.Key).ListAsync()); - Assert.AreEqual(1, list.Count, "id query"); + list = await (s.CreateQuery("from foo in class Foo where foo.id=?").SetString(0, foo.Key).ListAsync()); + Assert.AreEqual(1, list.Count, "id query"); - list = await (s.CreateQuery("from foo in class Foo where foo.Key=?").SetString(0, foo.Key).ListAsync()); - Assert.AreEqual(1, list.Count, "named id query"); - Assert.AreSame(foo, list[0], "id query"); + list = await (s.CreateQuery("from foo in class Foo where foo.Key=?").SetString(0, foo.Key).ListAsync()); + Assert.AreEqual(1, list.Count, "named id query"); + Assert.AreSame(foo, list[0], "id query"); - list = await (s.CreateQuery("select foo.TheFoo from foo in class Foo where foo.String='fizard'").ListAsync()); - Assert.AreEqual(1, list.Count, "query"); - Assert.AreSame(foo.TheFoo, list[0], "returned object"); + list = await (s.CreateQuery("select foo.TheFoo from foo in class Foo where foo.String='fizard'").ListAsync()); + Assert.AreEqual(1, list.Count, "query"); + Assert.AreSame(foo.TheFoo, list[0], "returned object"); - list = await (s.CreateQuery("from foo in class Foo where foo.Component.Subcomponent.Name='bar'").ListAsync()); - Assert.AreEqual(2, list.Count, "components of components"); + list = await (s.CreateQuery("from foo in class Foo where foo.Component.Subcomponent.Name='bar'").ListAsync()); + Assert.AreEqual(2, list.Count, "components of components"); - list = await (s.CreateQuery("select foo.TheFoo from foo in class Foo where foo.TheFoo.id=?") - .SetString(0, foo.TheFoo.Key).ListAsync()); - Assert.AreEqual(1, list.Count, "by id query"); - Assert.AreSame(foo.TheFoo, list[0], "by id returned object"); + list = await (s.CreateQuery("select foo.TheFoo from foo in class Foo where foo.TheFoo.id=?") + .SetString(0, foo.TheFoo.Key).ListAsync()); + Assert.AreEqual(1, list.Count, "by id query"); + Assert.AreSame(foo.TheFoo, list[0], "by id returned object"); - await (s.CreateQuery("from foo in class Foo where foo.TheFoo = ?").SetEntity(0, foo.TheFoo).ListAsync()); + await (s.CreateQuery("from foo in class Foo where foo.TheFoo = ?").SetEntity(0, foo.TheFoo).ListAsync()); - Assert.IsTrue( - IsEmpty(await (s.CreateQuery("from bar in class Bar where bar.String='a string' or bar.String='a string'").EnumerableAsync()) - )); + Assert.IsTrue( + IsEmpty(await (s.CreateQuery("from bar in class Bar where bar.String='a string' or bar.String='a string'").EnumerableAsync()) + )); - enumerable = await (s.CreateQuery( - "select foo.Component.Name, elements(foo.Component.ImportantDates) from foo in class Foo where foo.TheFoo.id=?"). - SetString(0, foo.TheFoo.Key).EnumerableAsync()); + enumerable = await (s.CreateQuery( + "select foo.Component.Name, elements(foo.Component.ImportantDates) from foo in class Foo where foo.TheFoo.id=?"). + SetString(0, foo.TheFoo.Key).EnumerableAsync()); - int i = 0; - foreach (object[] row in enumerable) - { - i++; - Assert.IsTrue(row[0] is String); - Assert.IsTrue(row[1] == null || row[1] is DateTime); - } - Assert.AreEqual(3, i); //WAS: 4 + int i = 0; + foreach (object[] row in enumerable) + { + i++; + Assert.IsTrue(row[0] is String); + Assert.IsTrue(row[1] == null || row[1] is DateTime); + } + Assert.AreEqual(3, i); //WAS: 4 - enumerable = await (s.CreateQuery("select max(elements(foo.Component.ImportantDates)) from foo in class Foo group by foo.id"). - EnumerableAsync()); - - IEnumerator enumerator = enumerable.GetEnumerator(); + enumerable = await (s.CreateQuery("select max(elements(foo.Component.ImportantDates)) from foo in class Foo group by foo.id"). + EnumerableAsync()); - Assert.IsTrue(enumerator.MoveNext()); - Assert.IsTrue(enumerator.Current is DateTime); + IEnumerator enumerator = enumerable.GetEnumerator(); - list = await (s.CreateQuery( - "select foo.TheFoo.TheFoo.TheFoo from foo in class Foo, foo2 in class Foo where" - + " foo = foo2.TheFoo and not not ( not foo.String='fizard' )" - + " and foo2.String between 'a' and (foo.TheFoo.String)" - + (Dialect is SQLiteDialect - ? " and ( foo2.String in ( 'fiz', 'blah') or 1=1 )" - : " and ( foo2.String in ( 'fiz', 'blah', foo.TheFoo.String, foo.String, foo2.String ) )") - ).ListAsync()); - Assert.AreEqual(1, list.Count, "complex query"); - Assert.AreSame(foo, list[0], "returned object"); + Assert.IsTrue(enumerator.MoveNext()); + Assert.IsTrue(enumerator.Current is DateTime); - foo.String = "from BoogieDown -tinsel town =!@#$^&*())"; + list = await (s.CreateQuery( + "select foo.TheFoo.TheFoo.TheFoo from foo in class Foo, foo2 in class Foo where" + + " foo = foo2.TheFoo and not not ( not foo.String='fizard' )" + + " and foo2.String between 'a' and (foo.TheFoo.String)" + + (Dialect is SQLiteDialect + ? " and ( foo2.String in ( 'fiz', 'blah') or 1=1 )" + : " and ( foo2.String in ( 'fiz', 'blah', foo.TheFoo.String, foo.String, foo2.String ) )") + ).ListAsync()); + Assert.AreEqual(1, list.Count, "complex query"); + Assert.AreSame(foo, list[0], "returned object"); - list = await (s.CreateQuery("from foo in class Foo where foo.String='from BoogieDown -tinsel town =!@#$^&*())'").ListAsync()); - Assert.AreEqual(1, list.Count, "single quotes"); + foo.String = "from BoogieDown -tinsel town =!@#$^&*())"; - list = await (s.CreateQuery("from foo in class Foo where not foo.String='foo''bar'").ListAsync()); - Assert.AreEqual(2, list.Count, "single quotes"); + list = await (s.CreateQuery("from foo in class Foo where foo.String='from BoogieDown -tinsel town =!@#$^&*())'").ListAsync()); + Assert.AreEqual(1, list.Count, "single quotes"); - list = await (s.CreateQuery("from foo in class Foo where foo.Component.Glarch.Next is null").ListAsync()); - Assert.AreEqual(2, list.Count, "query association in component"); + list = await (s.CreateQuery("from foo in class Foo where not foo.String='foo''bar'").ListAsync()); + Assert.AreEqual(2, list.Count, "single quotes"); - Bar bar = new Bar(); - Baz baz = new Baz(); - baz.SetDefaults(); - bar.Baz = baz; - baz.ManyToAny = new List(); - baz.ManyToAny.Add(bar); - baz.ManyToAny.Add(foo); - await (s.SaveAsync(bar)); - await (s.SaveAsync(baz)); - list = - await (s.CreateQuery(" from bar in class Bar where bar.Baz.Count=667 and bar.Baz.Count!=123 and not bar.Baz.Name='1-E-1'"). - ListAsync()); - Assert.AreEqual(1, list.Count, "query many-to-one"); - list = await (s.CreateQuery(" from i in class Bar where i.Baz.Name='Bazza'").ListAsync()); - Assert.AreEqual(1, list.Count, "query many-to-one"); + list = await (s.CreateQuery("from foo in class Foo where foo.Component.Glarch.Next is null").ListAsync()); + Assert.AreEqual(2, list.Count, "query association in component"); - if (TestDialect.SupportsCountDistinct) - { - enumerable = await (s.CreateQuery("select count(distinct foo.TheFoo) from foo in class Foo").EnumerableAsync()); - Assert.IsTrue(ContainsSingleObject(enumerable, (long) 2), "count"); // changed to Int64 (HQLFunction H3.2) - } + Bar bar = new Bar(); + Baz baz = new Baz(); + baz.SetDefaults(); + bar.Baz = baz; + baz.ManyToAny = new List(); + baz.ManyToAny.Add(bar); + baz.ManyToAny.Add(foo); + await (s.SaveAsync(bar)); + await (s.SaveAsync(baz)); + list = + await (s.CreateQuery(" from bar in class Bar where bar.Baz.Count=667 and bar.Baz.Count!=123 and not bar.Baz.Name='1-E-1'"). + ListAsync()); + Assert.AreEqual(1, list.Count, "query many-to-one"); + list = await (s.CreateQuery(" from i in class Bar where i.Baz.Name='Bazza'").ListAsync()); + Assert.AreEqual(1, list.Count, "query many-to-one"); - enumerable = await (s.CreateQuery("select count(foo.TheFoo.Boolean) from foo in class Foo").EnumerableAsync()); - Assert.IsTrue(ContainsSingleObject(enumerable, (long) 2), "count"); // changed to Int64 (HQLFunction H3.2) + if (TestDialect.SupportsCountDistinct) + { + enumerable = await (s.CreateQuery("select count(distinct foo.TheFoo) from foo in class Foo").EnumerableAsync()); + Assert.IsTrue(ContainsSingleObject(enumerable, (long) 2), "count"); // changed to Int64 (HQLFunction H3.2) + } - enumerable = await (s.CreateQuery("select count(*), foo.Int from foo in class Foo group by foo.Int").EnumerableAsync()); - enumerator = enumerable.GetEnumerator(); - Assert.IsTrue(enumerator.MoveNext()); - Assert.AreEqual(3L, (long) ((object[]) enumerator.Current)[0]); - Assert.IsFalse(enumerator.MoveNext()); + enumerable = await (s.CreateQuery("select count(foo.TheFoo.Boolean) from foo in class Foo").EnumerableAsync()); + Assert.IsTrue(ContainsSingleObject(enumerable, (long) 2), "count"); // changed to Int64 (HQLFunction H3.2) - enumerable = await (s.CreateQuery("select sum(foo.TheFoo.Int) from foo in class Foo").EnumerableAsync()); - Assert.IsTrue(ContainsSingleObject(enumerable, (long) 4), "sum"); // changed to Int64 (HQLFunction H3.2) + enumerable = await (s.CreateQuery("select count(*), foo.Int from foo in class Foo group by foo.Int").EnumerableAsync()); + enumerator = enumerable.GetEnumerator(); + Assert.IsTrue(enumerator.MoveNext()); + Assert.AreEqual(3L, (long) ((object[]) enumerator.Current)[0]); + Assert.IsFalse(enumerator.MoveNext()); - enumerable = await (s.CreateQuery("select count(foo) from foo in class Foo where foo.id=?") - .SetString(0, foo.Key).EnumerableAsync()); - Assert.IsTrue(ContainsSingleObject(enumerable, (long) 1), "id query count"); + enumerable = await (s.CreateQuery("select sum(foo.TheFoo.Int) from foo in class Foo").EnumerableAsync()); + Assert.IsTrue(ContainsSingleObject(enumerable, (long) 4), "sum"); // changed to Int64 (HQLFunction H3.2) - list = await (s.CreateQuery("from foo in class Foo where foo.Boolean = ?").SetBoolean(0, true).ListAsync()); + enumerable = await (s.CreateQuery("select count(foo) from foo in class Foo where foo.id=?") + .SetString(0, foo.Key).EnumerableAsync()); + Assert.IsTrue(ContainsSingleObject(enumerable, (long) 1), "id query count"); - list = await (s.CreateQuery("select new Foo(fo.X) from Fo fo").ListAsync()); - list = await (s.CreateQuery("select new Foo(fo.Integer) from Foo fo").ListAsync()); + list = await (s.CreateQuery("from foo in class Foo where foo.Boolean = ?").SetBoolean(0, true).ListAsync()); - list = await (s.CreateQuery("select new Foo(fo.X) from Foo fo") - .SetCacheable(true) - .ListAsync()); - Assert.IsTrue(list.Count == 3); - list = await (s.CreateQuery("select new Foo(fo.X) from Foo fo") - .SetCacheable(true) - .ListAsync()); - Assert.IsTrue(list.Count == 3); + list = await (s.CreateQuery("select new Foo(fo.X) from Fo fo").ListAsync()); + list = await (s.CreateQuery("select new Foo(fo.Integer) from Foo fo").ListAsync()); - enumerable = await (s.CreateQuery("select new Foo(fo.X) from Foo fo").EnumerableAsync()); - enumerator = enumerable.GetEnumerator(); - Assert.IsTrue(enumerator.MoveNext(), "projection iterate (results)"); - Assert.IsTrue(typeof(Foo).IsAssignableFrom(enumerator.Current.GetType()), - "projection iterate (return check)"); + list = await (s.CreateQuery("select new Foo(fo.X) from Foo fo") + .SetCacheable(true) + .ListAsync()); + Assert.IsTrue(list.Count == 3); + list = await (s.CreateQuery("select new Foo(fo.X) from Foo fo") + .SetCacheable(true) + .ListAsync()); + Assert.IsTrue(list.Count == 3); - // TODO: ScrollableResults not implemented - //ScrollableResults sr = s.CreateQuery("select new Foo(fo.x) from Foo fo").Scroll(); - //Assert.IsTrue( "projection scroll (results)", sr.next() ); - //Assert.IsTrue( "projection scroll (return check)", typeof(Foo).isAssignableFrom( sr.get(0).getClass() ) ); + enumerable = await (s.CreateQuery("select new Foo(fo.X) from Foo fo").EnumerableAsync()); + enumerator = enumerable.GetEnumerator(); + Assert.IsTrue(enumerator.MoveNext(), "projection iterate (results)"); + Assert.IsTrue(typeof(Foo).IsAssignableFrom(enumerator.Current.GetType()), + "projection iterate (return check)"); - list = await (s.CreateQuery("select foo.Long, foo.Component.Name, foo, foo.TheFoo from foo in class Foo").ListAsync()); - Assert.IsTrue(list.Count > 0); - foreach (object[] row in list) - { - Assert.IsTrue(row[0] is long); - Assert.IsTrue(row[1] is string); - Assert.IsTrue(row[2] is Foo); - Assert.IsTrue(row[3] is Foo); - } + // TODO: ScrollableResults not implemented + //ScrollableResults sr = s.CreateQuery("select new Foo(fo.x) from Foo fo").Scroll(); + //Assert.IsTrue( "projection scroll (results)", sr.next() ); + //Assert.IsTrue( "projection scroll (return check)", typeof(Foo).isAssignableFrom( sr.get(0).getClass() ) ); - if (TestDialect.SupportsCountDistinct) - { - list = - await (s.CreateQuery("select avg(foo.Float), max(foo.Component.Name), count(distinct foo.id) from foo in class Foo").ListAsync()); + list = await (s.CreateQuery("select foo.Long, foo.Component.Name, foo, foo.TheFoo from foo in class Foo").ListAsync()); Assert.IsTrue(list.Count > 0); foreach (object[] row in list) { - Assert.IsTrue(row[0] is double); // changed from float to double (HQLFunction H3.2) + Assert.IsTrue(row[0] is long); Assert.IsTrue(row[1] is string); - Assert.IsTrue(row[2] is long); // changed from int to long (HQLFunction H3.2) + Assert.IsTrue(row[2] is Foo); + Assert.IsTrue(row[3] is Foo); } - } - list = await (s.CreateQuery("select foo.Long, foo.Component, foo, foo.TheFoo from foo in class Foo").ListAsync()); - Assert.IsTrue(list.Count > 0); - foreach (object[] row in list) - { - Assert.IsTrue(row[0] is long); - Assert.IsTrue(row[1] is FooComponent); - Assert.IsTrue(row[2] is Foo); - Assert.IsTrue(row[3] is Foo); - } + if (TestDialect.SupportsCountDistinct) + { + list = + await (s.CreateQuery("select avg(foo.Float), max(foo.Component.Name), count(distinct foo.id) from foo in class Foo").ListAsync()); + Assert.IsTrue(list.Count > 0); + foreach (object[] row in list) + { + Assert.IsTrue(row[0] is double); // changed from float to double (HQLFunction H3.2) + Assert.IsTrue(row[1] is string); + Assert.IsTrue(row[2] is long); // changed from int to long (HQLFunction H3.2) + } + } - await (s.SaveAsync(new Holder("ice T"))); - await (s.SaveAsync(new Holder("ice cube"))); + list = await (s.CreateQuery("select foo.Long, foo.Component, foo, foo.TheFoo from foo in class Foo").ListAsync()); + Assert.IsTrue(list.Count > 0); + foreach (object[] row in list) + { + Assert.IsTrue(row[0] is long); + Assert.IsTrue(row[1] is FooComponent); + Assert.IsTrue(row[2] is Foo); + Assert.IsTrue(row[3] is Foo); + } - Assert.AreEqual(15, (await (s.CreateQuery("from o in class System.Object").ListAsync())).Count); - Assert.AreEqual(7, (await (s.CreateQuery("from n in class INamed").ListAsync())).Count); - Assert.IsTrue((await (s.CreateQuery("from n in class INamed where n.Name is not null").ListAsync())).Count == 4); + await (s.SaveAsync(new Holder("ice T"))); + await (s.SaveAsync(new Holder("ice cube"))); - foreach (INamed named in await (s.CreateQuery("from n in class INamed").EnumerableAsync())) - { - Assert.IsNotNull(named); - } + Assert.AreEqual(15, (await (s.CreateQuery("from o in class System.Object").ListAsync())).Count); + Assert.AreEqual(7, (await (s.CreateQuery("from n in class INamed").ListAsync())).Count); + Assert.IsTrue((await (s.CreateQuery("from n in class INamed where n.Name is not null").ListAsync())).Count == 4); - await (s.SaveAsync(new Holder("bar"))); - enumerable = await (s.CreateQuery("from n0 in class INamed, n1 in class INamed where n0.Name = n1.Name").EnumerableAsync()); - int cnt = 0; - foreach (object[] row in enumerable) - { - if (row[0] != row[1]) + foreach (INamed named in await (s.CreateQuery("from n in class INamed").EnumerableAsync())) { - cnt++; + Assert.IsNotNull(named); } - } - //if ( !(dialect is Dialect.HSQLDialect) ) - //{ - Assert.IsTrue(cnt == 2); - Assert.IsTrue((await (s.CreateQuery("from n0 in class INamed, n1 in class INamed where n0.Name = n1.Name").ListAsync())).Count == 7); - //} + await (s.SaveAsync(new Holder("bar"))); + enumerable = await (s.CreateQuery("from n0 in class INamed, n1 in class INamed where n0.Name = n1.Name").EnumerableAsync()); + int cnt = 0; + foreach (object[] row in enumerable) + { + if (row[0] != row[1]) + { + cnt++; + } + } - IQuery qu = s.CreateQuery("from n in class INamed where n.Name = :name"); - object temp = qu.ReturnTypes; - temp = qu.NamedParameters; + //if ( !(dialect is Dialect.HSQLDialect) ) + //{ + Assert.IsTrue(cnt == 2); + Assert.IsTrue((await (s.CreateQuery("from n0 in class INamed, n1 in class INamed where n0.Name = n1.Name").ListAsync())).Count == 7); + //} - int c = 0; + IQuery qu = s.CreateQuery("from n in class INamed where n.Name = :name"); + object temp = qu.ReturnTypes; + temp = qu.NamedParameters; - foreach (object obj in await (s.CreateQuery("from o in class System.Object").EnumerableAsync())) - { - c++; - } - Assert.IsTrue(c == 16); + int c = 0; - await (s.CreateQuery("select baz.Code, min(baz.Count) from baz in class Baz group by baz.Code").EnumerableAsync()); + foreach (object obj in await (s.CreateQuery("from o in class System.Object").EnumerableAsync())) + { + c++; + } + Assert.IsTrue(c == 16); - Assert.IsTrue( - IsEmpty( - await (s.CreateQuery( - "selecT baz from baz in class Baz where baz.StringDateMap['foo'] is not null or baz.StringDateMap['bar'] = ?") - .SetDateTime(0, DateTime.Today).EnumerableAsync()))); + await (s.CreateQuery("select baz.Code, min(baz.Count) from baz in class Baz group by baz.Code").EnumerableAsync()); - list = await (s.CreateQuery("select baz from baz in class Baz where baz.StringDateMap['now'] is not null").ListAsync()); - Assert.AreEqual(1, list.Count); + Assert.IsTrue( + IsEmpty( + await (s.CreateQuery( + "selecT baz from baz in class Baz where baz.StringDateMap['foo'] is not null or baz.StringDateMap['bar'] = ?") + .SetDateTime(0, DateTime.Today).EnumerableAsync()))); - list = - await (s.CreateQuery("select baz from baz in class Baz where baz.StringDateMap[:now] is not null").SetString("now", "now"). - ListAsync()); - Assert.AreEqual(1, list.Count); + list = await (s.CreateQuery("select baz from baz in class Baz where baz.StringDateMap['now'] is not null").ListAsync()); + Assert.AreEqual(1, list.Count); + + list = + await (s.CreateQuery("select baz from baz in class Baz where baz.StringDateMap[:now] is not null").SetString("now", "now"). + ListAsync()); + Assert.AreEqual(1, list.Count); + + list = + await (s.CreateQuery( + "select baz from baz in class Baz where baz.StringDateMap['now'] is not null and baz.StringDateMap['big bang'] < baz.StringDateMap['now']") + .ListAsync()); + Assert.AreEqual(1, list.Count); + + list = await (s.CreateQuery("select index(date) from Baz baz join baz.StringDateMap date").ListAsync()); + Console.WriteLine(list); + Assert.AreEqual(3, list.Count); - list = await (s.CreateQuery( - "select baz from baz in class Baz where baz.StringDateMap['now'] is not null and baz.StringDateMap['big bang'] < baz.StringDateMap['now']") + "from foo in class Foo where foo.Integer not between 1 and 5 and foo.String not in ('cde', 'abc') and foo.String is not null and foo.Integer<=3") .ListAsync()); - Assert.AreEqual(1, list.Count); - list = await (s.CreateQuery("select index(date) from Baz baz join baz.StringDateMap date").ListAsync()); - Console.WriteLine(list); - Assert.AreEqual(3, list.Count); + await (s.CreateQuery("from Baz baz inner join baz.CollectionComponent.Nested.Foos foo where foo.String is null").ListAsync()); + if (Dialect.SupportsSubSelects) + { + await (s.CreateQuery("from Baz baz inner join baz.FooSet where '1' in (from baz.FooSet foo where foo.String is not null)"). + ListAsync()); + await (s.CreateQuery( + "from Baz baz where 'a' in elements(baz.CollectionComponent.Nested.Foos) and 1.0 in elements(baz.CollectionComponent.Nested.Floats)") + .ListAsync()); + await (s.CreateQuery( + "from Baz baz where 'b' in elements(baz.CollectionComponent.Nested.Foos) and 1.0 in elements(baz.CollectionComponent.Nested.Floats)") + .ListAsync()); + } - await (s.CreateQuery( - "from foo in class Foo where foo.Integer not between 1 and 5 and foo.String not in ('cde', 'abc') and foo.String is not null and foo.Integer<=3") - .ListAsync()); + await (s.CreateQuery("from Foo foo join foo.TheFoo where foo.TheFoo in ('1','2','3')").ListAsync()); - await (s.CreateQuery("from Baz baz inner join baz.CollectionComponent.Nested.Foos foo where foo.String is null").ListAsync()); - if (Dialect.SupportsSubSelects) - { - await (s.CreateQuery("from Baz baz inner join baz.FooSet where '1' in (from baz.FooSet foo where foo.String is not null)"). + //if ( !(dialect is Dialect.HSQLDialect) ) + await (s.CreateQuery("from Foo foo left join foo.TheFoo where foo.TheFoo in ('1','2','3')").ListAsync()); + await (s.CreateQuery("select foo.TheFoo from Foo foo where foo.TheFoo in ('1','2','3')").ListAsync()); + await (s.CreateQuery("select foo.TheFoo.String from Foo foo where foo.TheFoo in ('1','2','3')").ListAsync()); + await (s.CreateQuery("select foo.TheFoo.String from Foo foo where foo.TheFoo.String in ('1','2','3')").ListAsync()); + await (s.CreateQuery("select foo.TheFoo.Long from Foo foo where foo.TheFoo.String in ('1','2','3')").ListAsync()); + await (s.CreateQuery("select count(*) from Foo foo where foo.TheFoo.String in ('1','2','3') or foo.TheFoo.Long in (1,2,3)"). ListAsync()); + await (s.CreateQuery("select count(*) from Foo foo where foo.TheFoo.String in ('1','2','3') group by foo.TheFoo.Long").ListAsync()); + + await (s.CreateQuery("from Foo foo1 left join foo1.TheFoo foo2 left join foo2.TheFoo where foo1.String is not null").ListAsync()); + await (s.CreateQuery("from Foo foo1 left join foo1.TheFoo.TheFoo where foo1.String is not null").ListAsync()); await (s.CreateQuery( - "from Baz baz where 'a' in elements(baz.CollectionComponent.Nested.Foos) and 1.0 in elements(baz.CollectionComponent.Nested.Floats)") - .ListAsync()); - await (s.CreateQuery( - "from Baz baz where 'b' in elements(baz.CollectionComponent.Nested.Foos) and 1.0 in elements(baz.CollectionComponent.Nested.Floats)") - .ListAsync()); - } + "from Foo foo1 left join foo1.TheFoo foo2 left join foo1.TheFoo.TheFoo foo3 where foo1.String is not null").ListAsync()); - await (s.CreateQuery("from Foo foo join foo.TheFoo where foo.TheFoo in ('1','2','3')").ListAsync()); + await (s.CreateQuery("select foo.Formula from Foo foo where foo.Formula > 0").ListAsync()); - //if ( !(dialect is Dialect.HSQLDialect) ) - await (s.CreateQuery("from Foo foo left join foo.TheFoo where foo.TheFoo in ('1','2','3')").ListAsync()); - await (s.CreateQuery("select foo.TheFoo from Foo foo where foo.TheFoo in ('1','2','3')").ListAsync()); - await (s.CreateQuery("select foo.TheFoo.String from Foo foo where foo.TheFoo in ('1','2','3')").ListAsync()); - await (s.CreateQuery("select foo.TheFoo.String from Foo foo where foo.TheFoo.String in ('1','2','3')").ListAsync()); - await (s.CreateQuery("select foo.TheFoo.Long from Foo foo where foo.TheFoo.String in ('1','2','3')").ListAsync()); - await (s.CreateQuery("select count(*) from Foo foo where foo.TheFoo.String in ('1','2','3') or foo.TheFoo.Long in (1,2,3)"). - ListAsync()); - await (s.CreateQuery("select count(*) from Foo foo where foo.TheFoo.String in ('1','2','3') group by foo.TheFoo.Long").ListAsync()); + int len = (await (s.CreateQuery("from Foo as foo join foo.TheFoo as foo2 where foo2.id >'a' or foo2.id <'a'").ListAsync())).Count; + Assert.IsTrue(len == 2); - await (s.CreateQuery("from Foo foo1 left join foo1.TheFoo foo2 left join foo2.TheFoo where foo1.String is not null").ListAsync()); - await (s.CreateQuery("from Foo foo1 left join foo1.TheFoo.TheFoo where foo1.String is not null").ListAsync()); - await (s.CreateQuery( - "from Foo foo1 left join foo1.TheFoo foo2 left join foo1.TheFoo.TheFoo foo3 where foo1.String is not null").ListAsync()); - - await (s.CreateQuery("select foo.Formula from Foo foo where foo.Formula > 0").ListAsync()); + await (s.DeleteAsync("from Holder")); + await (txn.CommitAsync()); + } - int len = (await (s.CreateQuery("from Foo as foo join foo.TheFoo as foo2 where foo2.id >'a' or foo2.id <'a'").ListAsync())).Count; - Assert.IsTrue(len == 2); + using (var s = OpenSession()) + using (var txn = s.BeginTransaction()) + { + var baz = (Baz) await (s.CreateQuery("from Baz baz left outer join fetch baz.ManyToAny").UniqueResultAsync()); + Assert.IsTrue(NHibernateUtil.IsInitialized(baz.ManyToAny)); + Assert.IsTrue(baz.ManyToAny.Count == 2); + BarProxy barp = (BarProxy) baz.ManyToAny[0]; + await (s.CreateQuery("from Baz baz join baz.ManyToAny").ListAsync()); + Assert.IsTrue((await (s.CreateQuery("select baz from Baz baz join baz.ManyToAny a where index(a) = 0").ListAsync())).Count == 1); - await (s.DeleteAsync("from Holder")); - await (txn.CommitAsync()); - s.Close(); + FooProxy foop = (FooProxy) await (s.GetAsync(typeof(Foo), foo.Key)); + Assert.IsTrue(foop == baz.ManyToAny[1]); - s = OpenSession(); - txn = s.BeginTransaction(); - baz = (Baz) await (s.CreateQuery("from Baz baz left outer join fetch baz.ManyToAny").UniqueResultAsync()); - Assert.IsTrue(NHibernateUtil.IsInitialized(baz.ManyToAny)); - Assert.IsTrue(baz.ManyToAny.Count == 2); - BarProxy barp = (BarProxy) baz.ManyToAny[0]; - await (s.CreateQuery("from Baz baz join baz.ManyToAny").ListAsync()); - Assert.IsTrue((await (s.CreateQuery("select baz from Baz baz join baz.ManyToAny a where index(a) = 0").ListAsync())).Count == 1); - - FooProxy foop = (FooProxy) await (s.GetAsync(typeof(Foo), foo.Key)); - Assert.IsTrue(foop == baz.ManyToAny[1]); - - barp.Baz = baz; - Assert.IsTrue((await (s.CreateQuery("select bar from Bar bar where bar.Baz.StringDateMap['now'] is not null").ListAsync())).Count == - 1); - Assert.IsTrue( - (await (s.CreateQuery( - "select bar from Bar bar join bar.Baz b where b.StringDateMap['big bang'] < b.StringDateMap['now'] and b.StringDateMap['now'] is not null") - .ListAsync())).Count == 1); - Assert.IsTrue( - (await (s.CreateQuery( - "select bar from Bar bar where bar.Baz.StringDateMap['big bang'] < bar.Baz.StringDateMap['now'] and bar.Baz.StringDateMap['now'] is not null") - .ListAsync())).Count == 1); + barp.Baz = baz; + Assert.IsTrue((await (s.CreateQuery("select bar from Bar bar where bar.Baz.StringDateMap['now'] is not null").ListAsync())).Count == + 1); + Assert.IsTrue( + (await (s.CreateQuery( + "select bar from Bar bar join bar.Baz b where b.StringDateMap['big bang'] < b.StringDateMap['now'] and b.StringDateMap['now'] is not null") + .ListAsync())).Count == 1); + Assert.IsTrue( + (await (s.CreateQuery( + "select bar from Bar bar where bar.Baz.StringDateMap['big bang'] < bar.Baz.StringDateMap['now'] and bar.Baz.StringDateMap['now'] is not null") + .ListAsync())).Count == 1); - list = await (s.CreateQuery("select foo.String, foo.Component, foo.id from Bar foo").ListAsync()); - Assert.IsTrue(((FooComponent) ((object[]) list[0])[1]).Name == "foo"); - list = await (s.CreateQuery("select elements(baz.Components) from Baz baz").ListAsync()); - Assert.IsTrue(list.Count == 2); - list = await (s.CreateQuery("select bc.Name from Baz baz join baz.Components bc").ListAsync()); - Assert.IsTrue(list.Count == 2); - //list = s.CreateQuery("select bc from Baz baz join baz.components bc").List(); + var list = await (s.CreateQuery("select foo.String, foo.Component, foo.id from Bar foo").ListAsync()); + Assert.IsTrue(((FooComponent) ((object[]) list[0])[1]).Name == "foo"); + list = await (s.CreateQuery("select elements(baz.Components) from Baz baz").ListAsync()); + Assert.IsTrue(list.Count == 2); + list = await (s.CreateQuery("select bc.Name from Baz baz join baz.Components bc").ListAsync()); + Assert.IsTrue(list.Count == 2); + //list = s.CreateQuery("select bc from Baz baz join baz.components bc").List(); - await (s.CreateQuery("from Foo foo where foo.Integer < 10 order by foo.String").SetMaxResults(12).ListAsync()); + await (s.CreateQuery("from Foo foo where foo.Integer < 10 order by foo.String").SetMaxResults(12).ListAsync()); - await (s.DeleteAsync(barp)); - await (s.DeleteAsync(baz)); - await (s.DeleteAsync(foop.TheFoo)); - await (s.DeleteAsync(foop)); - await (txn.CommitAsync()); - s.Close(); + await (s.DeleteAsync(barp)); + await (s.DeleteAsync(baz)); + await (s.DeleteAsync(foop.TheFoo)); + await (s.DeleteAsync(foop)); + await (txn.CommitAsync()); + } } [Test] diff --git a/src/NHibernate.Test/Legacy/FooBarTest.cs b/src/NHibernate.Test/Legacy/FooBarTest.cs index cd95652152b..5ac93fee5d0 100644 --- a/src/NHibernate.Test/Legacy/FooBarTest.cs +++ b/src/NHibernate.Test/Legacy/FooBarTest.cs @@ -423,467 +423,470 @@ private static bool ContainsSingleObject(IEnumerable enumerable, object obj) [Test] public void Query() { - ISession s = OpenSession(); - ITransaction txn = s.BeginTransaction(); - Foo foo = new Foo(); - s.Save(foo); - Foo foo2 = new Foo(); - s.Save(foo2); - foo.TheFoo = foo2; - - IList list = s.CreateQuery("from Foo foo inner join fetch foo.TheFoo").List(); - Foo foof = (Foo) list[0]; - Assert.IsTrue(NHibernateUtil.IsInitialized(foof.TheFoo)); - - list = s.CreateQuery("from Baz baz left outer join fetch baz.FooToGlarch").List(); + Foo foo = null; + using (var s = OpenSession()) + using (var txn = s.BeginTransaction()) + { + foo = new Foo(); + s.Save(foo); + Foo foo2 = new Foo(); + s.Save(foo2); + foo.TheFoo = foo2; - list = s.CreateQuery("select foo, bar from Foo foo left outer join foo.TheFoo bar where foo = ?") - .SetEntity(0, foo).List(); + IList list = s.CreateQuery("from Foo foo inner join fetch foo.TheFoo").List(); + Foo foof = (Foo) list[0]; + Assert.IsTrue(NHibernateUtil.IsInitialized(foof.TheFoo)); - object[] row1 = (object[]) list[0]; - Assert.IsTrue(row1[0] == foo && row1[1] == foo2); + list = s.CreateQuery("from Baz baz left outer join fetch baz.FooToGlarch").List(); - s.CreateQuery("select foo.TheFoo.TheFoo.String from foo in class Foo where foo.TheFoo = 'bar'").List(); - s.CreateQuery("select foo.TheFoo.TheFoo.TheFoo.String from foo in class Foo where foo.TheFoo.TheFoo = 'bar'").List(); - s.CreateQuery("select foo.TheFoo.TheFoo.String from foo in class Foo where foo.TheFoo.TheFoo.TheFoo.String = 'bar'"). - List(); - // if( !( dialect is Dialect.HSQLDialect ) ) - // { - s.CreateQuery("select foo.String from foo in class Foo where foo.TheFoo.TheFoo.TheFoo = foo.TheFoo.TheFoo").List(); - // } - s.CreateQuery( - "select foo.String from foo in class Foo where foo.TheFoo.TheFoo = 'bar' and foo.TheFoo.TheFoo.TheFoo = 'baz'").List - (); - s.CreateQuery( - "select foo.String from foo in class Foo where foo.TheFoo.TheFoo.TheFoo.String = 'a' and foo.TheFoo.String = 'b'"). - List(); + list = s.CreateQuery("select foo, bar from Foo foo left outer join foo.TheFoo bar where foo = ?") + .SetEntity(0, foo).List(); - s.CreateQuery("from bar in class Bar, foo in elements(bar.Baz.FooArray)").List(); + object[] row1 = (object[]) list[0]; + Assert.IsTrue(row1[0] == foo && row1[1] == foo2); - if (Dialect is DB2Dialect) - { - s.CreateQuery("from foo in class Foo where lower( foo.TheFoo.String ) = 'foo'").List(); - s.CreateQuery("from foo in class Foo where lower( (foo.TheFoo.String || 'foo') || 'bar' ) = 'foo'").List(); - s.CreateQuery("from foo in class Foo where repeat( (foo.TheFoo.STring || 'foo') || 'bar', 2 ) = 'foo'").List(); + s.CreateQuery("select foo.TheFoo.TheFoo.String from foo in class Foo where foo.TheFoo = 'bar'").List(); + s.CreateQuery("select foo.TheFoo.TheFoo.TheFoo.String from foo in class Foo where foo.TheFoo.TheFoo = 'bar'").List(); + s.CreateQuery("select foo.TheFoo.TheFoo.String from foo in class Foo where foo.TheFoo.TheFoo.TheFoo.String = 'bar'"). + List(); + // if( !( dialect is Dialect.HSQLDialect ) ) + // { + s.CreateQuery("select foo.String from foo in class Foo where foo.TheFoo.TheFoo.TheFoo = foo.TheFoo.TheFoo").List(); + // } s.CreateQuery( - "From foo in class Bar where foo.TheFoo.Integer is not null and repeat( (foo.TheFoo.String || 'foo') || 'bar', (5+5)/2 ) = 'foo'") - .List(); + "select foo.String from foo in class Foo where foo.TheFoo.TheFoo = 'bar' and foo.TheFoo.TheFoo.TheFoo = 'baz'").List + (); s.CreateQuery( - "From foo in class Bar where foo.TheFoo.Integer is not null or repeat( (foo.TheFoo.String || 'foo') || 'bar', (5+5)/2 ) = 'foo'") - .List(); - } + "select foo.String from foo in class Foo where foo.TheFoo.TheFoo.TheFoo.String = 'a' and foo.TheFoo.String = 'b'"). + List(); - if (Dialect is MsSql2000Dialect) - { - s.CreateQuery("select baz from Baz as baz join baz.FooArray foo group by baz order by sum(foo.Float)").Enumerable(); - } + s.CreateQuery("from bar in class Bar, foo in elements(bar.Baz.FooArray)").List(); + + if (Dialect is DB2Dialect) + { + s.CreateQuery("from foo in class Foo where lower( foo.TheFoo.String ) = 'foo'").List(); + s.CreateQuery("from foo in class Foo where lower( (foo.TheFoo.String || 'foo') || 'bar' ) = 'foo'").List(); + s.CreateQuery("from foo in class Foo where repeat( (foo.TheFoo.STring || 'foo') || 'bar', 2 ) = 'foo'").List(); + s.CreateQuery( + "From foo in class Bar where foo.TheFoo.Integer is not null and repeat( (foo.TheFoo.String || 'foo') || 'bar', (5+5)/2 ) = 'foo'") + .List(); + s.CreateQuery( + "From foo in class Bar where foo.TheFoo.Integer is not null or repeat( (foo.TheFoo.String || 'foo') || 'bar', (5+5)/2 ) = 'foo'") + .List(); + } - s.CreateQuery("from Foo as foo where foo.Component.Glarch.Name is not null").List(); - s.CreateQuery("from Foo as foo left outer join foo.Component.Glarch as glarch where glarch.Name = 'foo'").List(); + if (Dialect is MsSql2000Dialect) + { + s.CreateQuery("select baz from Baz as baz join baz.FooArray foo group by baz order by sum(foo.Float)").Enumerable(); + } - list = s.CreateQuery("from Foo").List(); - Assert.AreEqual(2, list.Count); - Assert.IsTrue(list[0] is FooProxy); - list = s.CreateQuery("from Foo foo left outer join foo.TheFoo").List(); - Assert.AreEqual(2, list.Count); - Assert.IsTrue(((object[]) list[0])[0] is FooProxy); + s.CreateQuery("from Foo as foo where foo.Component.Glarch.Name is not null").List(); + s.CreateQuery("from Foo as foo left outer join foo.Component.Glarch as glarch where glarch.Name = 'foo'").List(); - s.CreateQuery("From Foo, Bar").List(); - s.CreateQuery("from Baz baz left join baz.FooToGlarch, Bar bar join bar.TheFoo").List(); - s.CreateQuery("from Baz baz left join baz.FooToGlarch join baz.FooSet").List(); - s.CreateQuery("from Baz baz left join baz.FooToGlarch join fetch baz.FooSet foo left join fetch foo.TheFoo").List(); + list = s.CreateQuery("from Foo").List(); + Assert.AreEqual(2, list.Count); + Assert.IsTrue(list[0] is FooProxy); + list = s.CreateQuery("from Foo foo left outer join foo.TheFoo").List(); + Assert.AreEqual(2, list.Count); + Assert.IsTrue(((object[]) list[0])[0] is FooProxy); - list = - s.CreateQuery( - "from foo in class NHibernate.DomainModel.Foo where foo.String='osama bin laden' and foo.Boolean = true order by foo.String asc, foo.Component.Count desc") - .List(); - Assert.AreEqual(0, list.Count, "empty query"); - IEnumerable enumerable = - s.CreateQuery( - "from foo in class NHibernate.DomainModel.Foo where foo.String='osama bin laden' order by foo.String asc, foo.Component.Count desc") - .Enumerable(); - Assert.IsTrue(IsEmpty(enumerable), "empty enumerator"); + s.CreateQuery("From Foo, Bar").List(); + s.CreateQuery("from Baz baz left join baz.FooToGlarch, Bar bar join bar.TheFoo").List(); + s.CreateQuery("from Baz baz left join baz.FooToGlarch join baz.FooSet").List(); + s.CreateQuery("from Baz baz left join baz.FooToGlarch join fetch baz.FooSet foo left join fetch foo.TheFoo").List(); - list = s.CreateQuery("select foo.TheFoo from foo in class NHibernate.DomainModel.Foo").List(); - Assert.AreEqual(1, list.Count, "query"); - Assert.AreEqual(foo.TheFoo, list[0], "returned object"); - foo.TheFoo.TheFoo = foo; - foo.String = "fizard"; + list = + s.CreateQuery( + "from foo in class NHibernate.DomainModel.Foo where foo.String='osama bin laden' and foo.Boolean = true order by foo.String asc, foo.Component.Count desc") + .List(); + Assert.AreEqual(0, list.Count, "empty query"); + IEnumerable enumerable = + s.CreateQuery( + "from foo in class NHibernate.DomainModel.Foo where foo.String='osama bin laden' order by foo.String asc, foo.Component.Count desc") + .Enumerable(); + Assert.IsTrue(IsEmpty(enumerable), "empty enumerator"); - if (Dialect.SupportsSubSelects && TestDialect.SupportsOperatorSome) - { - if (!(Dialect is FirebirdDialect)) - { - list = s.CreateQuery( - "from foo in class NHibernate.DomainModel.Foo where ? = some elements(foo.Component.ImportantDates)"). - SetDateTime(0, DateTime.Today).List(); - - Assert.AreEqual(2, list.Count, "component query"); - } + list = s.CreateQuery("select foo.TheFoo from foo in class NHibernate.DomainModel.Foo").List(); + Assert.AreEqual(1, list.Count, "query"); + Assert.AreEqual(foo.TheFoo, list[0], "returned object"); + foo.TheFoo.TheFoo = foo; + foo.String = "fizard"; - if (Dialect.SupportsScalarSubSelects) + if (Dialect.SupportsSubSelects && TestDialect.SupportsOperatorSome) { - list = - s.CreateQuery("from foo in class NHibernate.DomainModel.Foo where size(foo.Component.ImportantDates) = 3").List(); + if (!(Dialect is FirebirdDialect)) + { + list = s.CreateQuery( + "from foo in class NHibernate.DomainModel.Foo where ? = some elements(foo.Component.ImportantDates)"). + SetDateTime(0, DateTime.Today).List(); + + Assert.AreEqual(2, list.Count, "component query"); + } + + if (Dialect.SupportsScalarSubSelects) + { + list = + s.CreateQuery("from foo in class NHibernate.DomainModel.Foo where size(foo.Component.ImportantDates) = 3").List(); + Assert.AreEqual(2, list.Count, "component query"); + list = s.CreateQuery("from foo in class Foo where 0 = size(foo.Component.ImportantDates)").List(); + Assert.AreEqual(0, list.Count, "component query"); + } + list = s.CreateQuery("from foo in class Foo where exists elements(foo.Component.ImportantDates)").List(); Assert.AreEqual(2, list.Count, "component query"); - list = s.CreateQuery("from foo in class Foo where 0 = size(foo.Component.ImportantDates)").List(); - Assert.AreEqual(0, list.Count, "component query"); - } - list = s.CreateQuery("from foo in class Foo where exists elements(foo.Component.ImportantDates)").List(); - Assert.AreEqual(2, list.Count, "component query"); - s.CreateQuery("from foo in class Foo where not exists (from bar in class Bar where bar.id = foo.id)").List(); + s.CreateQuery("from foo in class Foo where not exists (from bar in class Bar where bar.id = foo.id)").List(); - s.CreateQuery( - "select foo.TheFoo from foo in class Foo where foo = some(select x from x in class Foo where x.Long > foo.TheFoo.Long)") - .List(); - s.CreateQuery( - "from foo in class Foo where foo = some(select x from x in class Foo where x.Long > foo.TheFoo.Long) and foo.TheFoo.String='baz'") - .List(); - s.CreateQuery( - "from foo in class Foo where foo.TheFoo.String='baz' and foo = some(select x from x in class Foo where x.Long>foo.TheFoo.Long)") - .List(); - s.CreateQuery("from foo in class Foo where foo = some(select x from x in class Foo where x.Long > foo.TheFoo.Long)") - .List(); + s.CreateQuery( + "select foo.TheFoo from foo in class Foo where foo = some(select x from x in class Foo where x.Long > foo.TheFoo.Long)") + .List(); + s.CreateQuery( + "from foo in class Foo where foo = some(select x from x in class Foo where x.Long > foo.TheFoo.Long) and foo.TheFoo.String='baz'") + .List(); + s.CreateQuery( + "from foo in class Foo where foo.TheFoo.String='baz' and foo = some(select x from x in class Foo where x.Long>foo.TheFoo.Long)") + .List(); + s.CreateQuery("from foo in class Foo where foo = some(select x from x in class Foo where x.Long > foo.TheFoo.Long)") + .List(); - s.CreateQuery( - "select foo.String, foo.Date, foo.TheFoo.String, foo.id from foo in class Foo, baz in class Baz where foo in elements(baz.FooArray) and foo.String like 'foo'") - .Enumerable(); - } + s.CreateQuery( + "select foo.String, foo.Date, foo.TheFoo.String, foo.id from foo in class Foo, baz in class Baz where foo in elements(baz.FooArray) and foo.String like 'foo'") + .Enumerable(); + } - list = s.CreateQuery("from foo in class Foo where foo.Component.Count is null order by foo.Component.Count").List(); - Assert.AreEqual(0, list.Count, "component query"); + list = s.CreateQuery("from foo in class Foo where foo.Component.Count is null order by foo.Component.Count").List(); + Assert.AreEqual(0, list.Count, "component query"); - list = s.CreateQuery("from foo in class Foo where foo.Component.Name='foo'").List(); - Assert.AreEqual(2, list.Count, "component query"); + list = s.CreateQuery("from foo in class Foo where foo.Component.Name='foo'").List(); + Assert.AreEqual(2, list.Count, "component query"); - list = - s.CreateQuery( - "select distinct foo.Component.Name, foo.Component.Name from foo in class Foo where foo.Component.Name='foo'").List - (); - Assert.AreEqual(1, list.Count, "component query"); + list = + s.CreateQuery( + "select distinct foo.Component.Name, foo.Component.Name from foo in class Foo where foo.Component.Name='foo'").List + (); + Assert.AreEqual(1, list.Count, "component query"); - list = - s.CreateQuery("select distinct foo.Component.Name, foo.id from foo in class Foo where foo.Component.Name='foo'"). - List(); - Assert.AreEqual(2, list.Count, "component query"); + list = + s.CreateQuery("select distinct foo.Component.Name, foo.id from foo in class Foo where foo.Component.Name='foo'"). + List(); + Assert.AreEqual(2, list.Count, "component query"); - list = s.CreateQuery("select foo.TheFoo from foo in class Foo").List(); - Assert.AreEqual(2, list.Count, "query"); + list = s.CreateQuery("select foo.TheFoo from foo in class Foo").List(); + Assert.AreEqual(2, list.Count, "query"); - list = s.CreateQuery("from foo in class Foo where foo.id=?").SetString(0, foo.Key).List(); - Assert.AreEqual(1, list.Count, "id query"); + list = s.CreateQuery("from foo in class Foo where foo.id=?").SetString(0, foo.Key).List(); + Assert.AreEqual(1, list.Count, "id query"); - list = s.CreateQuery("from foo in class Foo where foo.Key=?").SetString(0, foo.Key).List(); - Assert.AreEqual(1, list.Count, "named id query"); - Assert.AreSame(foo, list[0], "id query"); + list = s.CreateQuery("from foo in class Foo where foo.Key=?").SetString(0, foo.Key).List(); + Assert.AreEqual(1, list.Count, "named id query"); + Assert.AreSame(foo, list[0], "id query"); - list = s.CreateQuery("select foo.TheFoo from foo in class Foo where foo.String='fizard'").List(); - Assert.AreEqual(1, list.Count, "query"); - Assert.AreSame(foo.TheFoo, list[0], "returned object"); + list = s.CreateQuery("select foo.TheFoo from foo in class Foo where foo.String='fizard'").List(); + Assert.AreEqual(1, list.Count, "query"); + Assert.AreSame(foo.TheFoo, list[0], "returned object"); - list = s.CreateQuery("from foo in class Foo where foo.Component.Subcomponent.Name='bar'").List(); - Assert.AreEqual(2, list.Count, "components of components"); + list = s.CreateQuery("from foo in class Foo where foo.Component.Subcomponent.Name='bar'").List(); + Assert.AreEqual(2, list.Count, "components of components"); - list = s.CreateQuery("select foo.TheFoo from foo in class Foo where foo.TheFoo.id=?") - .SetString(0, foo.TheFoo.Key).List(); - Assert.AreEqual(1, list.Count, "by id query"); - Assert.AreSame(foo.TheFoo, list[0], "by id returned object"); + list = s.CreateQuery("select foo.TheFoo from foo in class Foo where foo.TheFoo.id=?") + .SetString(0, foo.TheFoo.Key).List(); + Assert.AreEqual(1, list.Count, "by id query"); + Assert.AreSame(foo.TheFoo, list[0], "by id returned object"); - s.CreateQuery("from foo in class Foo where foo.TheFoo = ?").SetEntity(0, foo.TheFoo).List(); + s.CreateQuery("from foo in class Foo where foo.TheFoo = ?").SetEntity(0, foo.TheFoo).List(); - Assert.IsTrue( - IsEmpty(s.CreateQuery("from bar in class Bar where bar.String='a string' or bar.String='a string'").Enumerable() - )); + Assert.IsTrue( + IsEmpty(s.CreateQuery("from bar in class Bar where bar.String='a string' or bar.String='a string'").Enumerable() + )); - enumerable = s.CreateQuery( - "select foo.Component.Name, elements(foo.Component.ImportantDates) from foo in class Foo where foo.TheFoo.id=?"). - SetString(0, foo.TheFoo.Key).Enumerable(); + enumerable = s.CreateQuery( + "select foo.Component.Name, elements(foo.Component.ImportantDates) from foo in class Foo where foo.TheFoo.id=?"). + SetString(0, foo.TheFoo.Key).Enumerable(); - int i = 0; - foreach (object[] row in enumerable) - { - i++; - Assert.IsTrue(row[0] is String); - Assert.IsTrue(row[1] == null || row[1] is DateTime); - } - Assert.AreEqual(3, i); //WAS: 4 + int i = 0; + foreach (object[] row in enumerable) + { + i++; + Assert.IsTrue(row[0] is String); + Assert.IsTrue(row[1] == null || row[1] is DateTime); + } + Assert.AreEqual(3, i); //WAS: 4 - enumerable = s.CreateQuery("select max(elements(foo.Component.ImportantDates)) from foo in class Foo group by foo.id"). - Enumerable(); - - IEnumerator enumerator = enumerable.GetEnumerator(); + enumerable = s.CreateQuery("select max(elements(foo.Component.ImportantDates)) from foo in class Foo group by foo.id"). + Enumerable(); - Assert.IsTrue(enumerator.MoveNext()); - Assert.IsTrue(enumerator.Current is DateTime); + IEnumerator enumerator = enumerable.GetEnumerator(); - list = s.CreateQuery( - "select foo.TheFoo.TheFoo.TheFoo from foo in class Foo, foo2 in class Foo where" - + " foo = foo2.TheFoo and not not ( not foo.String='fizard' )" - + " and foo2.String between 'a' and (foo.TheFoo.String)" - + (Dialect is SQLiteDialect - ? " and ( foo2.String in ( 'fiz', 'blah') or 1=1 )" - : " and ( foo2.String in ( 'fiz', 'blah', foo.TheFoo.String, foo.String, foo2.String ) )") - ).List(); - Assert.AreEqual(1, list.Count, "complex query"); - Assert.AreSame(foo, list[0], "returned object"); + Assert.IsTrue(enumerator.MoveNext()); + Assert.IsTrue(enumerator.Current is DateTime); - foo.String = "from BoogieDown -tinsel town =!@#$^&*())"; + list = s.CreateQuery( + "select foo.TheFoo.TheFoo.TheFoo from foo in class Foo, foo2 in class Foo where" + + " foo = foo2.TheFoo and not not ( not foo.String='fizard' )" + + " and foo2.String between 'a' and (foo.TheFoo.String)" + + (Dialect is SQLiteDialect + ? " and ( foo2.String in ( 'fiz', 'blah') or 1=1 )" + : " and ( foo2.String in ( 'fiz', 'blah', foo.TheFoo.String, foo.String, foo2.String ) )") + ).List(); + Assert.AreEqual(1, list.Count, "complex query"); + Assert.AreSame(foo, list[0], "returned object"); - list = s.CreateQuery("from foo in class Foo where foo.String='from BoogieDown -tinsel town =!@#$^&*())'").List(); - Assert.AreEqual(1, list.Count, "single quotes"); + foo.String = "from BoogieDown -tinsel town =!@#$^&*())"; - list = s.CreateQuery("from foo in class Foo where not foo.String='foo''bar'").List(); - Assert.AreEqual(2, list.Count, "single quotes"); + list = s.CreateQuery("from foo in class Foo where foo.String='from BoogieDown -tinsel town =!@#$^&*())'").List(); + Assert.AreEqual(1, list.Count, "single quotes"); - list = s.CreateQuery("from foo in class Foo where foo.Component.Glarch.Next is null").List(); - Assert.AreEqual(2, list.Count, "query association in component"); + list = s.CreateQuery("from foo in class Foo where not foo.String='foo''bar'").List(); + Assert.AreEqual(2, list.Count, "single quotes"); - Bar bar = new Bar(); - Baz baz = new Baz(); - baz.SetDefaults(); - bar.Baz = baz; - baz.ManyToAny = new List(); - baz.ManyToAny.Add(bar); - baz.ManyToAny.Add(foo); - s.Save(bar); - s.Save(baz); - list = - s.CreateQuery(" from bar in class Bar where bar.Baz.Count=667 and bar.Baz.Count!=123 and not bar.Baz.Name='1-E-1'"). - List(); - Assert.AreEqual(1, list.Count, "query many-to-one"); - list = s.CreateQuery(" from i in class Bar where i.Baz.Name='Bazza'").List(); - Assert.AreEqual(1, list.Count, "query many-to-one"); + list = s.CreateQuery("from foo in class Foo where foo.Component.Glarch.Next is null").List(); + Assert.AreEqual(2, list.Count, "query association in component"); - if (TestDialect.SupportsCountDistinct) - { - enumerable = s.CreateQuery("select count(distinct foo.TheFoo) from foo in class Foo").Enumerable(); - Assert.IsTrue(ContainsSingleObject(enumerable, (long) 2), "count"); // changed to Int64 (HQLFunction H3.2) - } + Bar bar = new Bar(); + Baz baz = new Baz(); + baz.SetDefaults(); + bar.Baz = baz; + baz.ManyToAny = new List(); + baz.ManyToAny.Add(bar); + baz.ManyToAny.Add(foo); + s.Save(bar); + s.Save(baz); + list = + s.CreateQuery(" from bar in class Bar where bar.Baz.Count=667 and bar.Baz.Count!=123 and not bar.Baz.Name='1-E-1'"). + List(); + Assert.AreEqual(1, list.Count, "query many-to-one"); + list = s.CreateQuery(" from i in class Bar where i.Baz.Name='Bazza'").List(); + Assert.AreEqual(1, list.Count, "query many-to-one"); - enumerable = s.CreateQuery("select count(foo.TheFoo.Boolean) from foo in class Foo").Enumerable(); - Assert.IsTrue(ContainsSingleObject(enumerable, (long) 2), "count"); // changed to Int64 (HQLFunction H3.2) + if (TestDialect.SupportsCountDistinct) + { + enumerable = s.CreateQuery("select count(distinct foo.TheFoo) from foo in class Foo").Enumerable(); + Assert.IsTrue(ContainsSingleObject(enumerable, (long) 2), "count"); // changed to Int64 (HQLFunction H3.2) + } - enumerable = s.CreateQuery("select count(*), foo.Int from foo in class Foo group by foo.Int").Enumerable(); - enumerator = enumerable.GetEnumerator(); - Assert.IsTrue(enumerator.MoveNext()); - Assert.AreEqual(3L, (long) ((object[]) enumerator.Current)[0]); - Assert.IsFalse(enumerator.MoveNext()); + enumerable = s.CreateQuery("select count(foo.TheFoo.Boolean) from foo in class Foo").Enumerable(); + Assert.IsTrue(ContainsSingleObject(enumerable, (long) 2), "count"); // changed to Int64 (HQLFunction H3.2) - enumerable = s.CreateQuery("select sum(foo.TheFoo.Int) from foo in class Foo").Enumerable(); - Assert.IsTrue(ContainsSingleObject(enumerable, (long) 4), "sum"); // changed to Int64 (HQLFunction H3.2) + enumerable = s.CreateQuery("select count(*), foo.Int from foo in class Foo group by foo.Int").Enumerable(); + enumerator = enumerable.GetEnumerator(); + Assert.IsTrue(enumerator.MoveNext()); + Assert.AreEqual(3L, (long) ((object[]) enumerator.Current)[0]); + Assert.IsFalse(enumerator.MoveNext()); - enumerable = s.CreateQuery("select count(foo) from foo in class Foo where foo.id=?") - .SetString(0, foo.Key).Enumerable(); - Assert.IsTrue(ContainsSingleObject(enumerable, (long) 1), "id query count"); + enumerable = s.CreateQuery("select sum(foo.TheFoo.Int) from foo in class Foo").Enumerable(); + Assert.IsTrue(ContainsSingleObject(enumerable, (long) 4), "sum"); // changed to Int64 (HQLFunction H3.2) - list = s.CreateQuery("from foo in class Foo where foo.Boolean = ?").SetBoolean(0, true).List(); + enumerable = s.CreateQuery("select count(foo) from foo in class Foo where foo.id=?") + .SetString(0, foo.Key).Enumerable(); + Assert.IsTrue(ContainsSingleObject(enumerable, (long) 1), "id query count"); - list = s.CreateQuery("select new Foo(fo.X) from Fo fo").List(); - list = s.CreateQuery("select new Foo(fo.Integer) from Foo fo").List(); + list = s.CreateQuery("from foo in class Foo where foo.Boolean = ?").SetBoolean(0, true).List(); - list = s.CreateQuery("select new Foo(fo.X) from Foo fo") - .SetCacheable(true) - .List(); - Assert.IsTrue(list.Count == 3); - list = s.CreateQuery("select new Foo(fo.X) from Foo fo") - .SetCacheable(true) - .List(); - Assert.IsTrue(list.Count == 3); + list = s.CreateQuery("select new Foo(fo.X) from Fo fo").List(); + list = s.CreateQuery("select new Foo(fo.Integer) from Foo fo").List(); - enumerable = s.CreateQuery("select new Foo(fo.X) from Foo fo").Enumerable(); - enumerator = enumerable.GetEnumerator(); - Assert.IsTrue(enumerator.MoveNext(), "projection iterate (results)"); - Assert.IsTrue(typeof(Foo).IsAssignableFrom(enumerator.Current.GetType()), - "projection iterate (return check)"); + list = s.CreateQuery("select new Foo(fo.X) from Foo fo") + .SetCacheable(true) + .List(); + Assert.IsTrue(list.Count == 3); + list = s.CreateQuery("select new Foo(fo.X) from Foo fo") + .SetCacheable(true) + .List(); + Assert.IsTrue(list.Count == 3); - // TODO: ScrollableResults not implemented - //ScrollableResults sr = s.CreateQuery("select new Foo(fo.x) from Foo fo").Scroll(); - //Assert.IsTrue( "projection scroll (results)", sr.next() ); - //Assert.IsTrue( "projection scroll (return check)", typeof(Foo).isAssignableFrom( sr.get(0).getClass() ) ); + enumerable = s.CreateQuery("select new Foo(fo.X) from Foo fo").Enumerable(); + enumerator = enumerable.GetEnumerator(); + Assert.IsTrue(enumerator.MoveNext(), "projection iterate (results)"); + Assert.IsTrue(typeof(Foo).IsAssignableFrom(enumerator.Current.GetType()), + "projection iterate (return check)"); - list = s.CreateQuery("select foo.Long, foo.Component.Name, foo, foo.TheFoo from foo in class Foo").List(); - Assert.IsTrue(list.Count > 0); - foreach (object[] row in list) - { - Assert.IsTrue(row[0] is long); - Assert.IsTrue(row[1] is string); - Assert.IsTrue(row[2] is Foo); - Assert.IsTrue(row[3] is Foo); - } + // TODO: ScrollableResults not implemented + //ScrollableResults sr = s.CreateQuery("select new Foo(fo.x) from Foo fo").Scroll(); + //Assert.IsTrue( "projection scroll (results)", sr.next() ); + //Assert.IsTrue( "projection scroll (return check)", typeof(Foo).isAssignableFrom( sr.get(0).getClass() ) ); - if (TestDialect.SupportsCountDistinct) - { - list = - s.CreateQuery("select avg(foo.Float), max(foo.Component.Name), count(distinct foo.id) from foo in class Foo").List(); + list = s.CreateQuery("select foo.Long, foo.Component.Name, foo, foo.TheFoo from foo in class Foo").List(); Assert.IsTrue(list.Count > 0); foreach (object[] row in list) { - Assert.IsTrue(row[0] is double); // changed from float to double (HQLFunction H3.2) + Assert.IsTrue(row[0] is long); Assert.IsTrue(row[1] is string); - Assert.IsTrue(row[2] is long); // changed from int to long (HQLFunction H3.2) + Assert.IsTrue(row[2] is Foo); + Assert.IsTrue(row[3] is Foo); } - } - list = s.CreateQuery("select foo.Long, foo.Component, foo, foo.TheFoo from foo in class Foo").List(); - Assert.IsTrue(list.Count > 0); - foreach (object[] row in list) - { - Assert.IsTrue(row[0] is long); - Assert.IsTrue(row[1] is FooComponent); - Assert.IsTrue(row[2] is Foo); - Assert.IsTrue(row[3] is Foo); - } + if (TestDialect.SupportsCountDistinct) + { + list = + s.CreateQuery("select avg(foo.Float), max(foo.Component.Name), count(distinct foo.id) from foo in class Foo").List(); + Assert.IsTrue(list.Count > 0); + foreach (object[] row in list) + { + Assert.IsTrue(row[0] is double); // changed from float to double (HQLFunction H3.2) + Assert.IsTrue(row[1] is string); + Assert.IsTrue(row[2] is long); // changed from int to long (HQLFunction H3.2) + } + } - s.Save(new Holder("ice T")); - s.Save(new Holder("ice cube")); + list = s.CreateQuery("select foo.Long, foo.Component, foo, foo.TheFoo from foo in class Foo").List(); + Assert.IsTrue(list.Count > 0); + foreach (object[] row in list) + { + Assert.IsTrue(row[0] is long); + Assert.IsTrue(row[1] is FooComponent); + Assert.IsTrue(row[2] is Foo); + Assert.IsTrue(row[3] is Foo); + } - Assert.AreEqual(15, s.CreateQuery("from o in class System.Object").List().Count); - Assert.AreEqual(7, s.CreateQuery("from n in class INamed").List().Count); - Assert.IsTrue(s.CreateQuery("from n in class INamed where n.Name is not null").List().Count == 4); + s.Save(new Holder("ice T")); + s.Save(new Holder("ice cube")); - foreach (INamed named in s.CreateQuery("from n in class INamed").Enumerable()) - { - Assert.IsNotNull(named); - } + Assert.AreEqual(15, s.CreateQuery("from o in class System.Object").List().Count); + Assert.AreEqual(7, s.CreateQuery("from n in class INamed").List().Count); + Assert.IsTrue(s.CreateQuery("from n in class INamed where n.Name is not null").List().Count == 4); - s.Save(new Holder("bar")); - enumerable = s.CreateQuery("from n0 in class INamed, n1 in class INamed where n0.Name = n1.Name").Enumerable(); - int cnt = 0; - foreach (object[] row in enumerable) - { - if (row[0] != row[1]) + foreach (INamed named in s.CreateQuery("from n in class INamed").Enumerable()) { - cnt++; + Assert.IsNotNull(named); } - } - //if ( !(dialect is Dialect.HSQLDialect) ) - //{ - Assert.IsTrue(cnt == 2); - Assert.IsTrue(s.CreateQuery("from n0 in class INamed, n1 in class INamed where n0.Name = n1.Name").List().Count == 7); - //} + s.Save(new Holder("bar")); + enumerable = s.CreateQuery("from n0 in class INamed, n1 in class INamed where n0.Name = n1.Name").Enumerable(); + int cnt = 0; + foreach (object[] row in enumerable) + { + if (row[0] != row[1]) + { + cnt++; + } + } - IQuery qu = s.CreateQuery("from n in class INamed where n.Name = :name"); - object temp = qu.ReturnTypes; - temp = qu.NamedParameters; + //if ( !(dialect is Dialect.HSQLDialect) ) + //{ + Assert.IsTrue(cnt == 2); + Assert.IsTrue(s.CreateQuery("from n0 in class INamed, n1 in class INamed where n0.Name = n1.Name").List().Count == 7); + //} - int c = 0; + IQuery qu = s.CreateQuery("from n in class INamed where n.Name = :name"); + object temp = qu.ReturnTypes; + temp = qu.NamedParameters; - foreach (object obj in s.CreateQuery("from o in class System.Object").Enumerable()) - { - c++; - } - Assert.IsTrue(c == 16); + int c = 0; - s.CreateQuery("select baz.Code, min(baz.Count) from baz in class Baz group by baz.Code").Enumerable(); + foreach (object obj in s.CreateQuery("from o in class System.Object").Enumerable()) + { + c++; + } + Assert.IsTrue(c == 16); - Assert.IsTrue( - IsEmpty( - s.CreateQuery( - "selecT baz from baz in class Baz where baz.StringDateMap['foo'] is not null or baz.StringDateMap['bar'] = ?") - .SetDateTime(0, DateTime.Today).Enumerable())); + s.CreateQuery("select baz.Code, min(baz.Count) from baz in class Baz group by baz.Code").Enumerable(); - list = s.CreateQuery("select baz from baz in class Baz where baz.StringDateMap['now'] is not null").List(); - Assert.AreEqual(1, list.Count); + Assert.IsTrue( + IsEmpty( + s.CreateQuery( + "selecT baz from baz in class Baz where baz.StringDateMap['foo'] is not null or baz.StringDateMap['bar'] = ?") + .SetDateTime(0, DateTime.Today).Enumerable())); - list = - s.CreateQuery("select baz from baz in class Baz where baz.StringDateMap[:now] is not null").SetString("now", "now"). - List(); - Assert.AreEqual(1, list.Count); + list = s.CreateQuery("select baz from baz in class Baz where baz.StringDateMap['now'] is not null").List(); + Assert.AreEqual(1, list.Count); + + list = + s.CreateQuery("select baz from baz in class Baz where baz.StringDateMap[:now] is not null").SetString("now", "now"). + List(); + Assert.AreEqual(1, list.Count); + + list = + s.CreateQuery( + "select baz from baz in class Baz where baz.StringDateMap['now'] is not null and baz.StringDateMap['big bang'] < baz.StringDateMap['now']") + .List(); + Assert.AreEqual(1, list.Count); + + list = s.CreateQuery("select index(date) from Baz baz join baz.StringDateMap date").List(); + Console.WriteLine(list); + Assert.AreEqual(3, list.Count); - list = s.CreateQuery( - "select baz from baz in class Baz where baz.StringDateMap['now'] is not null and baz.StringDateMap['big bang'] < baz.StringDateMap['now']") + "from foo in class Foo where foo.Integer not between 1 and 5 and foo.String not in ('cde', 'abc') and foo.String is not null and foo.Integer<=3") .List(); - Assert.AreEqual(1, list.Count); - list = s.CreateQuery("select index(date) from Baz baz join baz.StringDateMap date").List(); - Console.WriteLine(list); - Assert.AreEqual(3, list.Count); + s.CreateQuery("from Baz baz inner join baz.CollectionComponent.Nested.Foos foo where foo.String is null").List(); + if (Dialect.SupportsSubSelects) + { + s.CreateQuery("from Baz baz inner join baz.FooSet where '1' in (from baz.FooSet foo where foo.String is not null)"). + List(); + s.CreateQuery( + "from Baz baz where 'a' in elements(baz.CollectionComponent.Nested.Foos) and 1.0 in elements(baz.CollectionComponent.Nested.Floats)") + .List(); + s.CreateQuery( + "from Baz baz where 'b' in elements(baz.CollectionComponent.Nested.Foos) and 1.0 in elements(baz.CollectionComponent.Nested.Floats)") + .List(); + } - s.CreateQuery( - "from foo in class Foo where foo.Integer not between 1 and 5 and foo.String not in ('cde', 'abc') and foo.String is not null and foo.Integer<=3") - .List(); + s.CreateQuery("from Foo foo join foo.TheFoo where foo.TheFoo in ('1','2','3')").List(); - s.CreateQuery("from Baz baz inner join baz.CollectionComponent.Nested.Foos foo where foo.String is null").List(); - if (Dialect.SupportsSubSelects) - { - s.CreateQuery("from Baz baz inner join baz.FooSet where '1' in (from baz.FooSet foo where foo.String is not null)"). + //if ( !(dialect is Dialect.HSQLDialect) ) + s.CreateQuery("from Foo foo left join foo.TheFoo where foo.TheFoo in ('1','2','3')").List(); + s.CreateQuery("select foo.TheFoo from Foo foo where foo.TheFoo in ('1','2','3')").List(); + s.CreateQuery("select foo.TheFoo.String from Foo foo where foo.TheFoo in ('1','2','3')").List(); + s.CreateQuery("select foo.TheFoo.String from Foo foo where foo.TheFoo.String in ('1','2','3')").List(); + s.CreateQuery("select foo.TheFoo.Long from Foo foo where foo.TheFoo.String in ('1','2','3')").List(); + s.CreateQuery("select count(*) from Foo foo where foo.TheFoo.String in ('1','2','3') or foo.TheFoo.Long in (1,2,3)"). List(); + s.CreateQuery("select count(*) from Foo foo where foo.TheFoo.String in ('1','2','3') group by foo.TheFoo.Long").List(); + + s.CreateQuery("from Foo foo1 left join foo1.TheFoo foo2 left join foo2.TheFoo where foo1.String is not null").List(); + s.CreateQuery("from Foo foo1 left join foo1.TheFoo.TheFoo where foo1.String is not null").List(); s.CreateQuery( - "from Baz baz where 'a' in elements(baz.CollectionComponent.Nested.Foos) and 1.0 in elements(baz.CollectionComponent.Nested.Floats)") - .List(); - s.CreateQuery( - "from Baz baz where 'b' in elements(baz.CollectionComponent.Nested.Foos) and 1.0 in elements(baz.CollectionComponent.Nested.Floats)") - .List(); - } + "from Foo foo1 left join foo1.TheFoo foo2 left join foo1.TheFoo.TheFoo foo3 where foo1.String is not null").List(); - s.CreateQuery("from Foo foo join foo.TheFoo where foo.TheFoo in ('1','2','3')").List(); + s.CreateQuery("select foo.Formula from Foo foo where foo.Formula > 0").List(); - //if ( !(dialect is Dialect.HSQLDialect) ) - s.CreateQuery("from Foo foo left join foo.TheFoo where foo.TheFoo in ('1','2','3')").List(); - s.CreateQuery("select foo.TheFoo from Foo foo where foo.TheFoo in ('1','2','3')").List(); - s.CreateQuery("select foo.TheFoo.String from Foo foo where foo.TheFoo in ('1','2','3')").List(); - s.CreateQuery("select foo.TheFoo.String from Foo foo where foo.TheFoo.String in ('1','2','3')").List(); - s.CreateQuery("select foo.TheFoo.Long from Foo foo where foo.TheFoo.String in ('1','2','3')").List(); - s.CreateQuery("select count(*) from Foo foo where foo.TheFoo.String in ('1','2','3') or foo.TheFoo.Long in (1,2,3)"). - List(); - s.CreateQuery("select count(*) from Foo foo where foo.TheFoo.String in ('1','2','3') group by foo.TheFoo.Long").List(); + int len = s.CreateQuery("from Foo as foo join foo.TheFoo as foo2 where foo2.id >'a' or foo2.id <'a'").List().Count; + Assert.IsTrue(len == 2); - s.CreateQuery("from Foo foo1 left join foo1.TheFoo foo2 left join foo2.TheFoo where foo1.String is not null").List(); - s.CreateQuery("from Foo foo1 left join foo1.TheFoo.TheFoo where foo1.String is not null").List(); - s.CreateQuery( - "from Foo foo1 left join foo1.TheFoo foo2 left join foo1.TheFoo.TheFoo foo3 where foo1.String is not null").List(); - - s.CreateQuery("select foo.Formula from Foo foo where foo.Formula > 0").List(); + s.Delete("from Holder"); + txn.Commit(); + } - int len = s.CreateQuery("from Foo as foo join foo.TheFoo as foo2 where foo2.id >'a' or foo2.id <'a'").List().Count; - Assert.IsTrue(len == 2); + using (var s = OpenSession()) + using (var txn = s.BeginTransaction()) + { + var baz = (Baz) s.CreateQuery("from Baz baz left outer join fetch baz.ManyToAny").UniqueResult(); + Assert.IsTrue(NHibernateUtil.IsInitialized(baz.ManyToAny)); + Assert.IsTrue(baz.ManyToAny.Count == 2); + BarProxy barp = (BarProxy) baz.ManyToAny[0]; + s.CreateQuery("from Baz baz join baz.ManyToAny").List(); + Assert.IsTrue(s.CreateQuery("select baz from Baz baz join baz.ManyToAny a where index(a) = 0").List().Count == 1); - s.Delete("from Holder"); - txn.Commit(); - s.Close(); + FooProxy foop = (FooProxy) s.Get(typeof(Foo), foo.Key); + Assert.IsTrue(foop == baz.ManyToAny[1]); - s = OpenSession(); - txn = s.BeginTransaction(); - baz = (Baz) s.CreateQuery("from Baz baz left outer join fetch baz.ManyToAny").UniqueResult(); - Assert.IsTrue(NHibernateUtil.IsInitialized(baz.ManyToAny)); - Assert.IsTrue(baz.ManyToAny.Count == 2); - BarProxy barp = (BarProxy) baz.ManyToAny[0]; - s.CreateQuery("from Baz baz join baz.ManyToAny").List(); - Assert.IsTrue(s.CreateQuery("select baz from Baz baz join baz.ManyToAny a where index(a) = 0").List().Count == 1); - - FooProxy foop = (FooProxy) s.Get(typeof(Foo), foo.Key); - Assert.IsTrue(foop == baz.ManyToAny[1]); - - barp.Baz = baz; - Assert.IsTrue(s.CreateQuery("select bar from Bar bar where bar.Baz.StringDateMap['now'] is not null").List().Count == - 1); - Assert.IsTrue( - s.CreateQuery( - "select bar from Bar bar join bar.Baz b where b.StringDateMap['big bang'] < b.StringDateMap['now'] and b.StringDateMap['now'] is not null") - .List().Count == 1); - Assert.IsTrue( - s.CreateQuery( - "select bar from Bar bar where bar.Baz.StringDateMap['big bang'] < bar.Baz.StringDateMap['now'] and bar.Baz.StringDateMap['now'] is not null") - .List().Count == 1); + barp.Baz = baz; + Assert.IsTrue(s.CreateQuery("select bar from Bar bar where bar.Baz.StringDateMap['now'] is not null").List().Count == + 1); + Assert.IsTrue( + s.CreateQuery( + "select bar from Bar bar join bar.Baz b where b.StringDateMap['big bang'] < b.StringDateMap['now'] and b.StringDateMap['now'] is not null") + .List().Count == 1); + Assert.IsTrue( + s.CreateQuery( + "select bar from Bar bar where bar.Baz.StringDateMap['big bang'] < bar.Baz.StringDateMap['now'] and bar.Baz.StringDateMap['now'] is not null") + .List().Count == 1); - list = s.CreateQuery("select foo.String, foo.Component, foo.id from Bar foo").List(); - Assert.IsTrue(((FooComponent) ((object[]) list[0])[1]).Name == "foo"); - list = s.CreateQuery("select elements(baz.Components) from Baz baz").List(); - Assert.IsTrue(list.Count == 2); - list = s.CreateQuery("select bc.Name from Baz baz join baz.Components bc").List(); - Assert.IsTrue(list.Count == 2); - //list = s.CreateQuery("select bc from Baz baz join baz.components bc").List(); + var list = s.CreateQuery("select foo.String, foo.Component, foo.id from Bar foo").List(); + Assert.IsTrue(((FooComponent) ((object[]) list[0])[1]).Name == "foo"); + list = s.CreateQuery("select elements(baz.Components) from Baz baz").List(); + Assert.IsTrue(list.Count == 2); + list = s.CreateQuery("select bc.Name from Baz baz join baz.Components bc").List(); + Assert.IsTrue(list.Count == 2); + //list = s.CreateQuery("select bc from Baz baz join baz.components bc").List(); - s.CreateQuery("from Foo foo where foo.Integer < 10 order by foo.String").SetMaxResults(12).List(); + s.CreateQuery("from Foo foo where foo.Integer < 10 order by foo.String").SetMaxResults(12).List(); - s.Delete(barp); - s.Delete(baz); - s.Delete(foop.TheFoo); - s.Delete(foop); - txn.Commit(); - s.Close(); + s.Delete(barp); + s.Delete(baz); + s.Delete(foop.TheFoo); + s.Delete(foop); + txn.Commit(); + } } [Test] From baf46ed1ed955221e6f7f76f4e657689e3fad110 Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Fri, 22 Feb 2019 18:26:27 +0200 Subject: [PATCH 2/8] Proper iteration in HQLQueryPlan.PerformIterate --- .../Async/Legacy/FooBarTest.cs | 11 +- src/NHibernate.Test/Legacy/FooBarTest.cs | 11 +- .../UtilityTest/JoinedEnumerableFixture.cs | 213 ------------------ .../Async/Engine/Query/HQLQueryPlan.cs | 35 +-- src/NHibernate/Async/Impl/SessionImpl.cs | 8 +- src/NHibernate/Engine/Query/HQLQueryPlan.cs | 20 +- src/NHibernate/Util/JoinedEnumerable.cs | 2 + 7 files changed, 23 insertions(+), 277 deletions(-) delete mode 100644 src/NHibernate.Test/UtilityTest/JoinedEnumerableFixture.cs diff --git a/src/NHibernate.Test/Async/Legacy/FooBarTest.cs b/src/NHibernate.Test/Async/Legacy/FooBarTest.cs index 0802496aa74..600dfeee02c 100644 --- a/src/NHibernate.Test/Async/Legacy/FooBarTest.cs +++ b/src/NHibernate.Test/Async/Legacy/FooBarTest.cs @@ -28,6 +28,7 @@ using NHibernate.Type; using NHibernate.Util; using NUnit.Framework; +using System.Linq; namespace NHibernate.Test.Legacy { @@ -1225,8 +1226,7 @@ public async Task BatchLoadAsync() await (s.DeleteAsync(baz2)); await (s.DeleteAsync(baz3)); - IEnumerable en = new JoinedEnumerable( - new IEnumerable[] {baz.FooSet, baz2.FooSet}); + IEnumerable en = Enumerable.Concat(baz.FooSet, baz2.FooSet); foreach (object obj in en) { @@ -3411,7 +3411,7 @@ public async Task PersistentLifecycleAsync() } [Test] - public async Task EnumerableAsync() + public async Task EnumerableTestAsync() { // this test used to be called Iterators() @@ -5282,10 +5282,9 @@ public async Task TransientOrphanDeleteAsync() baz.FooBag = foos; await (s.SaveAsync(baz)); - IEnumerator enumer = new JoinedEnumerable(new IEnumerable[] {foos, bars}).GetEnumerator(); - while (enumer.MoveNext()) + foreach(Foo foo in Enumerable.Concat(foos, bars)) { - FooComponent cmp = ((Foo) enumer.Current).Component; + FooComponent cmp = foo.Component; await (s.DeleteAsync(cmp.Glarch)); cmp.Glarch = null; } diff --git a/src/NHibernate.Test/Legacy/FooBarTest.cs b/src/NHibernate.Test/Legacy/FooBarTest.cs index 5ac93fee5d0..3c7c4138fa0 100644 --- a/src/NHibernate.Test/Legacy/FooBarTest.cs +++ b/src/NHibernate.Test/Legacy/FooBarTest.cs @@ -18,6 +18,7 @@ using NHibernate.Type; using NHibernate.Util; using NUnit.Framework; +using System.Linq; namespace NHibernate.Test.Legacy { @@ -1213,8 +1214,7 @@ public void BatchLoad() s.Delete(baz2); s.Delete(baz3); - IEnumerable en = new JoinedEnumerable( - new IEnumerable[] {baz.FooSet, baz2.FooSet}); + IEnumerable en = Enumerable.Concat(baz.FooSet, baz2.FooSet); foreach (object obj in en) { @@ -3399,7 +3399,7 @@ public void PersistentLifecycle() } [Test] - public void Enumerable() + public void EnumerableTest() { // this test used to be called Iterators() @@ -5270,10 +5270,9 @@ public void TransientOrphanDelete() baz.FooBag = foos; s.Save(baz); - IEnumerator enumer = new JoinedEnumerable(new IEnumerable[] {foos, bars}).GetEnumerator(); - while (enumer.MoveNext()) + foreach(Foo foo in Enumerable.Concat(foos, bars)) { - FooComponent cmp = ((Foo) enumer.Current).Component; + FooComponent cmp = foo.Component; s.Delete(cmp.Glarch); cmp.Glarch = null; } diff --git a/src/NHibernate.Test/UtilityTest/JoinedEnumerableFixture.cs b/src/NHibernate.Test/UtilityTest/JoinedEnumerableFixture.cs deleted file mode 100644 index c037121dc7c..00000000000 --- a/src/NHibernate.Test/UtilityTest/JoinedEnumerableFixture.cs +++ /dev/null @@ -1,213 +0,0 @@ -using System; -using System.Collections; -using NHibernate.Util; -using NUnit.Framework; - -namespace NHibernate.Test.UtilityTest -{ - /// - /// Test cases for the class. - /// - [TestFixture] - public class JoinedEnumerableFixture - { - /// - /// Test that the JoinedEnumerable works with a single wrapped - /// IEnumerable as expected when fully enumerating the collection. - /// - [Test] - public void WrapsSingle() - { - int[] expected = new int[] {1, 2, 3}; - - EnumerableTester first; - JoinedEnumerable joined = InitSingle(out first); - - int index = 0; - - foreach (int actual in joined) - { - Assert.AreEqual(expected[index], actual, "Failure at " + index.ToString()); - index++; - } - - Assert.AreEqual(expected.Length, index, "Every expected value was found"); - Assert.IsTrue(first.WasDisposed, "should have been disposed of."); - } - - /// - /// Test that the wrapped IEnumerator has Dispose called even when - /// the JoinedEnumerator doesn't enumerate all the way through the - /// collection. - /// - [Test] - public void WrapsSingleBreak() - { - int[] expected = new int[] {1, 2, 3}; - - EnumerableTester first; - JoinedEnumerable joined = InitSingle(out first); - - foreach (int actual in joined) - { - Assert.AreEqual(expected[0], actual, "first one was not what was expected."); - break; - } - - // ensure that the first was disposed of even though we didn't enumerate - // all the way through - Assert.IsTrue(first.WasDisposed, "should have been disposed of."); - } - - /// - /// Test that the JoinedEnumerable works with multiple wrapped - /// IEnumerable as expected when fully enumerating the collections. - /// - [Test] - public void WrapsMultiple() - { - int[] expected = new int[] {1, 2, 3, 4, 5, 6}; - - EnumerableTester first; - EnumerableTester second; - JoinedEnumerable joined = InitMultiple(out first, out second); - - int index = 0; - - foreach (int actual in joined) - { - Assert.AreEqual(expected[index], actual, "Failure at " + index.ToString()); - index++; - } - - Assert.AreEqual(expected.Length, index, "Every expected value was found"); - Assert.IsTrue(first.WasDisposed, "first should have been disposed of."); - Assert.IsTrue(second.WasDisposed, "second should have been disposed of. "); - } - - /// - /// Test that the JoinedEnumerable works with multiple wrapped - /// IEnumerable as expected when breaking out. - /// - [Test] - public void WrapsMultipleBreak() - { - // break in the first IEnumerator - WrapsMultipleBreak(2); - - // ensure behavior is consistent if break in 2nd IEnumerator - WrapsMultipleBreak(4); - } - - private void WrapsMultipleBreak(int breakIndex) - { - int[] expected = new int[] {1, 2, 3, 4, 5, 6}; - - EnumerableTester first; - EnumerableTester second; - JoinedEnumerable joined = InitMultiple(out first, out second); - - int index = 0; - - foreach (int actual in joined) - { - Assert.AreEqual(expected[index], actual, "Failure at " + index.ToString()); - index++; - if (index == breakIndex) - { - break; - } - } - - Assert.IsTrue(first.WasDisposed, "first should have been disposed of."); - Assert.IsTrue(second.WasDisposed, "second should have been disposed of. "); - } - - private JoinedEnumerable InitSingle(out EnumerableTester first) - { - first = new EnumerableTester(new ArrayList(new int[] {1, 2, 3})); - return new JoinedEnumerable(new IEnumerable[] {first}); - } - - private JoinedEnumerable InitMultiple(out EnumerableTester first, out EnumerableTester second) - { - first = new EnumerableTester(new ArrayList(new int[] {1, 2, 3})); - second = new EnumerableTester(new ArrayList(new int[] {4, 5, 6})); - return new JoinedEnumerable(new IEnumerable[] {first, second}); - } - } - - /// - /// Simple class that wraps an array list for testing purposes. - /// - internal class EnumerableTester : IEnumerable - { - private ArrayList _list; - private EnumerableTesterEnumerator _enumerator; - - public EnumerableTester(ArrayList wrappedList) - { - _list = wrappedList; - _enumerator = new EnumerableTesterEnumerator(_list.GetEnumerator()); - } - - public bool WasDisposed - { - get { return _enumerator.IsDisposed; } - } - - #region IEnumerable Members - - public IEnumerator GetEnumerator() - { - return _enumerator; - } - - #endregion - - private class EnumerableTesterEnumerator : IEnumerator, IDisposable - { - private IEnumerator _enumerator; - private bool _isDisposed; - - public EnumerableTesterEnumerator(IEnumerator enumerator) - { - _enumerator = enumerator; - } - - public bool IsDisposed - { - get { return _isDisposed; } - } - - #region IEnumerator Members - - public void Reset() - { - _isDisposed = false; - _enumerator.Reset(); - } - - public object Current - { - get { return _enumerator.Current; } - } - - public bool MoveNext() - { - return _enumerator.MoveNext(); - } - - #endregion - - #region IDisposable Members - - public void Dispose() - { - _isDisposed = true; - } - - #endregion - } - } -} diff --git a/src/NHibernate/Async/Engine/Query/HQLQueryPlan.cs b/src/NHibernate/Async/Engine/Query/HQLQueryPlan.cs index 853d1ad1261..1b7073558e2 100644 --- a/src/NHibernate/Async/Engine/Query/HQLQueryPlan.cs +++ b/src/NHibernate/Async/Engine/Query/HQLQueryPlan.cs @@ -11,7 +11,7 @@ using System; using System.Collections; using System.Collections.Generic; - +using System.Linq; using NHibernate.Event; using NHibernate.Hql; using NHibernate.Linq; @@ -26,8 +26,6 @@ public partial interface IQueryPlan { Task PerformListAsync(QueryParameters queryParameters, ISessionImplementor statelessSessionImpl, IList results, CancellationToken cancellationToken); Task PerformExecuteUpdateAsync(QueryParameters queryParameters, ISessionImplementor statelessSessionImpl, CancellationToken cancellationToken); - Task> PerformIterateAsync(QueryParameters queryParameters, IEventSource session, CancellationToken cancellationToken); - Task PerformIterateAsync(QueryParameters queryParameters, IEventSource session, CancellationToken cancellationToken); } public partial class HQLQueryPlan : IQueryPlan { @@ -100,37 +98,6 @@ public async Task PerformListAsync(QueryParameters queryParameters, ISessionImpl } } - public async Task PerformIterateAsync(QueryParameters queryParameters, IEventSource session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - if (Log.IsDebugEnabled()) - { - Log.Debug("enumerable: {0}", _sourceQuery); - queryParameters.LogParameters(session.Factory); - } - if (Translators.Length == 0) - { - return CollectionHelper.EmptyEnumerable; - } - if (Translators.Length == 1) - { - return await (Translators[0].GetEnumerableAsync(queryParameters, session, cancellationToken)).ConfigureAwait(false); - } - var results = new IEnumerable[Translators.Length]; - for (int i = 0; i < Translators.Length; i++) - { - var result = await (Translators[i].GetEnumerableAsync(queryParameters, session, cancellationToken)).ConfigureAwait(false); - results[i] = result; - } - return new JoinedEnumerable(results); - } - - public async Task> PerformIterateAsync(QueryParameters queryParameters, IEventSource session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - return new SafetyEnumerable(await (PerformIterateAsync(queryParameters, session, cancellationToken)).ConfigureAwait(false)); - } - public async Task PerformExecuteUpdateAsync(QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/NHibernate/Async/Impl/SessionImpl.cs b/src/NHibernate/Async/Impl/SessionImpl.cs index 7843a87a307..607fc69e45d 100644 --- a/src/NHibernate/Async/Impl/SessionImpl.cs +++ b/src/NHibernate/Async/Impl/SessionImpl.cs @@ -310,7 +310,7 @@ public override async Task> EnumerableAsync(IQueryExpression q using (SuspendAutoFlush()) //stops flush being called multiple times if this method is recursively called { - return await (plan.PerformIterateAsync(queryParameters, this, cancellationToken)).ConfigureAwait(false); + return plan.PerformIterate(queryParameters, this); } } } @@ -326,7 +326,7 @@ public override async Task EnumerableAsync(IQueryExpression queryEx using (SuspendAutoFlush()) //stops flush being called multiple times if this method is recursively called { - return await (plan.PerformIterateAsync(queryParameters, this, cancellationToken)).ConfigureAwait(false); + return plan.PerformIterate(queryParameters, this); } } } @@ -1107,7 +1107,7 @@ public override async Task EnumerableFilterAsync(object collection, using (BeginProcess()) { var plan = await (GetFilterQueryPlanAsync(collection, filter, queryParameters, true, cancellationToken)).ConfigureAwait(false); - return await (plan.PerformIterateAsync(queryParameters, this, cancellationToken)).ConfigureAwait(false); + return plan.PerformIterate(queryParameters, this); } } @@ -1117,7 +1117,7 @@ public override async Task> EnumerableFilterAsync(object colle using (BeginProcess()) { var plan = await (GetFilterQueryPlanAsync(collection, filter, queryParameters, true, cancellationToken)).ConfigureAwait(false); - return await (plan.PerformIterateAsync(queryParameters, this, cancellationToken)).ConfigureAwait(false); + return plan.PerformIterate(queryParameters, this); } } diff --git a/src/NHibernate/Engine/Query/HQLQueryPlan.cs b/src/NHibernate/Engine/Query/HQLQueryPlan.cs index ee1062a26e9..bf5eaa8a2a8 100644 --- a/src/NHibernate/Engine/Query/HQLQueryPlan.cs +++ b/src/NHibernate/Engine/Query/HQLQueryPlan.cs @@ -1,7 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; - +using System.Linq; using NHibernate.Event; using NHibernate.Hql; using NHibernate.Linq; @@ -157,21 +157,13 @@ public IEnumerable PerformIterate(QueryParameters queryParameters, IEventSource Log.Debug("enumerable: {0}", _sourceQuery); queryParameters.LogParameters(session.Factory); } - if (Translators.Length == 0) - { - return CollectionHelper.EmptyEnumerable; - } - if (Translators.Length == 1) - { - return Translators[0].GetEnumerable(queryParameters, session); - } - var results = new IEnumerable[Translators.Length]; - for (int i = 0; i < Translators.Length; i++) + + //TODO: FIXME AsyncGenerator throws for this code.. + foreach (var translator in Translators) + foreach (object obj in translator.GetEnumerable(queryParameters, session)) { - var result = Translators[i].GetEnumerable(queryParameters, session); - results[i] = result; + yield return obj; } - return new JoinedEnumerable(results); } public IEnumerable PerformIterate(QueryParameters queryParameters, IEventSource session) diff --git a/src/NHibernate/Util/JoinedEnumerable.cs b/src/NHibernate/Util/JoinedEnumerable.cs index df7c268efed..e8ebb8968eb 100644 --- a/src/NHibernate/Util/JoinedEnumerable.cs +++ b/src/NHibernate/Util/JoinedEnumerable.cs @@ -8,6 +8,8 @@ namespace NHibernate.Util /// /// Concatenates multiple objects implementing into one. /// + //Since 5.3 + [Obsolete("This class has no more usages in NHibernate and will be removed in a future version.")] public class JoinedEnumerable : IEnumerable { private static readonly INHibernateLogger log = NHibernateLogger.For(typeof(JoinedEnumerable)); From dc965b6fb80ff3b2b56d090fd72c2c93e2d2753d Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Sat, 23 Feb 2019 09:16:27 +0200 Subject: [PATCH 3/8] Another attempt to better iterate --- src/AsyncGenerator.yml | 3 ++ .../Async/Engine/Query/HQLQueryPlan.cs | 37 ++++++++++++++++++- src/NHibernate/Async/Impl/SessionImpl.cs | 8 ++-- src/NHibernate/Engine/Query/HQLQueryPlan.cs | 19 ++++++++-- 4 files changed, 57 insertions(+), 10 deletions(-) diff --git a/src/AsyncGenerator.yml b/src/AsyncGenerator.yml index 68ae0a1c735..954cb90d048 100644 --- a/src/AsyncGenerator.yml +++ b/src/AsyncGenerator.yml @@ -11,6 +11,9 @@ - conversion: Ignore name: ProcessResults containingTypeName: IQueryBatchItem + - conversion: Ignore + name: GetEnumerable + containingTypeName: HQLQueryPlan - conversion: Ignore name: PostProcessInsert containingTypeName: HqlSqlWalker diff --git a/src/NHibernate/Async/Engine/Query/HQLQueryPlan.cs b/src/NHibernate/Async/Engine/Query/HQLQueryPlan.cs index 1b7073558e2..b868c5574c0 100644 --- a/src/NHibernate/Async/Engine/Query/HQLQueryPlan.cs +++ b/src/NHibernate/Async/Engine/Query/HQLQueryPlan.cs @@ -12,6 +12,8 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Threading; +using System.Threading.Tasks; using NHibernate.Event; using NHibernate.Hql; using NHibernate.Linq; @@ -20,12 +22,12 @@ namespace NHibernate.Engine.Query { - using System.Threading.Tasks; - using System.Threading; public partial interface IQueryPlan { Task PerformListAsync(QueryParameters queryParameters, ISessionImplementor statelessSessionImpl, IList results, CancellationToken cancellationToken); Task PerformExecuteUpdateAsync(QueryParameters queryParameters, ISessionImplementor statelessSessionImpl, CancellationToken cancellationToken); + Task> PerformIterateAsync(QueryParameters queryParameters, IEventSource session, CancellationToken cancellationToken); + Task PerformIterateAsync(QueryParameters queryParameters, IEventSource session, CancellationToken cancellationToken); } public partial class HQLQueryPlan : IQueryPlan { @@ -98,6 +100,37 @@ public async Task PerformListAsync(QueryParameters queryParameters, ISessionImpl } } + public Task PerformIterateAsync(QueryParameters queryParameters, IEventSource session, CancellationToken cancellationToken) + { + if (cancellationToken.IsCancellationRequested) + { + return Task.FromCanceled(cancellationToken); + } + try + { + if (Log.IsDebugEnabled()) + { + Log.Debug("enumerable: {0}", _sourceQuery); + queryParameters.LogParameters(session.Factory); + } + + if (Translators.Length == 1) + return Translators[0].GetEnumerableAsync(queryParameters, session, cancellationToken); + + return Task.FromResult(GetEnumerable(queryParameters, session)); + } + catch (Exception ex) + { + return Task.FromException(ex); + } + } + + public async Task> PerformIterateAsync(QueryParameters queryParameters, IEventSource session, CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + return new SafetyEnumerable(await (PerformIterateAsync(queryParameters, session, cancellationToken)).ConfigureAwait(false)); + } + public async Task PerformExecuteUpdateAsync(QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/NHibernate/Async/Impl/SessionImpl.cs b/src/NHibernate/Async/Impl/SessionImpl.cs index 607fc69e45d..7843a87a307 100644 --- a/src/NHibernate/Async/Impl/SessionImpl.cs +++ b/src/NHibernate/Async/Impl/SessionImpl.cs @@ -310,7 +310,7 @@ public override async Task> EnumerableAsync(IQueryExpression q using (SuspendAutoFlush()) //stops flush being called multiple times if this method is recursively called { - return plan.PerformIterate(queryParameters, this); + return await (plan.PerformIterateAsync(queryParameters, this, cancellationToken)).ConfigureAwait(false); } } } @@ -326,7 +326,7 @@ public override async Task EnumerableAsync(IQueryExpression queryEx using (SuspendAutoFlush()) //stops flush being called multiple times if this method is recursively called { - return plan.PerformIterate(queryParameters, this); + return await (plan.PerformIterateAsync(queryParameters, this, cancellationToken)).ConfigureAwait(false); } } } @@ -1107,7 +1107,7 @@ public override async Task EnumerableFilterAsync(object collection, using (BeginProcess()) { var plan = await (GetFilterQueryPlanAsync(collection, filter, queryParameters, true, cancellationToken)).ConfigureAwait(false); - return plan.PerformIterate(queryParameters, this); + return await (plan.PerformIterateAsync(queryParameters, this, cancellationToken)).ConfigureAwait(false); } } @@ -1117,7 +1117,7 @@ public override async Task> EnumerableFilterAsync(object colle using (BeginProcess()) { var plan = await (GetFilterQueryPlanAsync(collection, filter, queryParameters, true, cancellationToken)).ConfigureAwait(false); - return plan.PerformIterate(queryParameters, this); + return await (plan.PerformIterateAsync(queryParameters, this, cancellationToken)).ConfigureAwait(false); } } diff --git a/src/NHibernate/Engine/Query/HQLQueryPlan.cs b/src/NHibernate/Engine/Query/HQLQueryPlan.cs index bf5eaa8a2a8..1a202763887 100644 --- a/src/NHibernate/Engine/Query/HQLQueryPlan.cs +++ b/src/NHibernate/Engine/Query/HQLQueryPlan.cs @@ -2,6 +2,8 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Threading; +using System.Threading.Tasks; using NHibernate.Event; using NHibernate.Hql; using NHibernate.Linq; @@ -158,11 +160,20 @@ public IEnumerable PerformIterate(QueryParameters queryParameters, IEventSource queryParameters.LogParameters(session.Factory); } - //TODO: FIXME AsyncGenerator throws for this code.. - foreach (var translator in Translators) - foreach (object obj in translator.GetEnumerable(queryParameters, session)) + if (Translators.Length == 1) + return Translators[0].GetEnumerable(queryParameters, session); + + return GetEnumerable(queryParameters, session); + } + + private IEnumerable GetEnumerable(QueryParameters queryParameters, IEventSource session) + { + foreach (var t in Translators) { - yield return obj; + foreach (object obj in t.GetEnumerable(queryParameters, session)) + { + yield return obj; + } } } From ca0ac69cc980e61ff20efc5ca389e295c450e98c Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Sat, 16 Nov 2019 20:59:14 +0200 Subject: [PATCH 4/8] Make Enumerable reusable --- .../Async/Engine/Query/HQLQueryPlan.cs | 19 ++++++------------- src/NHibernate/Async/Impl/SessionImpl.cs | 8 ++++---- src/NHibernate/Engine/Query/HQLQueryPlan.cs | 11 ++++++++--- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/NHibernate/Async/Engine/Query/HQLQueryPlan.cs b/src/NHibernate/Async/Engine/Query/HQLQueryPlan.cs index b868c5574c0..195c3fc4bd9 100644 --- a/src/NHibernate/Async/Engine/Query/HQLQueryPlan.cs +++ b/src/NHibernate/Async/Engine/Query/HQLQueryPlan.cs @@ -26,8 +26,6 @@ public partial interface IQueryPlan { Task PerformListAsync(QueryParameters queryParameters, ISessionImplementor statelessSessionImpl, IList results, CancellationToken cancellationToken); Task PerformExecuteUpdateAsync(QueryParameters queryParameters, ISessionImplementor statelessSessionImpl, CancellationToken cancellationToken); - Task> PerformIterateAsync(QueryParameters queryParameters, IEventSource session, CancellationToken cancellationToken); - Task PerformIterateAsync(QueryParameters queryParameters, IEventSource session, CancellationToken cancellationToken); } public partial class HQLQueryPlan : IQueryPlan { @@ -99,7 +97,8 @@ public async Task PerformListAsync(QueryParameters queryParameters, ISessionImpl ArrayHelper.AddAll(combinedResults, tmp); } } - + // Since v5.3 + [Obsolete("This method has no more usages and will be removed in a future version")] public Task PerformIterateAsync(QueryParameters queryParameters, IEventSource session, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) @@ -108,16 +107,7 @@ public Task PerformIterateAsync(QueryParameters queryParameters, IE } try { - if (Log.IsDebugEnabled()) - { - Log.Debug("enumerable: {0}", _sourceQuery); - queryParameters.LogParameters(session.Factory); - } - - if (Translators.Length == 1) - return Translators[0].GetEnumerableAsync(queryParameters, session, cancellationToken); - - return Task.FromResult(GetEnumerable(queryParameters, session)); + return Task.FromResult(PerformIterate(queryParameters, session)); } catch (Exception ex) { @@ -125,9 +115,12 @@ public Task PerformIterateAsync(QueryParameters queryParameters, IE } } + // Since v5.3 + [Obsolete("This method has no more usages and will be removed in a future version")] public async Task> PerformIterateAsync(QueryParameters queryParameters, IEventSource session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); + //TODO 6.0: Get rid of SafetyEnumerable and use Cast return new SafetyEnumerable(await (PerformIterateAsync(queryParameters, session, cancellationToken)).ConfigureAwait(false)); } diff --git a/src/NHibernate/Async/Impl/SessionImpl.cs b/src/NHibernate/Async/Impl/SessionImpl.cs index 7843a87a307..607fc69e45d 100644 --- a/src/NHibernate/Async/Impl/SessionImpl.cs +++ b/src/NHibernate/Async/Impl/SessionImpl.cs @@ -310,7 +310,7 @@ public override async Task> EnumerableAsync(IQueryExpression q using (SuspendAutoFlush()) //stops flush being called multiple times if this method is recursively called { - return await (plan.PerformIterateAsync(queryParameters, this, cancellationToken)).ConfigureAwait(false); + return plan.PerformIterate(queryParameters, this); } } } @@ -326,7 +326,7 @@ public override async Task EnumerableAsync(IQueryExpression queryEx using (SuspendAutoFlush()) //stops flush being called multiple times if this method is recursively called { - return await (plan.PerformIterateAsync(queryParameters, this, cancellationToken)).ConfigureAwait(false); + return plan.PerformIterate(queryParameters, this); } } } @@ -1107,7 +1107,7 @@ public override async Task EnumerableFilterAsync(object collection, using (BeginProcess()) { var plan = await (GetFilterQueryPlanAsync(collection, filter, queryParameters, true, cancellationToken)).ConfigureAwait(false); - return await (plan.PerformIterateAsync(queryParameters, this, cancellationToken)).ConfigureAwait(false); + return plan.PerformIterate(queryParameters, this); } } @@ -1117,7 +1117,7 @@ public override async Task> EnumerableFilterAsync(object colle using (BeginProcess()) { var plan = await (GetFilterQueryPlanAsync(collection, filter, queryParameters, true, cancellationToken)).ConfigureAwait(false); - return await (plan.PerformIterateAsync(queryParameters, this, cancellationToken)).ConfigureAwait(false); + return plan.PerformIterate(queryParameters, this); } } diff --git a/src/NHibernate/Engine/Query/HQLQueryPlan.cs b/src/NHibernate/Engine/Query/HQLQueryPlan.cs index 1a202763887..7a02d5da601 100644 --- a/src/NHibernate/Engine/Query/HQLQueryPlan.cs +++ b/src/NHibernate/Engine/Query/HQLQueryPlan.cs @@ -22,6 +22,13 @@ public partial interface IQueryPlan int PerformExecuteUpdate(QueryParameters queryParameters, ISessionImplementor statelessSessionImpl); IEnumerable PerformIterate(QueryParameters queryParameters, IEventSource session); IEnumerable PerformIterate(QueryParameters queryParameters, IEventSource session); + + // Since v5.3 + [Obsolete("This method has no more usages and will be removed in a future version")] + Task> PerformIterateAsync(QueryParameters queryParameters, IEventSource session, CancellationToken cancellationToken); + // Since v5.3 + [Obsolete("This method has no more usages and will be removed in a future version")] + Task PerformIterateAsync(QueryParameters queryParameters, IEventSource session, CancellationToken cancellationToken); } public interface IQueryExpressionPlan : IQueryPlan @@ -160,9 +167,6 @@ public IEnumerable PerformIterate(QueryParameters queryParameters, IEventSource queryParameters.LogParameters(session.Factory); } - if (Translators.Length == 1) - return Translators[0].GetEnumerable(queryParameters, session); - return GetEnumerable(queryParameters, session); } @@ -179,6 +183,7 @@ private IEnumerable GetEnumerable(QueryParameters queryParameters, IEven public IEnumerable PerformIterate(QueryParameters queryParameters, IEventSource session) { + //TODO 6.0: Get rid of SafetyEnumerable and use Cast return new SafetyEnumerable(PerformIterate(queryParameters, session)); } From dc52284f7be13c9aed3fb7f9a941cc04af5392ff Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Sat, 16 Nov 2019 22:08:47 +0200 Subject: [PATCH 5/8] Fix Enumerable Dispose logic --- src/NHibernate/NHibernateUtil.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/NHibernate/NHibernateUtil.cs b/src/NHibernate/NHibernateUtil.cs index e781db52bef..f56065faaf2 100644 --- a/src/NHibernate/NHibernateUtil.cs +++ b/src/NHibernate/NHibernateUtil.cs @@ -1,7 +1,5 @@ using System; -using System.Collections; using NHibernate.Collection; -using NHibernate.Impl; using NHibernate.Intercept; using NHibernate.Proxy; using NHibernate.Type; @@ -532,7 +530,7 @@ public static Clob CreateClob(TextReader reader, int length) { /// public static void Close(IEnumerator enumerator) { - EnumerableImpl hibernateEnumerator = enumerator as EnumerableImpl; + var hibernateEnumerator = enumerator as IDisposable; if (hibernateEnumerator == null) { throw new ArgumentException("Not a NHibernate enumerator", nameof(enumerator)); @@ -546,7 +544,7 @@ public static void Close(IEnumerator enumerator) /// public static void Close(IEnumerable enumerable) { - EnumerableImpl hibernateEnumerable = enumerable as EnumerableImpl; + var hibernateEnumerable = enumerable as IDisposable; if (hibernateEnumerable == null) { throw new ArgumentException("Not a NHibernate enumerable", nameof(enumerable)); From a18e5bf9480a2f88b0cfa9655238eca01a250249 Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Sat, 16 Nov 2019 22:11:32 +0200 Subject: [PATCH 6/8] Oups --- src/NHibernate/NHibernateUtil.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/NHibernate/NHibernateUtil.cs b/src/NHibernate/NHibernateUtil.cs index f56065faaf2..dd3d3a143db 100644 --- a/src/NHibernate/NHibernateUtil.cs +++ b/src/NHibernate/NHibernateUtil.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using NHibernate.Collection; using NHibernate.Intercept; using NHibernate.Proxy; From 940559d42954cf7dfa71525623499c3209143a35 Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Sat, 16 Nov 2019 22:37:05 +0200 Subject: [PATCH 7/8] Fix test --- .../Async/ConnectionTest/AggressiveReleaseTest.cs | 1 + src/NHibernate.Test/ConnectionTest/AggressiveReleaseTest.cs | 1 + src/NHibernate/Async/NHibernateUtil.cs | 1 - 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/NHibernate.Test/Async/ConnectionTest/AggressiveReleaseTest.cs b/src/NHibernate.Test/Async/ConnectionTest/AggressiveReleaseTest.cs index 24dca7f8a36..860ae86ea3f 100644 --- a/src/NHibernate.Test/Async/ConnectionTest/AggressiveReleaseTest.cs +++ b/src/NHibernate.Test/Async/ConnectionTest/AggressiveReleaseTest.cs @@ -92,6 +92,7 @@ public async Task SerializationFailsOnAfterStatementAggressiveReleaseWithOpenRes // to resources, which should make aggresive-Release not Release // the connection (and thus cause serialization to fail) IEnumerable en = await (s.CreateQuery("from Silly").EnumerableAsync()); + en.GetEnumerator().MoveNext(); try { diff --git a/src/NHibernate.Test/ConnectionTest/AggressiveReleaseTest.cs b/src/NHibernate.Test/ConnectionTest/AggressiveReleaseTest.cs index efb6d5488fc..916acb160ce 100644 --- a/src/NHibernate.Test/ConnectionTest/AggressiveReleaseTest.cs +++ b/src/NHibernate.Test/ConnectionTest/AggressiveReleaseTest.cs @@ -80,6 +80,7 @@ public void SerializationFailsOnAfterStatementAggressiveReleaseWithOpenResources // to resources, which should make aggresive-Release not Release // the connection (and thus cause serialization to fail) IEnumerable en = s.CreateQuery("from Silly").Enumerable(); + en.GetEnumerator().MoveNext(); try { diff --git a/src/NHibernate/Async/NHibernateUtil.cs b/src/NHibernate/Async/NHibernateUtil.cs index fd7959973ac..8e4241acb97 100644 --- a/src/NHibernate/Async/NHibernateUtil.cs +++ b/src/NHibernate/Async/NHibernateUtil.cs @@ -11,7 +11,6 @@ using System; using System.Collections; using NHibernate.Collection; -using NHibernate.Impl; using NHibernate.Intercept; using NHibernate.Proxy; using NHibernate.Type; From 7d19b9e3e8946b781fe413ba9cb599684e6cefc2 Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Sat, 16 Nov 2019 22:48:22 +0200 Subject: [PATCH 8/8] Fix test --- src/NHibernate.Test/Async/Stats/StatsFixture.cs | 1 + src/NHibernate.Test/Stats/StatsFixture.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/NHibernate.Test/Async/Stats/StatsFixture.cs b/src/NHibernate.Test/Async/Stats/StatsFixture.cs index f36c5cb7cd8..1b05dfc89b7 100644 --- a/src/NHibernate.Test/Async/Stats/StatsFixture.cs +++ b/src/NHibernate.Test/Async/Stats/StatsFixture.cs @@ -174,6 +174,7 @@ public async Task QueryStatGatheringAsync() Assert.AreEqual( continents, stats.QueryExecutionMaxTimeQueryString ); IEnumerable itr = await (s.CreateQuery(continents).EnumerableAsync()); + itr.GetEnumerator().MoveNext(); // Enumerable() should increment the execution count Assert.AreEqual(2, continentStats.ExecutionCount, "unexpected execution count"); // but should not effect the cumulative row count diff --git a/src/NHibernate.Test/Stats/StatsFixture.cs b/src/NHibernate.Test/Stats/StatsFixture.cs index 98beb3c37a3..0147b8066f0 100644 --- a/src/NHibernate.Test/Stats/StatsFixture.cs +++ b/src/NHibernate.Test/Stats/StatsFixture.cs @@ -162,6 +162,7 @@ public void QueryStatGathering() Assert.AreEqual( continents, stats.QueryExecutionMaxTimeQueryString ); IEnumerable itr = s.CreateQuery(continents).Enumerable(); + itr.GetEnumerator().MoveNext(); // Enumerable() should increment the execution count Assert.AreEqual(2, continentStats.ExecutionCount, "unexpected execution count"); // but should not effect the cumulative row count