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 @ 46517
History | View | Annotate | Download (1.6 KB)
1 |
package org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters; |
---|---|
2 |
|
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 |
public class ToDouble implements Formatter<Value> { |
17 |
|
18 |
private final Formatter<Value> formatter; |
19 |
private final SQLBuilder builder; |
20 |
|
21 |
public ToDouble(SQLBuilder builder, Formatter<Value> formatter) { |
22 |
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 |
return StringUtils.equalsIgnoreCase(ExpressionBuilder.FUNCTION_TODOUBLE, ((Function) value).name());
|
31 |
} |
32 |
} |
33 |
return false; |
34 |
} |
35 |
|
36 |
@Override
|
37 |
public String format(Value function) { |
38 |
List<Value> parameters = ((Function) function).parameters();
|
39 |
String p1 = parameters.get(0).toString(formatter); |
40 |
|
41 |
String r = MessageFormat.format( |
42 |
"CAST ( {0} AS DECIMAL )",
|
43 |
p1 |
44 |
); |
45 |
// 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 |
return r;
|
48 |
} |
49 |
|
50 |
} |