|
From: <fab...@us...> - 2009-05-07 18:00:53
|
Revision: 4262
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4262&view=rev
Author: fabiomaulo
Date: 2009-05-07 18:00:44 +0000 (Thu, 07 May 2009)
Log Message:
-----------
- Minor adjust of exceptions
- Test for "with" clause
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/InvalidWithClauseException.cs
trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QuerySyntaxException.cs
trunk/nhibernate/src/NHibernate/QueryException.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/HQL/Ast/WithClauseFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/InvalidWithClauseException.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/InvalidWithClauseException.cs 2009-05-07 15:04:34 UTC (rev 4261)
+++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/InvalidWithClauseException.cs 2009-05-07 18:00:44 UTC (rev 4262)
@@ -1,13 +1,16 @@
-namespace NHibernate.Hql.Ast.ANTLR
+using System;
+using System.Runtime.Serialization;
+
+namespace NHibernate.Hql.Ast.ANTLR
{
- class InvalidWithClauseException : QuerySyntaxException
+ [CLSCompliant(false)]
+ [Serializable]
+ public class InvalidWithClauseException : QuerySyntaxException
{
- public InvalidWithClauseException(string message) : base(message)
- {
- }
+ protected InvalidWithClauseException() {}
+ public InvalidWithClauseException(string message) : base(message) {}
+ public InvalidWithClauseException(string message, Exception inner) : base(message, inner) {}
- public InvalidWithClauseException(string message, string hql) : base(message, hql)
- {
- }
+ protected InvalidWithClauseException(SerializationInfo info, StreamingContext context) : base(info, context) {}
}
-}
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QuerySyntaxException.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QuerySyntaxException.cs 2009-05-07 15:04:34 UTC (rev 4261)
+++ trunk/nhibernate/src/NHibernate/Hql/Ast/ANTLR/QuerySyntaxException.cs 2009-05-07 18:00:44 UTC (rev 4262)
@@ -1,20 +1,21 @@
using System;
+using System.Runtime.Serialization;
using Antlr.Runtime;
namespace NHibernate.Hql.Ast.ANTLR
{
[CLSCompliant(false)]
+ [Serializable]
public class QuerySyntaxException : QueryException
{
- public QuerySyntaxException(string message) : base(message)
- {
- }
+ protected QuerySyntaxException() {}
+ public QuerySyntaxException(string message, string hql) : base(message, hql) {}
- public QuerySyntaxException(string message, string hql)
- : base(message, hql)
- {
- }
+ public QuerySyntaxException(string message) : base(message) {}
+ public QuerySyntaxException(string message, Exception inner) : base(message, inner) {}
+ protected QuerySyntaxException(SerializationInfo info, StreamingContext context) : base(info, context) {}
+
public static QuerySyntaxException Convert(RecognitionException e)
{
return Convert(e, null);
@@ -23,9 +24,9 @@
public static QuerySyntaxException Convert(RecognitionException e, string hql)
{
string positionInfo = e.Line > 0 && e.CharPositionInLine > 0
- ? " near line " + e.Line + ", column " + e.CharPositionInLine
- : "";
+ ? " near line " + e.Line + ", column " + e.CharPositionInLine
+ : "";
return new QuerySyntaxException(e.Message + positionInfo, hql);
}
}
-}
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/QueryException.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/QueryException.cs 2009-05-07 15:04:34 UTC (rev 4261)
+++ trunk/nhibernate/src/NHibernate/QueryException.cs 2009-05-07 18:00:44 UTC (rev 4262)
@@ -12,6 +12,8 @@
{
private string queryString;
+ protected QueryException() {}
+
/// <summary>
/// Initializes a new instance of the <see cref="QueryException"/> class.
/// </summary>
Added: trunk/nhibernate/src/NHibernate.Test/HQL/Ast/WithClauseFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/HQL/Ast/WithClauseFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/HQL/Ast/WithClauseFixture.cs 2009-05-07 18:00:44 UTC (rev 4262)
@@ -0,0 +1,159 @@
+using System.Collections;
+using NHibernate.Hql.Ast.ANTLR;
+using NUnit.Framework;
+
+namespace NHibernate.Test.HQL.Ast
+{
+ [TestFixture, Ignore("Not suported yet.")]
+ public class WithClauseFixture : BaseFixture
+ {
+ public ISession OpenNewSession()
+ {
+ return OpenSession();
+ }
+
+ [Test]
+ public void WithClauseFailsWithFetch()
+ {
+ var data = new TestData(this);
+ data.Prepare();
+
+ ISession s = OpenSession();
+ ITransaction txn = s.BeginTransaction();
+
+ Assert.Throws<HibernateException>(
+ () =>
+ s.CreateQuery("from Animal a inner join fetch a.offspring as o with o.bodyWeight = :someLimit").SetDouble(
+ "someLimit", 1).List(), "ad-hoc on clause allowed with fetched association");
+
+ txn.Commit();
+ s.Close();
+
+ data.Cleanup();
+ }
+
+ [Test]
+ public void InvalidWithSemantics()
+ {
+ ISession s = OpenSession();
+ ITransaction txn = s.BeginTransaction();
+
+ // PROBLEM : f.bodyWeight is a reference to a column on the Animal table; however, the 'f'
+ // alias relates to the Human.friends collection which the aonther Human entity. The issue
+ // here is the way JoinSequence and Joinable (the persister) interact to generate the
+ // joins relating to the sublcass/superclass tables
+ Assert.Throws<InvalidWithClauseException>(
+ () =>
+ s.CreateQuery("from Human h inner join h.friends as f with f.bodyWeight < :someLimit").SetDouble("someLimit", 1).
+ List());
+
+ Assert.Throws<InvalidWithClauseException>(
+ () =>
+ s.CreateQuery(
+ "from Animal a inner join a.offspring o inner join o.mother as m inner join m.father as f with o.bodyWeight > 1").
+ List());
+
+ Assert.Throws<InvalidWithClauseException>(
+ () =>
+ s.CreateQuery("from Human h inner join h.offspring o with o.mother.father = :cousin").SetEntity("cousin",
+ s.Load<Human>(123L))
+ .List());
+
+ txn.Commit();
+ s.Close();
+ }
+
+ [Test]
+ public void WithClause()
+ {
+ var data = new TestData(this);
+ data.Prepare();
+
+ ISession s = OpenSession();
+ ITransaction txn = s.BeginTransaction();
+
+ // one-to-many
+ IList list =
+ s.CreateQuery("from Human h inner join h.offspring as o with o.bodyWeight < :someLimit").SetDouble("someLimit", 1).
+ List();
+ Assert.That(list, Is.Empty, "ad-hoc on did not take effect");
+
+ // many-to-one
+ list =
+ s.CreateQuery("from Animal a inner join a.mother as m with m.bodyWeight < :someLimit").SetDouble("someLimit", 1).
+ List();
+ Assert.That(list, Is.Empty, "ad-hoc on did not take effect");
+
+ // many-to-many
+ list = s.CreateQuery("from Human h inner join h.friends as f with f.nickName like 'bubba'").List();
+ Assert.That(list, Is.Empty, "ad-hoc on did not take effect");
+
+ txn.Commit();
+ s.Close();
+
+ data.Cleanup();
+ }
+
+ private class TestData
+ {
+ private readonly WithClauseFixture tc;
+
+ public TestData(WithClauseFixture tc)
+ {
+ this.tc = tc;
+ }
+
+ public void Prepare()
+ {
+ ISession session = tc.OpenNewSession();
+ ITransaction txn = session.BeginTransaction();
+
+ var mother = new Human {BodyWeight = 10, Description = "mother"};
+
+ var father = new Human {BodyWeight = 15, Description = "father"};
+
+ var child1 = new Human {BodyWeight = 5, Description = "child1"};
+
+ var child2 = new Human {BodyWeight = 6, Description = "child2"};
+
+ var friend = new Human {BodyWeight = 20, Description = "friend"};
+
+ child1.Mother = mother;
+ child1.Father = father;
+ mother.AddOffspring(child1);
+ father.AddOffspring(child1);
+
+ child2.Mother = mother;
+ child2.Father = father;
+ mother.AddOffspring(child2);
+ father.AddOffspring(child2);
+
+ father.Friends = new[] {friend};
+
+ session.Save(mother);
+ session.Save(father);
+ session.Save(child1);
+ session.Save(child2);
+ session.Save(friend);
+
+ txn.Commit();
+ session.Close();
+ }
+
+ public void Cleanup()
+ {
+ ISession session = tc.OpenNewSession();
+ ITransaction txn = session.BeginTransaction();
+ session.CreateQuery("delete Animal where mother is not null").ExecuteUpdate();
+ IList humansWithFriends = session.CreateQuery("from Human h where exists(from h.friends)").List();
+ foreach (var friend in humansWithFriends)
+ {
+ session.Delete(friend);
+ }
+ session.CreateQuery("delete Animal").ExecuteUpdate();
+ txn.Commit();
+ session.Close();
+ }
+ }
+ }
+}
\ 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 15:04:34 UTC (rev 4261)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-05-07 18:00:44 UTC (rev 4262)
@@ -322,6 +322,7 @@
<Compile Include="HQL\Ast\TimestampVersioned.cs" />
<Compile Include="HQL\Ast\User.cs" />
<Compile Include="HQL\Ast\Vehicles.cs" />
+ <Compile Include="HQL\Ast\WithClauseFixture.cs" />
<Compile Include="HQL\Ast\Zoo.cs" />
<Compile Include="HQL\BaseFunctionFixture.cs" />
<Compile Include="NHSpecificTest\Dates\TimeFixture.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|