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 / expressionbuilder / formatters / ToDouble.java @ 46104
History | View | Annotate | Download (1.6 KB)
1 | 45605 | omartinez | package org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters; |
---|---|---|---|
2 | 44198 | jjdelcerro | |
3 | import java.text.MessageFormat; |
||
4 | import java.util.List; |
||
5 | import org.apache.commons.lang3.StringUtils; |
||
6 | import org.gvsig.expressionevaluator.ExpressionBuilder; |
||
7 | import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
||
8 | import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
||
9 | import org.gvsig.expressionevaluator.Formatter; |
||
10 | import org.gvsig.fmap.dal.SQLBuilder; |
||
11 | |||
12 | /**
|
||
13 | *
|
||
14 | * @author jjdelcerro
|
||
15 | */
|
||
16 | 46104 | omartinez | public class ToDouble implements Formatter<Value> { |
17 | 44198 | jjdelcerro | |
18 | private final Formatter<Value> formatter; |
||
19 | private final SQLBuilder builder; |
||
20 | |||
21 | 46104 | omartinez | public ToDouble(SQLBuilder builder, Formatter<Value> formatter) { |
22 | 44198 | jjdelcerro | this.builder = builder;
|
23 | this.formatter = formatter;
|
||
24 | } |
||
25 | |||
26 | @Override
|
||
27 | public boolean canApply(Value value) { |
||
28 | if (value instanceof Function) { |
||
29 | if (value instanceof ExpressionBuilder.Function) { |
||
30 | 46104 | omartinez | return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_TODOUBLE, ((Function) value).name());
|
31 | 44198 | jjdelcerro | } |
32 | } |
||
33 | return false; |
||
34 | } |
||
35 | |||
36 | @Override
|
||
37 | public String format(Value function) { |
||
38 | 44750 | jjdelcerro | List<Value> parameters = ((Function) function).parameters();
|
39 | String p1 = parameters.get(0).toString(formatter); |
||
40 | 45183 | omartinez | |
41 | 44198 | jjdelcerro | String r = MessageFormat.format( |
42 | 46104 | omartinez | "CAST ( {0} AS DECIMAL )",
|
43 | p1 |
||
44 | 44198 | jjdelcerro | ); |
45 | 46104 | omartinez | // En oracle el format seria algo como esto:
|
46 | //(case when lower({0}) = 't' then 1 when lower({0}) = 'f' then 0 else cast({0} as decimal) end)
|
||
47 | 44198 | jjdelcerro | return r;
|
48 | } |
||
49 | |||
50 | } |