|
From: <fab...@us...> - 2010-10-06 17:09:47
|
Revision: 5231
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5231&view=rev
Author: fabiomaulo
Date: 2010-10-06 17:09:41 +0000 (Wed, 06 Oct 2010)
Log Message:
-----------
Applied NH-2357 by Daniel Guenter
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs
trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/Linq/BooleanMethodExtensionExample.cs
Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs 2010-10-01 11:55:44 UTC (rev 5230)
+++ trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeBuilder.cs 2010-10-06 17:09:41 UTC (rev 5231)
@@ -351,6 +351,11 @@
return new HqlMethodCall(_factory, methodName, parameters);
}
+ public HqlBooleanMethodCall BooleanMethodCall(string methodName, IEnumerable<HqlExpression> parameters)
+ {
+ return new HqlBooleanMethodCall(_factory, methodName, parameters);
+ }
+
public HqlDistinctHolder DistinctHolder(params HqlTreeNode[] children)
{
return new HqlDistinctHolder(_factory, children);
Modified: trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs 2010-10-01 11:55:44 UTC (rev 5230)
+++ trunk/nhibernate/src/NHibernate/Hql/Ast/HqlTreeNode.cs 2010-10-06 17:09:41 UTC (rev 5231)
@@ -810,6 +810,16 @@
}
}
+ public class HqlBooleanMethodCall : HqlBooleanExpression
+ {
+ public HqlBooleanMethodCall(IASTFactory factory, string methodName, IEnumerable<HqlExpression> parameters)
+ : base(HqlSqlWalker.METHOD_CALL, "method", factory)
+ {
+ AddChild(new HqlIdent(factory, methodName));
+ AddChild(new HqlExpressionList(factory, parameters));
+ }
+ }
+
public class HqlDistinctHolder : HqlExpression
{
public HqlDistinctHolder(IASTFactory factory, HqlTreeNode[] children) : base(int.MinValue, "distinct holder", factory, children)
Added: trunk/nhibernate/src/NHibernate.Test/Linq/BooleanMethodExtensionExample.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Linq/BooleanMethodExtensionExample.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/Linq/BooleanMethodExtensionExample.cs 2010-10-06 17:09:41 UTC (rev 5231)
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Reflection;
+using NHibernate.Cfg;
+using NHibernate.Cfg.Loquacious;
+using NHibernate.Hql.Ast;
+using NHibernate.Linq;
+using NHibernate.Linq.Functions;
+using NHibernate.Linq.Visitors;
+using NHibernate.Test.Linq.Entities;
+using NUnit.Framework;
+using SharpTestsEx;
+
+namespace NHibernate.Test.Linq
+{
+ public static class BooleanLinqExtensions
+ {
+ public static bool FreeText(this string source, string pattern)
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+ public class FreetextGenerator : BaseHqlGeneratorForMethod
+ {
+ public FreetextGenerator()
+ {
+ SupportedMethods = new[] {ReflectionHelper.GetMethodDefinition(() => BooleanLinqExtensions.FreeText(null, null))};
+ }
+
+ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject,
+ ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder,
+ IHqlExpressionVisitor visitor)
+ {
+ IEnumerable<HqlExpression> args = arguments.Select(a => visitor.Visit(a))
+ .Cast<HqlExpression>();
+
+ return treeBuilder.BooleanMethodCall("FREETEXT", args);
+ }
+ }
+
+ [TestFixture]
+ public class BooleanMethodExtensionExample : LinqTestCase
+ {
+ public class MyLinqToHqlGeneratorsRegistry : DefaultLinqToHqlGeneratorsRegistry
+ {
+ public MyLinqToHqlGeneratorsRegistry()
+ {
+ RegisterGenerator(ReflectionHelper.GetMethodDefinition(() => BooleanLinqExtensions.FreeText(null, null)),
+ new FreetextGenerator());
+ }
+ }
+
+ protected override void Configure(Configuration configuration)
+ {
+ configuration.LinqToHqlGeneratorsRegistry<MyLinqToHqlGeneratorsRegistry>();
+ }
+
+ [Test, Ignore("It work only with full-text indexes enabled.")]
+ public void CanUseMyCustomExtension()
+ {
+ List<Customer> contacts = (from c in db.Customers where c.ContactName.FreeText("Thomas") select c).ToList();
+ contacts.Count.Should().Be.GreaterThan(0);
+ contacts.Select(customer => customer.ContactName).All(c => c.Satisfy(customer => customer.Contains("Thomas")));
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-10-01 11:55:44 UTC (rev 5230)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2010-10-06 17:09:41 UTC (rev 5231)
@@ -404,6 +404,7 @@
<Compile Include="Linq\AggregateTests.cs" />
<Compile Include="Linq\BinaryBooleanExpressionTests.cs" />
<Compile Include="Linq\BinaryExpressionOrdererTests.cs" />
+ <Compile Include="Linq\BooleanMethodExtensionExample.cs" />
<Compile Include="Linq\CasingTest.cs" />
<Compile Include="Linq\CollectionAssert.cs" />
<Compile Include="Linq\CustomExtensionsExample.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|