svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.h2spatial / org.gvsig.h2spatial.h2gis132 / org.gvsig.h2spatial.h2gis132.provider / src / main / java / org / gvsig / fmap / dal / store / h2 / expressionbuilderformatter / IsNotNull.java @ 46104
History | View | Annotate | Download (2.19 KB)
1 |
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 |
import org.gvsig.expressionevaluator.Code.Constant; |
7 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
8 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.OPERATOR_IS; |
9 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.OPERATOR_NOT; |
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 IsNotNull implements Formatter<Value> { |
19 |
|
20 |
private final Formatter<Value> formatter; |
21 |
private final SQLBuilder builder; |
22 |
|
23 |
public IsNotNull(SQLBuilder builder, Formatter<Value> formatter) { |
24 |
this.builder = builder;
|
25 |
this.formatter = formatter;
|
26 |
} |
27 |
|
28 |
@Override
|
29 |
public boolean canApply(Value value_not) { |
30 |
if (value_not instanceof Function) { |
31 |
// NOT( IS( p1, NULL) )
|
32 |
if( StringUtils.equalsIgnoreCase(OPERATOR_NOT, ((Function) value_not).name()) ) {
|
33 |
List<Value> parameters = ((Function) value_not).parameters();
|
34 |
Value value_is = parameters.get(0);
|
35 |
if( value_is instanceof Function && StringUtils.equalsIgnoreCase(OPERATOR_IS, ((Function)value_is).name()) ) { |
36 |
List<Value> parameters_is = ((Function) value_is).parameters();
|
37 |
Value is_p2 = parameters_is.get(1);
|
38 |
if( is_p2 instanceof Constant && ((Constant)is_p2).value()==null ) { |
39 |
return true; |
40 |
} |
41 |
} |
42 |
} |
43 |
} |
44 |
return false; |
45 |
} |
46 |
|
47 |
@Override
|
48 |
public String format(Value value_not) { |
49 |
// NOT( IS( p1, NULL) )
|
50 |
|
51 |
List<Value> parameters = ((Function) value_not).parameters();
|
52 |
Value value_is = parameters.get(0);
|
53 |
List<Value> parameters_is = ((Function)value_is).parameters();
|
54 |
Value is_p1 = parameters_is.get(0);
|
55 |
String r = MessageFormat.format( |
56 |
"( ({0}) IS NOT NULL )",
|
57 |
is_p1.toString(formatter) |
58 |
); |
59 |
return r;
|
60 |
} |
61 |
|
62 |
} |