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 / ST_AsBinary.java @ 44748
History | View | Annotate | Download (1.36 KB)
1 | 44198 | jjdelcerro | package org.gvsig.fmap.dal.store.h2.expressionbuilderformatter; |
---|---|---|---|
2 | |||
3 | import java.text.MessageFormat; |
||
4 | import java.util.List; |
||
5 | import org.apache.commons.lang3.StringUtils; |
||
6 | 44748 | jjdelcerro | import org.apache.commons.lang3.tuple.Pair; |
7 | 44644 | jjdelcerro | import static org.gvsig.expressionevaluator.GeometryExpressionBuilder.FUNCTION_ST_ASBINARY; |
8 | 44198 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
9 | import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
||
10 | import org.gvsig.expressionevaluator.Formatter; |
||
11 | import org.gvsig.fmap.dal.SQLBuilder; |
||
12 | |||
13 | /**
|
||
14 | *
|
||
15 | * @author jjdelcerro
|
||
16 | */
|
||
17 | 44353 | jjdelcerro | class ST_AsBinary implements Formatter<Value> { |
18 | 44198 | jjdelcerro | |
19 | private final Formatter<Value> formatter; |
||
20 | private final SQLBuilder builder; |
||
21 | |||
22 | 44353 | jjdelcerro | public ST_AsBinary(SQLBuilder builder, Formatter<Value> formatter) { |
23 | 44198 | jjdelcerro | this.builder = builder;
|
24 | this.formatter = formatter;
|
||
25 | } |
||
26 | |||
27 | @Override
|
||
28 | public boolean canApply(Value value) { |
||
29 | if (value instanceof Function) { |
||
30 | 44353 | jjdelcerro | return StringUtils.equalsIgnoreCase(FUNCTION_ST_ASBINARY, ((Function) value).name());
|
31 | 44198 | jjdelcerro | } |
32 | return false; |
||
33 | } |
||
34 | |||
35 | @Override
|
||
36 | public String format(Value function) { |
||
37 | 44748 | jjdelcerro | List<Pair<String,Value>> parameters = ((Function) function).parameters(); |
38 | String p1 = parameters.get(0).getValue().toString(formatter); |
||
39 | 44611 | jjdelcerro | String r = MessageFormat.format("NVL2({0},ST_AsBinary({0}),NULL)", p1); |
40 | 44198 | jjdelcerro | return r;
|
41 | } |
||
42 | |||
43 | } |