From: <fab...@us...> - 2010-07-28 21:42:37
|
Revision: 5077 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5077&view=rev Author: fabiomaulo Date: 2010-07-28 21:42:28 +0000 (Wed, 28 Jul 2010) Log Message: ----------- Generalized IHqlGeneratorForType Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Linq/Functions/BaseHqlGeneratorForType.cs trunk/nhibernate/src/NHibernate/Linq/Functions/IHqlGeneratorForType.cs Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/BaseHqlGeneratorForType.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Functions/BaseHqlGeneratorForType.cs 2010-07-28 21:35:11 UTC (rev 5076) +++ trunk/nhibernate/src/NHibernate/Linq/Functions/BaseHqlGeneratorForType.cs 2010-07-28 21:42:28 UTC (rev 5077) @@ -1,42 +1,45 @@ using System; using System.Collections.Generic; using System.Reflection; -using NHibernate.Linq.Visitors; namespace NHibernate.Linq.Functions { - abstract public class BaseHqlGeneratorForType : IHqlGeneratorForType - { - protected readonly List<IHqlGeneratorForMethod> MethodRegistry = new List<IHqlGeneratorForMethod>(); - protected readonly List<IHqlGeneratorForProperty> PropertyRegistry = new List<IHqlGeneratorForProperty>(); + public abstract class BaseHqlGeneratorForType : IHqlGeneratorForType + { + protected readonly List<IHqlGeneratorForMethod> MethodRegistry = new List<IHqlGeneratorForMethod>(); + protected readonly List<IHqlGeneratorForProperty> PropertyRegistry = new List<IHqlGeneratorForProperty>(); - public void Register(DefaultLinqToHqlGeneratorsRegistry functionRegistry) - { - foreach (var generator in MethodRegistry) - { - foreach (var method in generator.SupportedMethods) - { - functionRegistry.RegisterGenerator(method, generator); - } - } + #region IHqlGeneratorForType Members - foreach (var generator in PropertyRegistry) - { - foreach (var property in generator.SupportedProperties) - { - functionRegistry.RegisterGenerator(property, generator); - } - } - } + public void Register(ILinqToHqlGeneratorsRegistry functionRegistry) + { + foreach (IHqlGeneratorForMethod generator in MethodRegistry) + { + foreach (MethodInfo method in generator.SupportedMethods) + { + functionRegistry.RegisterGenerator(method, generator); + } + } - public virtual bool SupportsMethod(MethodInfo method) - { - return false; - } + foreach (IHqlGeneratorForProperty generator in PropertyRegistry) + { + foreach (MemberInfo property in generator.SupportedProperties) + { + functionRegistry.RegisterGenerator(property, generator); + } + } + } - public virtual IHqlGeneratorForMethod GetMethodGenerator(MethodInfo method) - { - throw new NotSupportedException(); - } - } + public virtual bool SupportsMethod(MethodInfo method) + { + return false; + } + + public virtual IHqlGeneratorForMethod GetMethodGenerator(MethodInfo method) + { + throw new NotSupportedException(); + } + + #endregion + } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/IHqlGeneratorForType.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Functions/IHqlGeneratorForType.cs 2010-07-28 21:35:11 UTC (rev 5076) +++ trunk/nhibernate/src/NHibernate/Linq/Functions/IHqlGeneratorForType.cs 2010-07-28 21:42:28 UTC (rev 5077) @@ -2,10 +2,10 @@ namespace NHibernate.Linq.Functions { - public interface IHqlGeneratorForType - { - void Register(DefaultLinqToHqlGeneratorsRegistry functionRegistry); - bool SupportsMethod(MethodInfo method); - IHqlGeneratorForMethod GetMethodGenerator(MethodInfo method); - } + public interface IHqlGeneratorForType + { + void Register(ILinqToHqlGeneratorsRegistry functionRegistry); + bool SupportsMethod(MethodInfo method); + IHqlGeneratorForMethod GetMethodGenerator(MethodInfo method); + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fab...@us...> - 2010-07-31 14:16:00
|
Revision: 5086 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5086&view=rev Author: fabiomaulo Date: 2010-07-31 14:15:53 +0000 (Sat, 31 Jul 2010) Log Message: ----------- - relax of DateTimePropertiesHqlGenerator - removed if in ToUpperLowerGenerator (separated in two classes) Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Linq/Functions/DateTimePropertiesHqlGenerator.cs trunk/nhibernate/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/DateTimePropertiesHqlGenerator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Functions/DateTimePropertiesHqlGenerator.cs 2010-07-31 13:59:59 UTC (rev 5085) +++ trunk/nhibernate/src/NHibernate/Linq/Functions/DateTimePropertiesHqlGenerator.cs 2010-07-31 14:15:53 UTC (rev 5086) @@ -33,7 +33,7 @@ } } - public HqlTreeNode BuildHql(MemberInfo member, Expression expression, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) + public virtual HqlTreeNode BuildHql(MemberInfo member, Expression expression, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) { return treeBuilder.MethodCall(member.Name.ToLowerInvariant(), visitor.Visit(expression).AsExpression()); Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs 2010-07-31 13:59:59 UTC (rev 5085) +++ trunk/nhibernate/src/NHibernate/Linq/Functions/DefaultLinqToHqlGeneratorsRegistry.cs 2010-07-31 14:15:53 UTC (rev 5086) @@ -19,7 +19,8 @@ this.Merge(new EndsWithGenerator()); this.Merge(new ContainsGenerator()); this.Merge(new EqualsGenerator()); - this.Merge(new ToUpperLowerGenerator()); + this.Merge(new ToUpperGenerator()); + this.Merge(new ToLowerGenerator()); this.Merge(new SubStringGenerator()); this.Merge(new IndexOfGenerator()); this.Merge(new ReplaceGenerator()); Modified: trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs 2010-07-31 13:59:59 UTC (rev 5085) +++ trunk/nhibernate/src/NHibernate/Linq/Functions/StringGenerator.cs 2010-07-31 14:15:53 UTC (rev 5086) @@ -86,14 +86,12 @@ } } - public class ToUpperLowerGenerator : BaseHqlGeneratorForMethod + public class ToLowerGenerator : BaseHqlGeneratorForMethod { - public ToUpperLowerGenerator() + public ToLowerGenerator() { SupportedMethods = new[] { - ReflectionHelper.GetMethodDefinition<string>(x => x.ToUpper()), - ReflectionHelper.GetMethodDefinition<string>(x => x.ToUpperInvariant()), ReflectionHelper.GetMethodDefinition<string>(x => x.ToLower()), ReflectionHelper.GetMethodDefinition<string>(x => x.ToLowerInvariant()) }; @@ -101,18 +99,24 @@ public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) { - string methodName; + return treeBuilder.MethodCall("lower", visitor.Visit(targetObject).AsExpression()); + } + } - if (((method.Name == "ToUpper") || (method.Name == "ToUpperInvariant"))) - { - methodName = "upper"; - } - else - { - methodName = "lower"; - } + public class ToUpperGenerator : BaseHqlGeneratorForMethod + { + public ToUpperGenerator() + { + SupportedMethods = new[] + { + ReflectionHelper.GetMethodDefinition<string>(x => x.ToUpper()), + ReflectionHelper.GetMethodDefinition<string>(x => x.ToUpperInvariant()), + }; + } - return treeBuilder.MethodCall(methodName, visitor.Visit(targetObject).AsExpression()); + public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) + { + return treeBuilder.MethodCall("upper", visitor.Visit(targetObject).AsExpression()); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |