svn-gvsig-desktop / trunk / extensions / extOracleSpatial / src / es / prodevelop / cit / gvsig / fmap / drivers / jdbc / oracle / OracleSpatialFeatureIterator.java @ 14291
History | View | Annotate | Download (5.34 KB)
1 |
/* 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 java.sql.ResultSet; |
46 |
import java.sql.SQLException; |
47 |
import java.sql.Statement; |
48 |
|
49 |
import oracle.sql.ROWID; |
50 |
import oracle.sql.STRUCT; |
51 |
|
52 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
53 |
import com.hardcode.gdbms.engine.values.Value; |
54 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
55 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
56 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
57 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
58 |
|
59 |
|
60 |
/**
|
61 |
* Oracle feature iterator. An instance of this class is returned whaen gvSIG
|
62 |
* asks for a feature iterator for a new viewport.
|
63 |
*
|
64 |
* @author jldominguez
|
65 |
*
|
66 |
*/
|
67 |
public class OracleSpatialFeatureIterator implements IFeatureIterator { |
68 |
private OracleSpatialDriver driver;
|
69 |
private ResultSet rs = null; |
70 |
private int oneBasedGeoColInd = 0; |
71 |
private boolean useGeotools = false; |
72 |
private Statement st; |
73 |
|
74 |
/**
|
75 |
* Constructor.
|
76 |
*
|
77 |
* @param parent the driver that creates it
|
78 |
* @param _rs the result set to be iterated (already computed by the driver)
|
79 |
* @param _st the statement that generated the result set. The iterator will close it.
|
80 |
* @param geoColIndex index of the geometry field
|
81 |
* @param _useGeotools a switch to decide if the geotools classes
|
82 |
* must be used to deal with geometris
|
83 |
*/
|
84 |
public OracleSpatialFeatureIterator(OracleSpatialDriver parent,
|
85 |
ResultSet _rs, Statement _st, int geoColIndex, boolean _useGeotools) { |
86 |
driver = parent; |
87 |
rs = _rs; |
88 |
st = _st; |
89 |
useGeotools = _useGeotools; |
90 |
oneBasedGeoColInd = geoColIndex; |
91 |
} |
92 |
|
93 |
public boolean hasNext() throws ReadDriverException { |
94 |
if (rs == null) { |
95 |
return false; |
96 |
} |
97 |
|
98 |
try {
|
99 |
boolean _resp = rs.next();
|
100 |
|
101 |
if (!_resp) {
|
102 |
rs.close(); |
103 |
st.close(); |
104 |
} |
105 |
|
106 |
return _resp;
|
107 |
} catch (SQLException se) { |
108 |
throw new ReadDriverException(driver.getName(), se); |
109 |
} |
110 |
} |
111 |
|
112 |
public IFeature next() throws ReadDriverException { |
113 |
if (rs == null) { |
114 |
return null; |
115 |
} |
116 |
|
117 |
IFeature ife = null;
|
118 |
|
119 |
try {
|
120 |
ROWID ri = (ROWID) rs.getObject(1);
|
121 |
Value[] atts = driver.getAttributes(rs);
|
122 |
String gid = ri.stringValue();
|
123 |
STRUCT _st = (oracle.sql.STRUCT) rs.getObject(oneBasedGeoColInd); |
124 |
IGeometry theGeom = driver.getGeometryUsing(_st, useGeotools); |
125 |
ife = new DefaultFeature(theGeom, atts, gid);
|
126 |
} |
127 |
catch (SQLException se) { |
128 |
throw new ReadDriverException(driver.getName(), se); |
129 |
} |
130 |
|
131 |
return ife;
|
132 |
} |
133 |
|
134 |
public void closeIterator() throws ReadDriverException { |
135 |
try {
|
136 |
rs.close(); |
137 |
st.close(); |
138 |
} |
139 |
catch (SQLException se) { |
140 |
throw new ReadDriverException(driver.getName(), se); |
141 |
} |
142 |
} |
143 |
|
144 |
/**
|
145 |
* Utility method to get the oracle geometry type as a human-readable String.
|
146 |
*
|
147 |
* @param type the oracle geometry type
|
148 |
* @return a human-readable String describing it.
|
149 |
*/
|
150 |
public static String getJGeometryTypeName(int type) { |
151 |
String resp = "Unknown JGeometry type (" + type + ")"; |
152 |
|
153 |
switch (type) {
|
154 |
case OracleSpatialDriver.JGeometry_GTYPE_COLLECTION:
|
155 |
resp = "Collection";
|
156 |
|
157 |
break;
|
158 |
|
159 |
case OracleSpatialDriver.JGeometry_GTYPE_CURVE:
|
160 |
resp = "Curve";
|
161 |
|
162 |
break;
|
163 |
|
164 |
case OracleSpatialDriver.JGeometry_GTYPE_MULTICURVE:
|
165 |
resp = "Multi-curve";
|
166 |
|
167 |
break;
|
168 |
|
169 |
case OracleSpatialDriver.JGeometry_GTYPE_MULTIPOINT:
|
170 |
resp = "Multi-point";
|
171 |
|
172 |
break;
|
173 |
|
174 |
case OracleSpatialDriver.JGeometry_GTYPE_MULTIPOLYGON:
|
175 |
resp = "Multi-polygon";
|
176 |
|
177 |
break;
|
178 |
|
179 |
case OracleSpatialDriver.JGeometry_GTYPE_POINT:
|
180 |
resp = "Point";
|
181 |
|
182 |
break;
|
183 |
|
184 |
case OracleSpatialDriver.JGeometry_GTYPE_POLYGON:
|
185 |
resp = "Polygon";
|
186 |
|
187 |
break;
|
188 |
} |
189 |
|
190 |
return resp;
|
191 |
} |
192 |
} |