-
Notifications
You must be signed in to change notification settings - Fork 0
/
NHibernateStringComparison.cs
121 lines (109 loc) · 4.46 KB
/
NHibernateStringComparison.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System.Collections.ObjectModel;
using System.Reflection;
using NHibernate.Hql.Ast;
using NHibernate.Linq;
using NHibernate.Linq.Functions;
using NHibernate.Linq.Visitors;
namespace deviolib
{
public static class StringComparison
{
public static bool GreaterThan(this string s, string other)
{
return string.Compare(s, other) > 0;
}
public static bool GreaterThanOrEqual(this string s, string other)
{
return string.Compare(s, other) >= 0;
}
public static bool LessThan(this string s, string other)
{
return string.Compare(s, other) < 0;
}
public static bool LessThanOrEqual(this string s, string other)
{
return string.Compare(s, other) <= 0;
}
}
}
namespace deviolib.NHibernate
{
public class StringGreaterThanGenerator : BaseHqlGeneratorForMethod
{
public StringGreaterThanGenerator()
{
SupportedMethods = new[]
{
ReflectionHelper.GetMethodDefinition<string>(x => x.GreaterThan(null))
};
}
public override HqlTreeNode BuildHql(MethodInfo method, System.Linq.Expressions.Expression targetObject, ReadOnlyCollection<System.Linq.Expressions.Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
{
return treeBuilder.GreaterThan(
visitor.Visit(targetObject).AsExpression(),
visitor.Visit(arguments[0]).AsExpression());
}
}
public class StringGreaterThanOrEqualGenerator : BaseHqlGeneratorForMethod
{
public StringGreaterThanOrEqualGenerator()
{
SupportedMethods = new[]
{
ReflectionHelper.GetMethodDefinition<string>(x => x.GreaterThanOrEqual(null))
};
}
public override HqlTreeNode BuildHql(MethodInfo method, System.Linq.Expressions.Expression targetObject, ReadOnlyCollection<System.Linq.Expressions.Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
{
return treeBuilder.GreaterThanOrEqual(
visitor.Visit(arguments[0]).AsExpression(),
visitor.Visit(arguments[1]).AsExpression());
}
}
public class StringLessThanGenerator : BaseHqlGeneratorForMethod
{
public StringLessThanGenerator()
{
SupportedMethods = new[]
{
ReflectionHelper.GetMethodDefinition<string>(x => x.LessThan(null))
};
}
public override HqlTreeNode BuildHql(MethodInfo method, System.Linq.Expressions.Expression targetObject, ReadOnlyCollection<System.Linq.Expressions.Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
{
return treeBuilder.LessThan(
visitor.Visit(targetObject).AsExpression(),
visitor.Visit(arguments[0]).AsExpression());
}
}
public class StringLessThanOrEqualGenerator : BaseHqlGeneratorForMethod
{
public StringLessThanOrEqualGenerator()
{
SupportedMethods = new[]
{
ReflectionHelper.GetMethodDefinition<string>(x => x.LessThanOrEqual(null))
};
}
public override HqlTreeNode BuildHql(MethodInfo method, System.Linq.Expressions.Expression targetObject, ReadOnlyCollection<System.Linq.Expressions.Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
{
return treeBuilder.LessThanOrEqual(
visitor.Visit(arguments[0]).AsExpression(),
visitor.Visit(arguments[1]).AsExpression());
}
}
public class StringComparisonLinqtoHqlGeneratorsRegistry : DefaultLinqToHqlGeneratorsRegistry
{
public StringComparisonLinqtoHqlGeneratorsRegistry()
{
this.Merge(new StringGreaterThanGenerator());
this.Merge(new StringGreaterThanOrEqualGenerator());
this.Merge(new StringLessThanGenerator());
this.Merge(new StringLessThanOrEqualGenerator());
}
}
}
/*
activate using
configuration.LinqToHqlGeneratorsRegistry<StringComparisonLinqtoHqlGeneratorsRegistry>();
*/