svn-gvsig-desktop / branches / v10 / extensions / extOracleSpatial / src / es / prodevelop / cit / gvsig / fmap / drivers / jdbc / oracle / OracleSpatialFeatureIterator.java @ 14053
History | View | Annotate | Download (5.46 KB)
1 | 13991 | jldominguez@prodevelop.es | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * Prodevelop Integraci?n de Tecnolog?as SL
|
||
34 | * Conde Salvatierra de ?lava , 34-10
|
||
35 | * 46004 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963 510 612
|
||
39 | * +34 963 510 968
|
||
40 | * gis@prodevelop.es
|
||
41 | * http://www.prodevelop.es
|
||
42 | */
|
||
43 | package es.prodevelop.cit.gvsig.fmap.drivers.jdbc.oracle; |
||
44 | |||
45 | import com.hardcode.gdbms.engine.values.Value; |
||
46 | |||
47 | import com.iver.cit.gvsig.fmap.DriverException; |
||
48 | import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
||
49 | import com.iver.cit.gvsig.fmap.core.IFeature; |
||
50 | import com.iver.cit.gvsig.fmap.core.IGeometry; |
||
51 | import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
||
52 | |||
53 | 14011 | jldominguez@prodevelop.es | // import oracle.spatial.geometry.JGeometry;
|
54 | 13991 | jldominguez@prodevelop.es | |
55 | import oracle.sql.ROWID; |
||
56 | import oracle.sql.STRUCT; |
||
57 | |||
58 | import java.sql.ResultSet; |
||
59 | import java.sql.SQLException; |
||
60 | import java.sql.Statement; |
||
61 | |||
62 | |||
63 | /**
|
||
64 | * Oracle feature iterator. An instance of this class is returned whaen gvSIG
|
||
65 | * asks for a feature iterator for a new viewport.
|
||
66 | *
|
||
67 | * @author jldominguez
|
||
68 | *
|
||
69 | */
|
||
70 | public class OracleSpatialFeatureIterator implements IFeatureIterator { |
||
71 | private OracleSpatialDriver driver;
|
||
72 | private ResultSet rs = null; |
||
73 | private int oneBasedGeoColInd = 0; |
||
74 | private boolean useGeotools = false; |
||
75 | private Statement st; |
||
76 | |||
77 | /**
|
||
78 | * Constructor.
|
||
79 | *
|
||
80 | * @param parent the driver that creates it
|
||
81 | * @param _rs the result set to be iterated (already computed by the driver)
|
||
82 | * @param _st the statement that generated the result set. The iterator will close it.
|
||
83 | * @param geoColIndex index of the geometry field
|
||
84 | * @param _useGeotools a switch to decide if the geotools classes
|
||
85 | * must be used to deal with geometris
|
||
86 | */
|
||
87 | public OracleSpatialFeatureIterator(OracleSpatialDriver parent,
|
||
88 | ResultSet _rs, Statement _st, int geoColIndex, boolean _useGeotools) { |
||
89 | driver = parent; |
||
90 | rs = _rs; |
||
91 | st = _st; |
||
92 | useGeotools = _useGeotools; |
||
93 | oneBasedGeoColInd = geoColIndex; |
||
94 | } |
||
95 | |||
96 | public boolean hasNext() throws DriverException { |
||
97 | if (rs == null) { |
||
98 | return false; |
||
99 | } |
||
100 | |||
101 | try {
|
||
102 | boolean _resp = rs.next();
|
||
103 | |||
104 | if (!_resp) {
|
||
105 | rs.close(); |
||
106 | st.close(); |
||
107 | } |
||
108 | |||
109 | return _resp;
|
||
110 | } |
||
111 | catch (SQLException se) { |
||
112 | System.err.println("Error while doing hasNext(): " + |
||
113 | se.getMessage()); |
||
114 | } |
||
115 | |||
116 | return false; |
||
117 | } |
||
118 | |||
119 | public IFeature next() throws DriverException { |
||
120 | if (rs == null) { |
||
121 | return null; |
||
122 | } |
||
123 | |||
124 | IFeature ife = null;
|
||
125 | |||
126 | try {
|
||
127 | ROWID ri = (ROWID) rs.getObject(1);
|
||
128 | Value[] atts = driver.getAttributes(rs);
|
||
129 | String gid = ri.stringValue();
|
||
130 | STRUCT _st = (oracle.sql.STRUCT) rs.getObject(oneBasedGeoColInd); |
||
131 | IGeometry theGeom = driver.getGeometryUsing(_st, useGeotools); |
||
132 | ife = new DefaultFeature(theGeom, atts, gid);
|
||
133 | } |
||
134 | catch (SQLException se) { |
||
135 | System.err.println("Error while doing next(): " + se.getMessage()); |
||
136 | } |
||
137 | |||
138 | return ife;
|
||
139 | } |
||
140 | |||
141 | public void closeIterator() throws DriverException { |
||
142 | try {
|
||
143 | rs.close(); |
||
144 | st.close(); |
||
145 | } |
||
146 | catch (SQLException se) { |
||
147 | throw new DriverException("SQL Exception: " + se.getMessage()); |
||
148 | } |
||
149 | } |
||
150 | |||
151 | /**
|
||
152 | * Utility method to get the oracle geometry type as a human-readable String.
|
||
153 | *
|
||
154 | * @param type the oracle geometry type
|
||
155 | * @return a human-readable String describing it.
|
||
156 | */
|
||
157 | public static String getJGeometryTypeName(int type) { |
||
158 | String resp = "Unknown JGeometry type (" + type + ")"; |
||
159 | |||
160 | switch (type) {
|
||
161 | 14011 | jldominguez@prodevelop.es | case OracleSpatialDriver.JGeometry_GTYPE_COLLECTION:
|
162 | 13991 | jldominguez@prodevelop.es | resp = "Collection";
|
163 | |||
164 | break;
|
||
165 | |||
166 | 14011 | jldominguez@prodevelop.es | case OracleSpatialDriver.JGeometry_GTYPE_CURVE:
|
167 | 13991 | jldominguez@prodevelop.es | resp = "Curve";
|
168 | |||
169 | break;
|
||
170 | |||
171 | 14011 | jldominguez@prodevelop.es | case OracleSpatialDriver.JGeometry_GTYPE_MULTICURVE:
|
172 | 13991 | jldominguez@prodevelop.es | resp = "Multi-curve";
|
173 | |||
174 | break;
|
||
175 | |||
176 | 14011 | jldominguez@prodevelop.es | case OracleSpatialDriver.JGeometry_GTYPE_MULTIPOINT:
|
177 | 13991 | jldominguez@prodevelop.es | resp = "Multi-point";
|
178 | |||
179 | break;
|
||
180 | |||
181 | 14011 | jldominguez@prodevelop.es | case OracleSpatialDriver.JGeometry_GTYPE_MULTIPOLYGON:
|
182 | 13991 | jldominguez@prodevelop.es | resp = "Multi-polygon";
|
183 | |||
184 | break;
|
||
185 | |||
186 | 14011 | jldominguez@prodevelop.es | case OracleSpatialDriver.JGeometry_GTYPE_POINT:
|
187 | 13991 | jldominguez@prodevelop.es | resp = "Point";
|
188 | |||
189 | break;
|
||
190 | |||
191 | 14011 | jldominguez@prodevelop.es | case OracleSpatialDriver.JGeometry_GTYPE_POLYGON:
|
192 | 13991 | jldominguez@prodevelop.es | resp = "Polygon";
|
193 | |||
194 | break;
|
||
195 | } |
||
196 | |||
197 | return resp;
|
||
198 | } |
||
199 | } |