From: <fab...@us...> - 2009-05-07 05:02:58
|
Revision: 4258 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4258&view=rev Author: fabiomaulo Date: 2009-05-07 05:02:56 +0000 (Thu, 07 May 2009) Log Message: ----------- - CR-LF in BulkManipulation - moved test to Ast - ReturnMetadata now is working - NH-322 was fixed with the new parser Modified Paths: -------------- trunk/nhibernate/src/NHibernate.Test/HQL/Ast/BulkManipulation.cs trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj Added Paths: ----------- trunk/nhibernate/src/NHibernate.Test/HQL/Ast/HqlFixture.cs Removed Paths: ------------- trunk/nhibernate/src/NHibernate.Test/HQL/HqlFixture.cs Modified: trunk/nhibernate/src/NHibernate.Test/HQL/Ast/BulkManipulation.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/HQL/Ast/BulkManipulation.cs 2009-05-07 03:34:37 UTC (rev 4257) +++ trunk/nhibernate/src/NHibernate.Test/HQL/Ast/BulkManipulation.cs 2009-05-07 05:02:56 UTC (rev 4258) @@ -228,17 +228,17 @@ [Test] public void UpdateOnManyToOne() - { + { ISession s = OpenSession(); ITransaction t = s.BeginTransaction(); - - s.CreateQuery("update Animal a set a.mother = null where a.id = 2").ExecuteUpdate(); + + s.CreateQuery("update Animal a set a.mother = null where a.id = 2").ExecuteUpdate(); if (! (Dialect is MySQLDialect)) - { - // MySQL does not support (even un-correlated) subqueries against the update-mutating table - s.CreateQuery("update Animal a set a.mother = (from Animal where id = 1) where a.id = 2").ExecuteUpdate(); - } - + { + // MySQL does not support (even un-correlated) subqueries against the update-mutating table + s.CreateQuery("update Animal a set a.mother = (from Animal where id = 1) where a.id = 2").ExecuteUpdate(); + } + t.Commit(); s.Close(); } @@ -310,70 +310,70 @@ s.Close(); data.Cleanup(); - } + } [Test] public void UpdateOnAnimal() - { + { var data = new TestData(this); data.Prepare(); ISession s = OpenSession(); ITransaction t = s.BeginTransaction(); int count = - s.CreateQuery("update Animal set description = description where description = :desc") - .SetString("desc", data.Frog.Description) + s.CreateQuery("update Animal set description = description where description = :desc") + .SetString("desc", data.Frog.Description) .ExecuteUpdate(); Assert.That(count, Is.EqualTo(1), "Incorrect entity-updated count"); - + count = - s.CreateQuery("update Animal set description = :newDesc where description = :desc") - .SetString("desc",data.Polliwog.Description) - .SetString("newDesc", "Tadpole") + s.CreateQuery("update Animal set description = :newDesc where description = :desc") + .SetString("desc",data.Polliwog.Description) + .SetString("newDesc", "Tadpole") .ExecuteUpdate(); Assert.That(count, Is.EqualTo(1), "Incorrect entity-updated count"); - + var tadpole = s.Load<Animal>(data.Polliwog.Id); Assert.That(tadpole.Description, Is.EqualTo("Tadpole"), "Update did not take effect"); - + count = s.CreateQuery("update Animal set bodyWeight = bodyWeight + :w1 + :w2") .SetDouble("w1", 1) - .SetDouble("w2", 2) + .SetDouble("w2", 2) .ExecuteUpdate(); Assert.That(count, Is.EqualTo(6), "incorrect count on 'complex' update assignment"); - + if (! (Dialect is MySQLDialect)) - { - // MySQL does not support (even un-correlated) subqueries against the update-mutating table - s.CreateQuery("update Animal set bodyWeight = ( select max(bodyWeight) from Animal )").ExecuteUpdate(); + { + // MySQL does not support (even un-correlated) subqueries against the update-mutating table + s.CreateQuery("update Animal set bodyWeight = ( select max(bodyWeight) from Animal )").ExecuteUpdate(); } t.Commit(); s.Close(); data.Cleanup(); - } + } [Test] public void UpdateOnMammal() - { + { var data = new TestData(this); data.Prepare(); ISession s = OpenSession(); ITransaction t = s.BeginTransaction(); - + int count = s.CreateQuery("update Mammal set description = description").ExecuteUpdate(); Assert.That(count, Is.EqualTo(2), "incorrect update count against 'middle' of joined-subclass hierarchy"); - + count = s.CreateQuery("update Mammal set bodyWeight = 25").ExecuteUpdate(); Assert.That(count, Is.EqualTo(2), "incorrect update count against 'middle' of joined-subclass hierarchy"); - + if (! (Dialect is MySQLDialect)) { - // MySQL does not support (even un-correlated) subqueries against the update-mutating table + // MySQL does not support (even un-correlated) subqueries against the update-mutating table count = s.CreateQuery("update Mammal set bodyWeight = ( select max(bodyWeight) from Animal )").ExecuteUpdate(); Assert.That(count, Is.EqualTo(2), "incorrect update count against 'middle' of joined-subclass hierarchy"); } @@ -462,7 +462,7 @@ s.Close(); data.Cleanup(); - } + } #endregion Copied: trunk/nhibernate/src/NHibernate.Test/HQL/Ast/HqlFixture.cs (from rev 4248, trunk/nhibernate/src/NHibernate.Test/HQL/HqlFixture.cs) =================================================================== --- trunk/nhibernate/src/NHibernate.Test/HQL/Ast/HqlFixture.cs (rev 0) +++ trunk/nhibernate/src/NHibernate.Test/HQL/Ast/HqlFixture.cs 2009-05-07 05:02:56 UTC (rev 4258) @@ -0,0 +1,95 @@ +using System.Collections; +using NHibernate.Engine.Query; +using NHibernate.Util; +using NUnit.Framework; + +namespace NHibernate.Test.HQL.Ast +{ + [TestFixture] + public class HqlFixture : BaseFixture + { + protected HQLQueryPlan CreateQueryPlan(string hql, bool scalar) + { + return new HQLQueryPlan(hql, scalar, new CollectionHelper.EmptyMapClass<string, IFilter>(), sessions); + } + + protected HQLQueryPlan CreateQueryPlan(string hql) + { + return CreateQueryPlan(hql, false); + } + + private static void Check(ReturnMetadata returnMetadata, bool expectingEmptyTypes, bool expectingEmptyAliases) + { + Assert.IsNotNull(returnMetadata, "null return metadata"); + Assert.IsNotNull(returnMetadata, "null return metadata - types"); + Assert.AreEqual(1, returnMetadata.ReturnTypes.Length, "unexpected return size"); + + if (expectingEmptyTypes) + { + Assert.IsNull(returnMetadata.ReturnTypes[0], "non-empty types"); + } + else + { + Assert.IsNotNull(returnMetadata.ReturnTypes[0], "empty types"); + } + + if (expectingEmptyAliases) + { + Assert.IsNull(returnMetadata.ReturnAliases, "non-empty aliases"); + } + else + { + Assert.IsNotNull(returnMetadata.ReturnAliases, "empty aliases"); + Assert.IsNotNull(returnMetadata.ReturnAliases[0], "empty aliases"); + } + } + + [Test] + public void ReturnMetadata() + { + HQLQueryPlan plan; + plan = CreateQueryPlan("from Animal a"); + Check(plan.ReturnMetadata, false, true); + + plan = CreateQueryPlan("select a as animal from Animal a"); + Check(plan.ReturnMetadata, false, false); + + plan = CreateQueryPlan("from System.Object"); + Check(plan.ReturnMetadata, true, true); + + plan = CreateQueryPlan("select o as entity from System.Object o"); + Check(plan.ReturnMetadata, true, false); + } + + [Test] + public void CaseClauseInSelect() + { + // NH-322 + using (ISession s = OpenSession()) + using (s.BeginTransaction()) + { + s.Save(new Animal {BodyWeight = 12, Description = "Polliwog"}); + s.Transaction.Commit(); + } + + using (ISession s = OpenSession()) + { + var l = s.CreateQuery("select a.id, case when a.description = 'Polliwog' then 2 else 0 end from Animal a").List(); + var element = (IList)l[0]; + Assert.That(element[1], Is.EqualTo(2)); + + // work with alias + l = s.CreateQuery("select a.id, case when a.description = 'Polliwog' then 2 else 0 end as value from Animal a").List(); + element = (IList)l[0]; + Assert.That(element[1], Is.EqualTo(2)); + } + + using (ISession s = OpenSession()) + using (s.BeginTransaction()) + { + s.CreateQuery("delete from Animal").ExecuteUpdate(); + s.Transaction.Commit(); + } + } + } +} \ No newline at end of file Deleted: trunk/nhibernate/src/NHibernate.Test/HQL/HqlFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/HQL/HqlFixture.cs 2009-05-07 03:34:37 UTC (rev 4257) +++ trunk/nhibernate/src/NHibernate.Test/HQL/HqlFixture.cs 2009-05-07 05:02:56 UTC (rev 4258) @@ -1,74 +0,0 @@ -using System.Collections; -using NHibernate.Engine.Query; -using NHibernate.Util; -using NUnit.Framework; - -namespace NHibernate.Test.Hql -{ - [TestFixture, Ignore("Not supported yet.")] - public class HqlFixture : TestCase - { - protected override string MappingsAssembly - { - get { return "NHibernate.Test"; } - } - - protected override IList Mappings - { - get { return new[] {"HQL.Animal.hbm.xml"}; } - } - - protected HQLQueryPlan CreateQueryPlan(string hql, bool scalar) - { - return new HQLQueryPlan(hql, scalar, new CollectionHelper.EmptyMapClass<string, IFilter>(), sessions); - } - - protected HQLQueryPlan CreateQueryPlan(string hql) - { - return CreateQueryPlan(hql, false); - } - - private static void Check(ReturnMetadata returnMetadata, bool expectingEmptyTypes, bool expectingEmptyAliases) - { - Assert.IsNotNull(returnMetadata, "null return metadata"); - Assert.IsNotNull(returnMetadata, "null return metadata - types"); - Assert.AreEqual(1, returnMetadata.ReturnTypes.Length, "unexpected return size"); - - if (expectingEmptyTypes) - { - Assert.IsNull(returnMetadata.ReturnTypes[0], "non-empty types"); - } - else - { - Assert.IsNotNull(returnMetadata.ReturnTypes[0], "empty types"); - } - - if (expectingEmptyAliases) - { - Assert.IsNull(returnMetadata.ReturnAliases, "non-empty aliases"); - } - else - { - Assert.IsNotNull(returnMetadata.ReturnAliases, "empty aliases"); - Assert.IsNotNull(returnMetadata.ReturnAliases[0], "empty aliases"); - } - } - - [Test] - public void ReturnMetadata() - { - HQLQueryPlan plan; - plan = CreateQueryPlan("from Animal a"); - Check(plan.ReturnMetadata, false, true); - - plan = CreateQueryPlan("select a as animal from Animal a"); - Check(plan.ReturnMetadata, false, false); - - plan = CreateQueryPlan("from java.lang.Object"); - Check(plan.ReturnMetadata, true, true); - - plan = CreateQueryPlan("select o as entity from java.lang.Object o"); - Check(plan.ReturnMetadata, true, false); - } - } -} \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj =================================================================== --- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-05-07 03:34:37 UTC (rev 4257) +++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-05-07 05:02:56 UTC (rev 4258) @@ -364,7 +364,7 @@ <Compile Include="HQL\SQLFunctionTemplateTest.cs" /> <Compile Include="BulkManipulation\NativeSQLBulkOperations.cs" /> <Compile Include="BulkManipulation\Vehicles.cs" /> - <Compile Include="HQL\HqlFixture.cs" /> + <Compile Include="HQL\Ast\HqlFixture.cs" /> <Compile Include="IdGen\Enhanced\SequenceStyleConfigUnitFixture.cs" /> <Compile Include="IdGen\NativeGuid\NativeGuidFixture.cs" /> <Compile Include="IdGen\NativeGuid\NativeGuidGeneratorFixture.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |