gvsig-oracle / org.gvsig.oracle / trunk / org.gvsig.oracle / org.gvsig.oracle.provider / src / main / java / org / gvsig / oracle / dal / expressionbuilderformatter / OracleConstant.java @ 914
History | View | Annotate | Download (2.85 KB)
1 | 161 | omartinez | /*
|
---|---|---|---|
2 | * To change this license header, choose License Headers in Project Properties.
|
||
3 | * To change this template file, choose Tools | Templates
|
||
4 | * and open the template in the editor.
|
||
5 | */
|
||
6 | package org.gvsig.oracle.dal.expressionbuilderformatter; |
||
7 | |||
8 | import java.text.MessageFormat; |
||
9 | import org.gvsig.expressionevaluator.ExpressionBuilder; |
||
10 | 166 | omartinez | import org.gvsig.expressionevaluator.ExpressionBuilder.Constant; |
11 | 161 | omartinez | import org.gvsig.expressionevaluator.Formatter; |
12 | 179 | fdiaz | import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
13 | 161 | omartinez | import org.gvsig.fmap.dal.SQLBuilder; |
14 | import org.gvsig.fmap.geom.Geometry; |
||
15 | import org.gvsig.oracle.dal.OracleSQLBuilder; |
||
16 | |||
17 | /**
|
||
18 | *
|
||
19 | * @author osc
|
||
20 | */
|
||
21 | 166 | omartinez | public class OracleConstant implements Formatter<ExpressionBuilder.Value> { |
22 | 161 | omartinez | |
23 | private final Formatter<ExpressionBuilder.Value> formatter; |
||
24 | private final OracleSQLBuilder builder; |
||
25 | 179 | fdiaz | private final GeometryExpressionBuilder expbuilder; |
26 | |||
27 | 166 | omartinez | public OracleConstant(SQLBuilder builder, Formatter<ExpressionBuilder.Value> formatter) { |
28 | 161 | omartinez | this.builder = (OracleSQLBuilder) builder;
|
29 | this.formatter = formatter;
|
||
30 | this.expbuilder = builder.expression();
|
||
31 | } |
||
32 | |||
33 | @Override
|
||
34 | public boolean canApply(ExpressionBuilder.Value value) { |
||
35 | 179 | fdiaz | return value instanceof ExpressionBuilder.Constant; |
36 | 161 | omartinez | } |
37 | |||
38 | @Override
|
||
39 | public String format(ExpressionBuilder.Value function) { |
||
40 | 166 | omartinez | Object value = ((Constant) function).value();
|
41 | 914 | jjdelcerro | if( value instanceof Boolean ) { |
42 | if( (Boolean)value ) { |
||
43 | return "(1=1)"; |
||
44 | } |
||
45 | return "(1<>1)"; |
||
46 | } else if (value instanceof Geometry) { |
||
47 | 179 | fdiaz | Geometry geom = (Geometry) value; //function;
|
48 | 166 | omartinez | try {
|
49 | switch (this.builder.geometry_support_type()) { |
||
50 | case EWKB:
|
||
51 | 179 | fdiaz | return MessageFormat.format(OracleSQLBuilder.ST_GEOMFROMEWKB, |
52 | 166 | omartinez | this.builder.blob(geom.convertToEWKB()),
|
53 | String.valueOf(this.expbuilder.srs_id(geom.getProjection())) //TODO projection from ? |
||
54 | ); |
||
55 | case WKB:
|
||
56 | 179 | fdiaz | return MessageFormat.format(OracleSQLBuilder.ST_GEOMFROMWKB, |
57 | 166 | omartinez | this.builder.blob(geom.convertToWKB()),
|
58 | String.valueOf(this.expbuilder.srs_id(geom.getProjection())) |
||
59 | ); |
||
60 | case WKT:
|
||
61 | default:
|
||
62 | 179 | fdiaz | return MessageFormat.format(OracleSQLBuilder.ST_GEOMFROMTEXT, |
63 | 166 | omartinez | geom.convertToWKT(), |
64 | String.valueOf(this.expbuilder.srs_id(geom.getProjection())) |
||
65 | ); |
||
66 | } |
||
67 | } catch (Exception ex) { |
||
68 | throw new RuntimeException("Can't convert geometry to string.", ex); |
||
69 | 161 | omartinez | } |
70 | } |
||
71 | 179 | fdiaz | return function.toString(null); |
72 | 161 | omartinez | } |
73 | } |