2311 |
03 Apr 14 |
nicklas |
1 |
package net.sf.basedb.reggie.query; |
2311 |
03 Apr 14 |
nicklas |
2 |
|
2311 |
03 Apr 14 |
nicklas |
3 |
import java.util.Collection; |
2311 |
03 Apr 14 |
nicklas |
4 |
import java.util.Collections; |
2311 |
03 Apr 14 |
nicklas |
5 |
|
2311 |
03 Apr 14 |
nicklas |
6 |
import net.sf.basedb.core.BaseException; |
2311 |
03 Apr 14 |
nicklas |
7 |
import net.sf.basedb.core.DbControl; |
2311 |
03 Apr 14 |
nicklas |
8 |
import net.sf.basedb.core.query.Expression; |
2311 |
03 Apr 14 |
nicklas |
9 |
import net.sf.basedb.core.query.Query; |
2311 |
03 Apr 14 |
nicklas |
10 |
import net.sf.basedb.core.query.QueryElement; |
2311 |
03 Apr 14 |
nicklas |
11 |
import net.sf.basedb.util.EqualsHelper; |
2311 |
03 Apr 14 |
nicklas |
12 |
|
2311 |
03 Apr 14 |
nicklas |
13 |
/** |
2311 |
03 Apr 14 |
nicklas |
Expression that converts a string value to lowercase. |
2311 |
03 Apr 14 |
nicklas |
@author nicklas |
2311 |
03 Apr 14 |
nicklas |
@since 2.15 |
2311 |
03 Apr 14 |
nicklas |
17 |
*/ |
2311 |
03 Apr 14 |
nicklas |
18 |
public class LowerExpression |
2311 |
03 Apr 14 |
nicklas |
19 |
implements Expression |
2311 |
03 Apr 14 |
nicklas |
20 |
{ |
2311 |
03 Apr 14 |
nicklas |
21 |
|
2311 |
03 Apr 14 |
nicklas |
22 |
private final Expression e; |
2311 |
03 Apr 14 |
nicklas |
23 |
|
2311 |
03 Apr 14 |
nicklas |
24 |
public LowerExpression(Expression e) |
2311 |
03 Apr 14 |
nicklas |
25 |
{ |
2311 |
03 Apr 14 |
nicklas |
26 |
this.e = e; |
2311 |
03 Apr 14 |
nicklas |
27 |
} |
2311 |
03 Apr 14 |
nicklas |
28 |
|
2311 |
03 Apr 14 |
nicklas |
29 |
@Override |
2311 |
03 Apr 14 |
nicklas |
30 |
public String toQl(Query query, DbControl dc) |
2311 |
03 Apr 14 |
nicklas |
31 |
throws BaseException |
2311 |
03 Apr 14 |
nicklas |
32 |
{ |
2311 |
03 Apr 14 |
nicklas |
33 |
return "lower("+e.toQl(query, dc) + ")"; |
2311 |
03 Apr 14 |
nicklas |
34 |
} |
2311 |
03 Apr 14 |
nicklas |
35 |
|
2311 |
03 Apr 14 |
nicklas |
36 |
@Override |
2311 |
03 Apr 14 |
nicklas |
37 |
public Collection<? extends QueryElement> getChildren() |
2311 |
03 Apr 14 |
nicklas |
38 |
{ |
2311 |
03 Apr 14 |
nicklas |
39 |
return Collections.singleton(e); |
2311 |
03 Apr 14 |
nicklas |
40 |
} |
2311 |
03 Apr 14 |
nicklas |
41 |
|
2311 |
03 Apr 14 |
nicklas |
42 |
@Override |
2311 |
03 Apr 14 |
nicklas |
43 |
public String toString() |
2311 |
03 Apr 14 |
nicklas |
44 |
{ |
2311 |
03 Apr 14 |
nicklas |
45 |
return "lower(" + e + ")"; |
2311 |
03 Apr 14 |
nicklas |
46 |
} |
2311 |
03 Apr 14 |
nicklas |
47 |
|
2311 |
03 Apr 14 |
nicklas |
48 |
/** |
2311 |
03 Apr 14 |
nicklas |
This expression is equal to another LowerExpression if their |
2311 |
03 Apr 14 |
nicklas |
child expressions are equal. |
2311 |
03 Apr 14 |
nicklas |
51 |
*/ |
2311 |
03 Apr 14 |
nicklas |
52 |
@Override |
2311 |
03 Apr 14 |
nicklas |
53 |
public boolean equals(Object other) |
2311 |
03 Apr 14 |
nicklas |
54 |
{ |
2311 |
03 Apr 14 |
nicklas |
55 |
if (this == other) return true; |
2311 |
03 Apr 14 |
nicklas |
56 |
if ((other == null) || (super.getClass() != other.getClass())) return false; |
2311 |
03 Apr 14 |
nicklas |
57 |
LowerExpression o = (LowerExpression)other; |
2311 |
03 Apr 14 |
nicklas |
58 |
return EqualsHelper.equals(e, o.e); |
2311 |
03 Apr 14 |
nicklas |
59 |
} |
2311 |
03 Apr 14 |
nicklas |
60 |
|
2311 |
03 Apr 14 |
nicklas |
61 |
@Override |
2311 |
03 Apr 14 |
nicklas |
62 |
public int hashCode() |
2311 |
03 Apr 14 |
nicklas |
63 |
{ |
2311 |
03 Apr 14 |
nicklas |
64 |
return EqualsHelper.hashCode(e) + getClass().hashCode(); |
2311 |
03 Apr 14 |
nicklas |
65 |
} |
2311 |
03 Apr 14 |
nicklas |
66 |
} |