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 / IsNull.java @ 44748
History | View | Annotate | Download (1.64 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 | 44198 | jjdelcerro | import org.gvsig.expressionevaluator.Code.Constant; |
8 | import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
||
9 | import static org.gvsig.expressionevaluator.ExpressionBuilder.OPERATOR_IS; |
||
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 | class IsNull implements Formatter<Value> { |
||
19 | |||
20 | private final Formatter<Value> formatter; |
||
21 | private final SQLBuilder builder; |
||
22 | |||
23 | public IsNull(SQLBuilder builder, Formatter<Value> formatter) { |
||
24 | this.builder = builder;
|
||
25 | this.formatter = formatter;
|
||
26 | } |
||
27 | |||
28 | @Override
|
||
29 | public boolean canApply(Value value) { |
||
30 | if (value instanceof Function) { |
||
31 | if( StringUtils.equalsIgnoreCase(OPERATOR_IS, ((Function) value).name()) ) {
|
||
32 | 44748 | jjdelcerro | List<Pair<String,Value>> parameters = ((Function) value).parameters(); |
33 | Value p2 = parameters.get(1).getValue();
|
||
34 | 44198 | jjdelcerro | if( p2 instanceof Constant && ((Constant)p2).value()==null ) { |
35 | return true; |
||
36 | } |
||
37 | } |
||
38 | } |
||
39 | return false; |
||
40 | } |
||
41 | |||
42 | @Override
|
||
43 | public String format(Value function) { |
||
44 | 44748 | jjdelcerro | List<Pair<String,Value>> parameters = ((Function) function).parameters(); |
45 | String p1 = parameters.get(0).getValue().toString(formatter); |
||
46 | 44198 | jjdelcerro | String r = MessageFormat.format("( ({0}) IS NULL )", p1); |
47 | return r;
|
||
48 | } |
||
49 | |||
50 | } |