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.h2 / src / main / java / org / gvsig / fmap / dal / store / h2 / expressionbuilderformatter / Decode.java @ 44748
History | View | Annotate | Download (2.34 KB)
1 | 44198 | jjdelcerro | package org.gvsig.fmap.dal.store.h2.expressionbuilderformatter; |
---|---|---|---|
2 | |||
3 | import java.util.List; |
||
4 | 44296 | jjdelcerro | import java.util.Objects; |
5 | 44198 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
6 | 44748 | jjdelcerro | import org.apache.commons.lang3.tuple.Pair; |
7 | 44198 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionBuilder; |
8 | 44296 | jjdelcerro | import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_DECODE; |
9 | 44198 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
10 | import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
||
11 | import org.gvsig.expressionevaluator.Formatter; |
||
12 | import org.gvsig.fmap.dal.SQLBuilder; |
||
13 | |||
14 | /**
|
||
15 | *
|
||
16 | * @author jjdelcerro
|
||
17 | */
|
||
18 | 44296 | jjdelcerro | public class Decode implements Formatter<Value> { |
19 | 44198 | jjdelcerro | |
20 | private final SQLBuilder sqlbuilder; |
||
21 | private final Formatter<Value> formatter; |
||
22 | |||
23 | 44296 | jjdelcerro | public Decode(SQLBuilder sqlbuilder, Formatter<Value> formatter) { |
24 | 44198 | jjdelcerro | this.sqlbuilder = sqlbuilder;
|
25 | this.formatter = formatter;
|
||
26 | } |
||
27 | 44296 | jjdelcerro | |
28 | 44198 | jjdelcerro | @Override
|
29 | public boolean canApply(ExpressionBuilder.Value value) { |
||
30 | if (value instanceof ExpressionBuilder.Function) { |
||
31 | 44296 | jjdelcerro | if( StringUtils.equalsIgnoreCase(FUNCTION_DECODE, ((Function) value).name()) ) {
|
32 | 44748 | jjdelcerro | List<Pair<String,Value>> parameters = ((Function) value).parameters(); |
33 | 44296 | jjdelcerro | if( parameters.size()==2) { |
34 | 44748 | jjdelcerro | Value p1 = parameters.get(0).getValue();
|
35 | Value p2 = parameters.get(1).getValue();
|
||
36 | 44296 | jjdelcerro | if( p1 instanceof ExpressionBuilder.Constant && |
37 | p2 instanceof ExpressionBuilder.Constant &&
|
||
38 | ((ExpressionBuilder.Constant)p1).value() instanceof String && |
||
39 | ((ExpressionBuilder.Constant)p2).value() instanceof String |
||
40 | ) { |
||
41 | String p2value = ((ExpressionBuilder.Constant)p2).value().toString();
|
||
42 | if( StringUtils.equalsIgnoreCase(p2value, "hex") ) { |
||
43 | return true; |
||
44 | } |
||
45 | } |
||
46 | |||
47 | } |
||
48 | } |
||
49 | 44198 | jjdelcerro | } |
50 | return false; |
||
51 | } |
||
52 | |||
53 | @Override
|
||
54 | public String format(Value function) { |
||
55 | 44748 | jjdelcerro | List<Pair<String,Value>> parameters = ((Function) function).parameters(); |
56 | Value p1 = parameters.get(0).getValue();
|
||
57 | 44296 | jjdelcerro | String p1value = Objects.toString(((ExpressionBuilder.Constant)p1).value(), ""); |
58 | String r = "X'"+p1value+"'"; |
||
59 | 44198 | jjdelcerro | return r;
|
60 | } |
||
61 | |||
62 | } |