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