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 / Exists.java @ 46104
History | View | Annotate | Download (1.25 KB)
1 |
package org.gvsig.fmap.dal.store.h2.expressionbuilderformatter; |
---|---|
2 |
|
3 |
import org.apache.commons.lang3.StringUtils; |
4 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
5 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
6 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
7 |
import org.gvsig.expressionevaluator.Formatter; |
8 |
import static org.gvsig.fmap.dal.DataManager.FUNCTION_EXISTS; |
9 |
import org.gvsig.fmap.dal.SQLBuilder; |
10 |
|
11 |
/**
|
12 |
*
|
13 |
* @author jjdelcerro
|
14 |
*/
|
15 |
public class Exists implements Formatter<Value> { |
16 |
|
17 |
private final SQLBuilder sqlbuilder; |
18 |
private final Formatter<Value> formatter; |
19 |
|
20 |
public Exists(SQLBuilder sqlbuilder, Formatter<Value> formatter) { |
21 |
this.sqlbuilder = sqlbuilder;
|
22 |
this.formatter = formatter;
|
23 |
} |
24 |
@Override
|
25 |
public boolean canApply(ExpressionBuilder.Value value) { |
26 |
if (value instanceof ExpressionBuilder.Function) { |
27 |
return StringUtils.equalsIgnoreCase(FUNCTION_EXISTS, ((Function) value).name());
|
28 |
} |
29 |
return false; |
30 |
} |
31 |
|
32 |
@Override
|
33 |
public String format(Value function0) { |
34 |
Function function = (Function) function0; |
35 |
Value exp = function.parameters().get(0);
|
36 |
return "NVL2(COALESCE("+exp.toString(formatter)+"),TRUE,FALSE)"; |
37 |
} |
38 |
|
39 |
} |