svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.db / org.gvsig.fmap.dal.db.mdb / src / main / java / org / gvsig / fmap / dal / store / mdb / expressionbuilderformatter / ILike.java @ 46505
History | View | Annotate | Download (1.33 KB)
1 |
package org.gvsig.fmap.dal.store.mdb.expressionbuilderformatter; |
---|---|
2 |
|
3 |
import java.text.MessageFormat; |
4 |
import org.apache.commons.lang3.StringUtils; |
5 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
6 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
7 |
import org.gvsig.expressionevaluator.Formatter; |
8 |
import org.gvsig.fmap.dal.SQLBuilder; |
9 |
|
10 |
/**
|
11 |
*
|
12 |
* @author jjdelcerro
|
13 |
*/
|
14 |
public class ILike implements Formatter<Value> { |
15 |
|
16 |
private final SQLBuilder sqlbuilder; |
17 |
private final Formatter<Value> formatter; |
18 |
|
19 |
public ILike(SQLBuilder sqlbuilder, Formatter<Value> formatter) { |
20 |
this.sqlbuilder = sqlbuilder;
|
21 |
this.formatter = formatter;
|
22 |
} |
23 |
@Override
|
24 |
public boolean canApply(ExpressionBuilder.Value value) { |
25 |
if (value instanceof ExpressionBuilder.BinaryOperator) { |
26 |
return StringUtils.equalsIgnoreCase(ExpressionBuilder.OPERATOR_ILIKE, ((ExpressionBuilder.BinaryOperator) value).name());
|
27 |
} |
28 |
return false; |
29 |
} |
30 |
|
31 |
@Override
|
32 |
public String format(Value value) { |
33 |
ExpressionBuilder.BinaryOperator operator = (ExpressionBuilder.BinaryOperator) value; |
34 |
String p1 = operator.left().toString(formatter);
|
35 |
String p2 = operator.right().toString(formatter);
|
36 |
String r = MessageFormat.format("(lcase({0}) like lcase({1}))", p1, p2); |
37 |
return r;
|
38 |
} |
39 |
|
40 |
} |