svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extOracleSpatial / src / org / gvsig / oraclespatial / driver / OracleSpatialDriver.java @ 29563
History | View | Annotate | Download (120 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 org.gvsig.oraclespatial.driver; |
44 |
|
45 |
import java.awt.Shape; |
46 |
import java.awt.geom.Point2D; |
47 |
import java.awt.geom.Rectangle2D; |
48 |
import java.math.BigDecimal; |
49 |
import java.sql.Connection; |
50 |
import java.sql.DatabaseMetaData; |
51 |
import java.sql.PreparedStatement; |
52 |
import java.sql.ResultSet; |
53 |
import java.sql.ResultSetMetaData; |
54 |
import java.sql.SQLException; |
55 |
import java.sql.Statement; |
56 |
import java.sql.Timestamp; |
57 |
import java.sql.Types; |
58 |
import java.util.ArrayList; |
59 |
import java.util.HashMap; |
60 |
import java.util.Hashtable; |
61 |
import java.util.Iterator; |
62 |
import java.util.Random; |
63 |
import java.util.TreeMap; |
64 |
|
65 |
import oracle.sql.ARRAY; |
66 |
import oracle.sql.Datum; |
67 |
import oracle.sql.NUMBER; |
68 |
import oracle.sql.ROWID; |
69 |
import oracle.sql.STRUCT; |
70 |
import oracle.sql.StructDescriptor; |
71 |
import oracle.sql.TIMESTAMP; |
72 |
|
73 |
|
74 |
import org.cresques.cts.ICoordTrans; |
75 |
import org.cresques.cts.IProjection; |
76 |
import org.gvsig.oraclespatial.utils.OracleSpatialUtils; |
77 |
import org.slf4j.Logger; |
78 |
import org.slf4j.LoggerFactory; |
79 |
|
80 |
import com.iver.utiles.NumberUtilities; |
81 |
import com.iver.utiles.XMLEntity; |
82 |
import com.vividsolutions.jts.algorithm.CGAlgorithms; |
83 |
import com.vividsolutions.jts.geom.Coordinate; |
84 |
import com.vividsolutions.jts.geom.Geometry; |
85 |
import com.vividsolutions.jts.geom.GeometryFactory; |
86 |
import com.vividsolutions.jts.geom.LineString; |
87 |
import com.vividsolutions.jts.geom.LinearRing; |
88 |
import com.vividsolutions.jts.geom.MultiPolygon; |
89 |
import com.vividsolutions.jts.geom.Polygon; |
90 |
import com.vividsolutions.jts.geom.impl.CoordinateArraySequence; |
91 |
|
92 |
|
93 |
|
94 |
/**
|
95 |
* Vectorial driver to access Oracle databases geometries
|
96 |
* Should work on Oracle Locator.
|
97 |
*
|
98 |
* It contains switches to test different modules to perform the
|
99 |
* translation oracle structs --> gvsig geometries:
|
100 |
*
|
101 |
* - Parsing the structs directly.
|
102 |
* - Using Oracle's JGeometry static methods
|
103 |
* - Using Geotools utilities
|
104 |
*
|
105 |
* (currently, the driver parses the structs directly)
|
106 |
*
|
107 |
* @author jldominguez
|
108 |
*
|
109 |
*/
|
110 |
public class OracleSpatialDriver { |
111 |
|
112 |
// public class OracleSpatialDriver extends DefaultJDBCDriver
|
113 |
// implements IDelayedDriver, ICanReproject, IWriteable {
|
114 |
// private static Logger logger = LoggerFactory.getLogger(OracleSpatialDriver.class.getName());
|
115 |
// private static int FETCH_SIZE = 15000;
|
116 |
//
|
117 |
// // constants
|
118 |
// public static final int GEODETIC_FULLEXTENT_SAMPLE_SIZE = 50;
|
119 |
// public static final String GEODETIC_SRID = "8307";
|
120 |
// // public static final String ASSUMED_ORACLE_SRID = "8307";
|
121 |
//
|
122 |
// // ------------------------------------------------
|
123 |
// public static final String NAME = "Oracle Spatial Database Driver";
|
124 |
// public static final int ID_COLUMN_INDEX = 1;
|
125 |
//
|
126 |
// public static final String ALL_ORACLE_GEOMETADATA_VIEW = "ALL_SDO_GEOM_METADATA";
|
127 |
// public static final String USER_ORACLE_GEOMETADATA_VIEW = "USER_SDO_GEOM_METADATA";
|
128 |
//
|
129 |
// public static final String ORACLE_EPSG_TABLE_NAME = "ORA_EPSG";
|
130 |
// public static final String ORACLE_EPSG_FILE_NAME = "ORA_EPSG.DBF";
|
131 |
// public static final String DEFAULT_GEO_FIELD = "GEOMETRY";
|
132 |
// // public static final String DEFAULT_GEO_FIELD = "MERGEDGEOMETRY";
|
133 |
//
|
134 |
// public static final String ORACLE_ID_FIELD = "ROWID";
|
135 |
// public static final String DEFAULT_ID_FIELD_CASE_SENSITIVE = "GID";
|
136 |
// public static final String ORACLE_GEO_SCHEMA = "MDSYS";
|
137 |
// public static final String CONN_STR_BEGIN = "jdbc:oracle:thin:";
|
138 |
//
|
139 |
// public static final int VARCHAR2_STANDARD_SIZE = 80;
|
140 |
// public static final int VARCHAR2_LONG_SIZE = 256;
|
141 |
// public static final int MAX_ID_LENGTH = 30;
|
142 |
// private final static GeometryFactory geomFactory = new GeometryFactory();
|
143 |
// public static final double IRRELEVANT_DISTANCE = 0.00000001;
|
144 |
// private static final long ID_MIN_DELAY = 1000;
|
145 |
//
|
146 |
// public static final String ORACLE_JAR_FILE_NAME = "oracle.jdbc.driver.OracleDriver";
|
147 |
//
|
148 |
// static {
|
149 |
// try {
|
150 |
// Class.forName(ORACLE_JAR_FILE_NAME);
|
151 |
// }
|
152 |
// catch (ClassNotFoundException e) {
|
153 |
// throw new RuntimeException(e);
|
154 |
// }
|
155 |
// }
|
156 |
//
|
157 |
// private OracleSpatialWriter writer = null;
|
158 |
//
|
159 |
// // switch variable
|
160 |
// private boolean use_geotools = false;
|
161 |
// private boolean tableHasSrid = true;
|
162 |
//
|
163 |
// // ------------------------------------------------
|
164 |
// private boolean isNotAvailableYet = true;
|
165 |
// private Value nullVal = ValueFactory.createNullValue();
|
166 |
// private IdLoaderThread idLoader;
|
167 |
// private DriverAttributes drvAtts;
|
168 |
// private int[] pkOneBasedIndexes;
|
169 |
// private String[] fieldNames;
|
170 |
// private String not_restricted_sql = "";
|
171 |
//
|
172 |
// private Rectangle2D workingAreaInViewsCS = null;
|
173 |
// private Rectangle2D workingAreaInTablesCS = null;
|
174 |
// private STRUCT workingAreaInTablesCSStruct = null;
|
175 |
//
|
176 |
// private String idFieldNames;
|
177 |
// private int oneBasedGeoColInd = 0;
|
178 |
// private int shapeType = -1;
|
179 |
// private boolean needsCollectionLayer = true;
|
180 |
//
|
181 |
// // ----------------------------------------------
|
182 |
// // one feature is cached to avoid querying for each attribute request:
|
183 |
// private IFeature singleCachedFeature = null;
|
184 |
// private long singleCachedFeatureRowNum = -1;
|
185 |
//
|
186 |
// // ----------------------------------------------
|
187 |
// private boolean cancelIDLoad = false;
|
188 |
//
|
189 |
// // ----------------------------------------------
|
190 |
// private String fullTableName = "";
|
191 |
// private String geoColName = "";
|
192 |
// private String oracleSRID;
|
193 |
// private String epsgSRID;
|
194 |
// private String destProj = "";
|
195 |
// private Rectangle2D full_Extent = null;
|
196 |
// private boolean emptyWhereClause = true;
|
197 |
// private boolean isGeogCS = false;
|
198 |
// private boolean hasRealiableExtent = true;
|
199 |
//
|
200 |
// // new hash map to perform queries by row number:
|
201 |
// private HashMap rowToId = new HashMap();
|
202 |
// private String destProjOracle;
|
203 |
// private boolean isDestGeogCS = false;
|
204 |
//
|
205 |
// public OracleSpatialDriver() {
|
206 |
// drvAtts = new DriverAttributes();
|
207 |
// drvAtts.setLoadedInMemory(false);
|
208 |
// }
|
209 |
//
|
210 |
// public String getWhereClause() {
|
211 |
// return lyrDef.getWhereClause();
|
212 |
// }
|
213 |
//
|
214 |
//
|
215 |
// /**
|
216 |
// * This method is called when the user creates a new oracle
|
217 |
// * table from a vectorial layer
|
218 |
// *
|
219 |
// * @param params this array simply contains the parameters <tt>Connection</tt> and
|
220 |
// * <tt>DBLayerDefinition</tt>
|
221 |
// */
|
222 |
// public void setData(Object[] params) {
|
223 |
// setData((IConnection) params[0], (DBLayerDefinition) params[1]);
|
224 |
// }
|
225 |
//
|
226 |
// private void adjustLyrDef() throws SQLException {
|
227 |
// DBLayerDefinition ldef = getLyrDef();
|
228 |
// int cnt = metaData.getColumnCount();
|
229 |
//
|
230 |
// FieldDescription[] _new = new FieldDescription[cnt];
|
231 |
//
|
232 |
// for (int i = 0; i < cnt; i++) {
|
233 |
// _new[i] = new FieldDescription();
|
234 |
// _new[i].setFieldName(metaData.getColumnName(i + 1));
|
235 |
// _new[i].setDefaultValue(ValueFactory.createNullValue());
|
236 |
// _new[i].setFieldAlias(_new[i].getFieldName());
|
237 |
// _new[i].setFieldLength(getFieldWidth(i));
|
238 |
//
|
239 |
// int _type = metaData.getColumnType(i + 1);
|
240 |
// _new[i].setFieldType(_type);
|
241 |
//
|
242 |
// if ((_type == Types.FLOAT) || (_type == Types.DOUBLE) ||
|
243 |
// (_type == Types.DECIMAL) || (_type == Types.REAL)) {
|
244 |
// _new[i].setFieldDecimalCount(6);
|
245 |
// }
|
246 |
// else {
|
247 |
// _new[i].setFieldDecimalCount(0);
|
248 |
// }
|
249 |
// }
|
250 |
//
|
251 |
// ldef.setFieldsDesc(_new);
|
252 |
// setLyrDef(ldef);
|
253 |
// }
|
254 |
//
|
255 |
// /**
|
256 |
// * Standard initializing method.
|
257 |
// */
|
258 |
// public void setData(IConnection _conn, DBLayerDefinition lyrDef) {
|
259 |
// conn = _conn;
|
260 |
//
|
261 |
// // This metadata is required to store layer in GVP
|
262 |
// // without problems:
|
263 |
// ConnectionWithParams _cwp =
|
264 |
// SingleVectorialDBConnectionManager.instance().findConnection(conn);
|
265 |
// host = _cwp.getHost();
|
266 |
// port = _cwp.getPort();
|
267 |
// dbName = _cwp.getDb();
|
268 |
// connName = _cwp.getName();
|
269 |
//
|
270 |
// try {
|
271 |
// if (conn.isClosed()) {
|
272 |
// SingleVectorialDBConnectionManager.instance().closeAndRemove(_cwp);
|
273 |
// _cwp = SingleVectorialDBConnectionManager.instance().getConnection(
|
274 |
// _cwp.getDrvName(),
|
275 |
// _cwp.getUser(),
|
276 |
// _cwp.getPw(),
|
277 |
// _cwp.getName(),
|
278 |
// _cwp.getHost(),
|
279 |
// _cwp.getPort(),
|
280 |
// _cwp.getDb(), true);
|
281 |
// }
|
282 |
// } catch (DBException e1) {
|
283 |
// logger.error("While trying to reconnect: " + e1.getMessage());
|
284 |
// logger.error("Layer will not be reloaded!");
|
285 |
// }
|
286 |
//
|
287 |
// // ------------------
|
288 |
//
|
289 |
// OracleSpatialUtils.setUpperCase(lyrDef);
|
290 |
// lyrDef.setConnection(conn);
|
291 |
//
|
292 |
// String geo_can[];
|
293 |
// try {
|
294 |
// geo_can = getGeometryFieldsCandidates(conn, lyrDef.getTableName());
|
295 |
// OracleSpatialUtils.removeStructFields(lyrDef, geo_can);
|
296 |
// } catch (DBException e) {
|
297 |
// logger.error("While removing STRUCT fields: " + e.getMessage());
|
298 |
// }
|
299 |
//
|
300 |
// setLyrDef(lyrDef);
|
301 |
//
|
302 |
// geoColName = lyrDef.getFieldGeometry();
|
303 |
//
|
304 |
// String tn = lyrDef.getTableName();
|
305 |
//
|
306 |
// if (tn.indexOf(".") == -1) {
|
307 |
//
|
308 |
// if (lyrDef.getSchema() == null) {
|
309 |
// fullTableName = _cwp.getUser().toUpperCase() + "." + tn;
|
310 |
// } else {
|
311 |
// fullTableName = lyrDef.getSchema() + "." + tn;
|
312 |
// }
|
313 |
//
|
314 |
//
|
315 |
// } else {
|
316 |
// fullTableName = tn;
|
317 |
// }
|
318 |
//
|
319 |
// not_restricted_sql = "select " + getStandardSelectExpression() +
|
320 |
// " from " + getTableName() + " c ";
|
321 |
//
|
322 |
// // various metadata settings
|
323 |
// // getMetaDataInThisThread();
|
324 |
// cleanWhereClause();
|
325 |
// loadSdoMetadata();
|
326 |
// oneRowMetadata();
|
327 |
//
|
328 |
// setDestProjection(lyrDef.getSRID_EPSG());
|
329 |
// workingAreaInViewsCS = lyrDef.getWorkingArea();
|
330 |
//
|
331 |
// if ((workingAreaInViewsCS != null) && (epsgSRID != null)) {
|
332 |
// IProjection viewProj = CRSFactory.getCRS("EPSG:" + destProj);
|
333 |
// IProjection tableProj = CRSFactory.getCRS("EPSG:" + epsgSRID);
|
334 |
// ICoordTrans reprojecter = viewProj.getCT(tableProj);
|
335 |
// workingAreaInTablesCS = reprojecter.convert(workingAreaInViewsCS);
|
336 |
// workingAreaInTablesCSStruct = shapeToStruct(workingAreaInTablesCS,
|
337 |
// FShape.NULL, tableHasSrid, false, true);
|
338 |
// }
|
339 |
//
|
340 |
// cancelIDLoad = false;
|
341 |
// idLoader = new IdLoaderThread(this);
|
342 |
// idLoader.start();
|
343 |
// }
|
344 |
//
|
345 |
//
|
346 |
//
|
347 |
//
|
348 |
// /**
|
349 |
// * Utility method to load IDs in a different thred, so that gvsig's gui
|
350 |
// * does not get blocked.
|
351 |
// *
|
352 |
// */
|
353 |
// public void getMetaDataInThisThread() {
|
354 |
// getMetadata();
|
355 |
// }
|
356 |
//
|
357 |
// private void getMetadata() {
|
358 |
//
|
359 |
// long id_load_start = System.currentTimeMillis();
|
360 |
// setIdRowTable();
|
361 |
// long id_load_end = System.currentTimeMillis();
|
362 |
//
|
363 |
// long delay = id_load_end - id_load_start;
|
364 |
// if (delay < ID_MIN_DELAY) {
|
365 |
// logger.info("Ids thread delayed by: " + (ID_MIN_DELAY - delay) + " ms.");
|
366 |
// try {
|
367 |
// Thread.sleep(ID_MIN_DELAY - delay);
|
368 |
// } catch (InterruptedException e) {
|
369 |
// logger.error("While delaying ids thread: " + e.getMessage());
|
370 |
// }
|
371 |
// }
|
372 |
//
|
373 |
// if (!hasRealiableExtent) {
|
374 |
// full_Extent = getEstimatedExtent(
|
375 |
// getTableName(), geoColName, conn, 20, 1.5, isGeogCS);
|
376 |
// }
|
377 |
//
|
378 |
// if (cancelIDLoad) {
|
379 |
// return;
|
380 |
// }
|
381 |
// }
|
382 |
//
|
383 |
// private String getOracleSridFromCurrentRecord(ResultSet _rs)
|
384 |
// throws SQLException {
|
385 |
// Object obj = _rs.getObject("SRID");
|
386 |
//
|
387 |
// if (obj == null) {
|
388 |
// logger.warn("No SRID found for this table.");
|
389 |
// tableHasSrid = false;
|
390 |
//
|
391 |
// return null;
|
392 |
// }
|
393 |
//
|
394 |
// return obj.toString();
|
395 |
// }
|
396 |
//
|
397 |
// private Rectangle2D getFullExtentFromCurrentRecord(ResultSet _rs)
|
398 |
// throws SQLException {
|
399 |
// ARRAY dim_info_array = (ARRAY) _rs.getObject("DIMINFO");
|
400 |
//
|
401 |
// if (dim_info_array == null) {
|
402 |
// // no full extent found:
|
403 |
// return null;
|
404 |
// }
|
405 |
// else {
|
406 |
// Datum[] da = dim_info_array.getOracleArray();
|
407 |
//
|
408 |
// STRUCT sx = (STRUCT) da[0];
|
409 |
// STRUCT sy = (STRUCT) da[1];
|
410 |
//
|
411 |
// try {
|
412 |
// double minx = Double.parseDouble(sx.getAttributes()[1].toString());
|
413 |
// double maxx = Double.parseDouble(sx.getAttributes()[2].toString());
|
414 |
// double miny = Double.parseDouble(sy.getAttributes()[1].toString());
|
415 |
// double maxy = Double.parseDouble(sy.getAttributes()[2].toString());
|
416 |
//
|
417 |
// if (minx > maxx) {
|
418 |
// double aux = minx;
|
419 |
// minx = maxx;
|
420 |
// maxx = aux;
|
421 |
// }
|
422 |
//
|
423 |
// if (miny > maxy) {
|
424 |
// double aux = miny;
|
425 |
// miny = maxy;
|
426 |
// maxy = aux;
|
427 |
// }
|
428 |
//
|
429 |
// return getRectangle(minx, maxx, miny, maxy);
|
430 |
//
|
431 |
// // fullExtentJTS = shapeToGeometry(fullExtent);
|
432 |
// }
|
433 |
// catch (Exception ex) {
|
434 |
// logger.error("While getting full extent from metadata table.");
|
435 |
// return null;
|
436 |
// }
|
437 |
// }
|
438 |
// }
|
439 |
//
|
440 |
// private void loadSdoMetadata() {
|
441 |
// try {
|
442 |
// Statement _st = ((ConnectionJDBC)conn).getConnection().createStatement();
|
443 |
// String[] tokens = getTableName().split("\\u002E", 2);
|
444 |
// String qry;
|
445 |
// if (tokens.length > 1)
|
446 |
// {
|
447 |
// qry = "select * from " + ALL_ORACLE_GEOMETADATA_VIEW +
|
448 |
// " where OWNER = '" + tokens[0] + "' AND TABLE_NAME = '" +
|
449 |
// tokens[1] + "' AND COLUMN_NAME = '" + geoColName + "'";
|
450 |
// }
|
451 |
// else
|
452 |
// {
|
453 |
// qry = "select * from " + ALL_ORACLE_GEOMETADATA_VIEW +
|
454 |
// " where TABLE_NAME = " + "'" + getTableName()
|
455 |
// + "' AND COLUMN_NAME = '"
|
456 |
// + geoColName + "'";
|
457 |
//
|
458 |
// }
|
459 |
//
|
460 |
// ResultSet _rs = _st.executeQuery(qry);
|
461 |
//
|
462 |
// if (_rs.next()) {
|
463 |
// oracleSRID = getOracleSridFromCurrentRecord(_rs);
|
464 |
//
|
465 |
// isGeogCS = OracleSpatialUtils.getIsGCS(oracleSRID, tableHasSrid);
|
466 |
//
|
467 |
// try {
|
468 |
// epsgSRID = oracleSridToEpsgSrid(oracleSRID);
|
469 |
// } catch (Exception e) {
|
470 |
// logger.error("Unknown oracle SRID: " + oracleSRID);
|
471 |
// tableHasSrid = false;
|
472 |
// }
|
473 |
// full_Extent = getFullExtentFromCurrentRecord(_rs);
|
474 |
//
|
475 |
// hasRealiableExtent = realiableExtent(full_Extent, isGeogCS);
|
476 |
//
|
477 |
// if (!hasRealiableExtent) {
|
478 |
// full_Extent = getFastEstimatedExtent(
|
479 |
// getTableName(), geoColName, conn, 20, 10, isGeogCS);
|
480 |
// }
|
481 |
//
|
482 |
// _rs.close();
|
483 |
// _st.close();
|
484 |
// }
|
485 |
// else {
|
486 |
// throw new SQLException("Empty resultset from this query: " +
|
487 |
// qry);
|
488 |
// }
|
489 |
// }
|
490 |
// catch (SQLException se) {
|
491 |
// logger.error("While getting SDO metadata: " + se.getMessage());
|
492 |
// }
|
493 |
// }
|
494 |
//
|
495 |
// /**
|
496 |
// * Utility method to get a geometry from a struct.
|
497 |
// *
|
498 |
// * @param theStruct the struct to be converted
|
499 |
// * @param use_gtools switch to use geotools classes or not
|
500 |
// * @return the geometry
|
501 |
// * @throws SQLException
|
502 |
// */
|
503 |
// public IGeometry getGeometryUsing(STRUCT theStruct, boolean use_gtools)
|
504 |
// throws SQLException {
|
505 |
// IGeometry _igeom = null;
|
506 |
//
|
507 |
// if (theStruct == null) {
|
508 |
// return OracleSpatialUtils.NULL_GEOM;
|
509 |
// }
|
510 |
//
|
511 |
// if (use_gtools) { // geotools
|
512 |
//// _igeom = getGeotoolsIGeometry(theStruct);
|
513 |
// }
|
514 |
// else { // jgeometry
|
515 |
// _igeom = getFMapGeometry(theStruct, false);
|
516 |
// }
|
517 |
//
|
518 |
// return _igeom;
|
519 |
// }
|
520 |
//
|
521 |
// /**
|
522 |
// * Utility method to transform a struct into a IGeometry.
|
523 |
// *
|
524 |
// * @param st the struct to be converted
|
525 |
// * @param complex comes from a complex sdo geometry
|
526 |
// * @return the IGeometry
|
527 |
// */
|
528 |
// private IGeometry getFMapGeometry(STRUCT st, boolean complex) {
|
529 |
//
|
530 |
// if (st == null) {
|
531 |
// return new FNullGeometry();
|
532 |
// }
|
533 |
//
|
534 |
//
|
535 |
// Datum[] the_data = null;
|
536 |
//
|
537 |
// try {
|
538 |
// the_data = st.getOracleAttributes();
|
539 |
//
|
540 |
// int jgtype = ((NUMBER) the_data[0]).intValue() % 1000;
|
541 |
// jgtype = OracleSpatialUtils.oracleGTypeToFShapeType(jgtype, complex);
|
542 |
//
|
543 |
// int dim = ((NUMBER) the_data[0]).intValue() / 1000;
|
544 |
//
|
545 |
// if (dim < 2) {
|
546 |
// dim = 2;
|
547 |
// }
|
548 |
//
|
549 |
// IGeometry ig = null;
|
550 |
//
|
551 |
// if (OracleSpatialUtils.isActuallyACollection(the_data)) {
|
552 |
// jgtype = FShape.MULTI;
|
553 |
// }
|
554 |
//
|
555 |
// switch (jgtype) {
|
556 |
// case FShape.MULTI:
|
557 |
//
|
558 |
// // int srid = ((NUMBER) the_data[1]).intValue();
|
559 |
// ig = getFMapGeometryCollection(the_data, dim);
|
560 |
//
|
561 |
// break;
|
562 |
//
|
563 |
// case FShape.POINT:
|
564 |
// ig = OracleSpatialUtils.getFMapGeometryPoint(the_data, dim);
|
565 |
//
|
566 |
// break;
|
567 |
//
|
568 |
// case FShape.LINE:
|
569 |
// ig = OracleSpatialUtils.getFMapGeometryMultiLineString(the_data, dim);
|
570 |
//
|
571 |
// break;
|
572 |
//
|
573 |
// case FShape.POLYGON:
|
574 |
// ig = OracleSpatialUtils.getFMapGeometryMultipolygon(the_data, dim);
|
575 |
//
|
576 |
// break;
|
577 |
// }
|
578 |
//
|
579 |
// return ig;
|
580 |
// }
|
581 |
// catch (SQLException e) {
|
582 |
// logger.error(e);
|
583 |
// }
|
584 |
//
|
585 |
// return null;
|
586 |
// }
|
587 |
//
|
588 |
//
|
589 |
// private Rectangle2D getRectangle(double minx, double maxx, double miny,
|
590 |
// double maxy) {
|
591 |
// Rectangle2D resp = new Rectangle2D.Double(minx, miny, maxx - minx,
|
592 |
// maxy - miny);
|
593 |
// return resp;
|
594 |
// }
|
595 |
//
|
596 |
// private void oneRowMetadata() {
|
597 |
// try {
|
598 |
// String _sql = "select " + getStandardSelectExpression() + ", c." +
|
599 |
// geoColName + " from " + getTableName() + " c ";
|
600 |
//
|
601 |
// st = ((ConnectionJDBC)conn).getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
|
602 |
// ResultSet.CONCUR_READ_ONLY);
|
603 |
//
|
604 |
// ResultSet _rs = st.executeQuery(_sql + " where c." + geoColName + " is not NULL AND rownum = 1");
|
605 |
//
|
606 |
// if (_rs.next()) {
|
607 |
// STRUCT sample_geo = (STRUCT) _rs.getObject(geoColName);
|
608 |
// shapeType = OracleSpatialUtils.getShapeTypeOfStruct(sample_geo);
|
609 |
// }
|
610 |
// else {
|
611 |
// shapeType = FShape.MULTI;
|
612 |
// }
|
613 |
//
|
614 |
// // -----------------------
|
615 |
// _rs = st.executeQuery(not_restricted_sql + " where (rownum = 1)");
|
616 |
// metaData = _rs.getMetaData();
|
617 |
//
|
618 |
// userName = ((ConnectionJDBC)conn).getConnection().getMetaData().getUserName();
|
619 |
//
|
620 |
// // geoColInd = _rs.findColumn(geoColName);
|
621 |
// oneBasedGeoColInd = metaData.getColumnCount() + 1;
|
622 |
//
|
623 |
// DatabaseMetaData dbmd = ((ConnectionJDBC)conn).getConnection().getMetaData();
|
624 |
// pkOneBasedIndexes = getPKIndexes(dbmd, _rs);
|
625 |
//
|
626 |
// int cnt = metaData.getColumnCount();
|
627 |
// fieldNames = new String[cnt];
|
628 |
//
|
629 |
// for (int i = 0; i < cnt; i++) {
|
630 |
// fieldNames[i] = metaData.getColumnName(i + 1);
|
631 |
// }
|
632 |
//
|
633 |
// getIdFieldNames();
|
634 |
//
|
635 |
// adjustLyrDef();
|
636 |
//
|
637 |
// _rs.close(); // st no debe cerrarse ya que las llamadas a metadata lo encesitan
|
638 |
// }
|
639 |
// catch (SQLException se) {
|
640 |
// logger.error("While getting metadata. " + se.getMessage());
|
641 |
// }
|
642 |
// }
|
643 |
//
|
644 |
//
|
645 |
//
|
646 |
// private String getIdFieldNames() {
|
647 |
// try {
|
648 |
// idFieldNames = "";
|
649 |
//
|
650 |
// for (int i = 0; i < pkOneBasedIndexes.length; i++) {
|
651 |
// idFieldNames = idFieldNames +
|
652 |
// metaData.getColumnName(pkOneBasedIndexes[i]) + ", ";
|
653 |
// }
|
654 |
// }
|
655 |
// catch (SQLException se) {
|
656 |
// }
|
657 |
//
|
658 |
// idFieldNames = idFieldNames.substring(0, idFieldNames.length() - 2);
|
659 |
//
|
660 |
// return idFieldNames;
|
661 |
// }
|
662 |
//
|
663 |
// private int[] getPKIndexes(DatabaseMetaData metaData, ResultSet table_rs) {
|
664 |
// int[] _res = new int[1];
|
665 |
// _res[0] = 1;
|
666 |
//
|
667 |
// return _res;
|
668 |
// }
|
669 |
//
|
670 |
// public String getSqlTotal() {
|
671 |
// // TODO Auto-generated method stub
|
672 |
// return "";
|
673 |
// }
|
674 |
//
|
675 |
// public String getCompleteWhere() {
|
676 |
// // TODO Auto-generated method stub
|
677 |
// return "";
|
678 |
// }
|
679 |
//
|
680 |
// /**
|
681 |
// * Gets the feature iterator for a given SQL sentence (ignores previous filters
|
682 |
// * and uses directly that sentence to query the table).
|
683 |
// */
|
684 |
// public IFeatureIterator getFeatureIterator(String sql)
|
685 |
// throws ReadDriverException {
|
686 |
// if (isNotAvailableYet) {
|
687 |
// return new AnEmptyFeatureIterator();
|
688 |
// // return null;
|
689 |
// }
|
690 |
//
|
691 |
// singleCachedFeatureRowNum = -1;
|
692 |
//
|
693 |
// Object[] rs_st = getViewResultSet(null, sql, tableHasSrid);
|
694 |
//
|
695 |
// ResultSet localrs = (ResultSet) rs_st[0];
|
696 |
// Statement _st = (Statement) rs_st[1];
|
697 |
//
|
698 |
// return new OracleSpatialFeatureIterator(this, localrs, _st,
|
699 |
// oneBasedGeoColInd, use_geotools, false, null);
|
700 |
// }
|
701 |
//
|
702 |
// /**
|
703 |
// * Gets Oracle particular connection string beginning: "jdbc:oracle:thin:"
|
704 |
// */
|
705 |
// public String getConnectionStringBeginning() {
|
706 |
// // oracle
|
707 |
// return CONN_STR_BEGIN;
|
708 |
// }
|
709 |
//
|
710 |
// public void open() { // throws DriverException {
|
711 |
// }
|
712 |
//
|
713 |
// /**
|
714 |
// * Gets Oracle's default port: 1521
|
715 |
// */
|
716 |
// public int getDefaultPort() {
|
717 |
// // oracle port
|
718 |
// return 1521;
|
719 |
// }
|
720 |
//
|
721 |
// /**
|
722 |
// * Gets the feature iterator for a given rectangle (the view's bounding box)
|
723 |
// * and a SRS.
|
724 |
// */
|
725 |
// public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG)
|
726 |
// throws ReadDriverException {
|
727 |
// if (isNotAvailableYet) {
|
728 |
// return new AnEmptyFeatureIterator();
|
729 |
// // return null;
|
730 |
// }
|
731 |
//
|
732 |
// singleCachedFeatureRowNum = -1;
|
733 |
//
|
734 |
// STRUCT local_st = shapeToStruct(r, FShape.NULL, tableHasSrid, false, true);
|
735 |
// Object[] rs_st = getViewResultSet(local_st, null, tableHasSrid);
|
736 |
// ResultSet localrs = (ResultSet) rs_st[0];
|
737 |
// Statement _st = (Statement) rs_st[1];
|
738 |
//
|
739 |
// return new OracleSpatialFeatureIterator(this, localrs, _st,
|
740 |
// oneBasedGeoColInd, use_geotools, false, null);
|
741 |
// }
|
742 |
//
|
743 |
// private Rectangle2D intersectWithWorkingArea(Rectangle2D r) {
|
744 |
// if (workingAreaInTablesCS == null) return r;
|
745 |
// return OracleSpatialUtils.doIntersect(r, workingAreaInTablesCS);
|
746 |
// }
|
747 |
//
|
748 |
// /**
|
749 |
// * This method reverts to the one without the fields specification.
|
750 |
// * The fields have been selected from the start.
|
751 |
// */
|
752 |
// public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG,
|
753 |
// String[] alphaNumericFieldsNeeded) throws ReadDriverException {
|
754 |
//
|
755 |
// if (isNotAvailableYet) {
|
756 |
// return new AnEmptyFeatureIterator();
|
757 |
// // return null;
|
758 |
// }
|
759 |
// singleCachedFeatureRowNum = -1;
|
760 |
//
|
761 |
// if ((alphaNumericFieldsNeeded == null) || (alphaNumericFieldsNeeded.length == 0)) {
|
762 |
// return getFeatureIterator(r, strEPSG);
|
763 |
// } else {
|
764 |
//
|
765 |
// STRUCT local_st = shapeToStruct(r, FShape.NULL, tableHasSrid, false, true);
|
766 |
// Object[] rs_st = getViewResultSet(local_st, null, tableHasSrid);
|
767 |
// ResultSet localrs = (ResultSet) rs_st[0];
|
768 |
// Statement _st = (Statement) rs_st[1];
|
769 |
//
|
770 |
// return new OracleSpatialFeatureIterator(this, localrs, _st,
|
771 |
// oneBasedGeoColInd, use_geotools, true, alphaNumericFieldsNeeded);
|
772 |
// }
|
773 |
// }
|
774 |
//
|
775 |
// private String getSqlFor(String[] alphaNumericFieldsNeeded, String sdo_inter) {
|
776 |
//
|
777 |
// String idswhere = getIdsQueryWhereClause(false);
|
778 |
// String custom_sel = getCustomSelect(alphaNumericFieldsNeeded, sdo_inter, idswhere);
|
779 |
// return custom_sel;
|
780 |
// }
|
781 |
//
|
782 |
// public String getGeometryField(String fieldName) {
|
783 |
// return fieldName;
|
784 |
// }
|
785 |
//
|
786 |
// public DriverAttributes getDriverAttributes() {
|
787 |
// return drvAtts;
|
788 |
// }
|
789 |
//
|
790 |
// /**
|
791 |
// * Gets the requested geometry. Always performs a new query in this case.
|
792 |
// * This should be a rare way to get the geometries. The standard way is by using
|
793 |
// * the iterators.
|
794 |
// */
|
795 |
// public IGeometry getShape(int _ind) throws ReadDriverException {
|
796 |
// if (isNotAvailableYet) {
|
797 |
// return OracleSpatialUtils.NULL_GEOM;
|
798 |
// }
|
799 |
//
|
800 |
// ROWID r_id = (ROWID) rowToId.get(new Integer(_ind));
|
801 |
//
|
802 |
// String _sql = "select " + geoColName + " from " + getTableName() +
|
803 |
// " where rowid = ?";
|
804 |
//
|
805 |
// try {
|
806 |
// java.sql.PreparedStatement ps = ((ConnectionJDBC)conn).getConnection().prepareStatement(_sql);
|
807 |
// ps.setObject(1, r_id);
|
808 |
//
|
809 |
// // Statement stmnt = conn.createStatement();
|
810 |
// ps.execute();
|
811 |
//
|
812 |
// ResultSet _res = ps.getResultSet();
|
813 |
//
|
814 |
// if (_res.next()) {
|
815 |
// STRUCT _st = (oracle.sql.STRUCT) _res.getObject(1); // geocolind);
|
816 |
// IGeometry theGeom = getGeometryUsing(_st, use_geotools);
|
817 |
// _res.close();
|
818 |
// ps.close();
|
819 |
//
|
820 |
// return theGeom;
|
821 |
// }
|
822 |
// else {
|
823 |
// logger.error("Unable to get shape: " + _ind +
|
824 |
// " (probably due to edition)");
|
825 |
//
|
826 |
//
|
827 |
// return OracleSpatialUtils.NULL_GEOM;
|
828 |
// }
|
829 |
// }
|
830 |
// catch (SQLException se) {
|
831 |
// throw new ReadDriverException(getName(), se);
|
832 |
// }
|
833 |
// }
|
834 |
//
|
835 |
// public boolean isWritable() {
|
836 |
// return true;
|
837 |
// }
|
838 |
//
|
839 |
// public String getName() {
|
840 |
// return NAME;
|
841 |
// }
|
842 |
//
|
843 |
// public int[] getPrimaryKeys() throws ReadDriverException {
|
844 |
// return pkOneBasedIndexes;
|
845 |
// }
|
846 |
//
|
847 |
//
|
848 |
//
|
849 |
//
|
850 |
// private void setIdRowTable() {
|
851 |
// hashRelate = new Hashtable();
|
852 |
//
|
853 |
// java.sql.PreparedStatement ps = null;
|
854 |
//
|
855 |
// try {
|
856 |
// String _sql = getIdAndElemInfoFullResulltSetQuery();
|
857 |
//
|
858 |
// logger.debug("SQL para leer ids: " + _sql);
|
859 |
// Statement st = null;
|
860 |
//
|
861 |
//
|
862 |
// st = ((ConnectionJDBC)conn).getConnection().createStatement(
|
863 |
// ResultSet.TYPE_FORWARD_ONLY,
|
864 |
// ResultSet.CONCUR_READ_ONLY);
|
865 |
//
|
866 |
//
|
867 |
//
|
868 |
// // st = ((ConnectionJDBC)conn).getConnection().createStatement();
|
869 |
//
|
870 |
// st.setFetchSize(FETCH_SIZE);
|
871 |
// logger.info("FETCH_SIZE = " + FETCH_SIZE);
|
872 |
//
|
873 |
// ResultSet _r = null;
|
874 |
// _r = st.executeQuery(_sql);
|
875 |
//
|
876 |
// ROWID ri = null;
|
877 |
//
|
878 |
// int row = 0;
|
879 |
// String gid;
|
880 |
// Value aux = null;
|
881 |
//
|
882 |
// // ----------------------------------- types init
|
883 |
// ArrayList types = new ArrayList();
|
884 |
// int types_aux = 0;
|
885 |
//
|
886 |
// ARRAY info_aux;
|
887 |
// int[] info_aux_int;
|
888 |
// int size;
|
889 |
//
|
890 |
// // ----------------------------------- types init
|
891 |
// logger.debug("Beginning of result set:");
|
892 |
//
|
893 |
// while (_r.next()) {
|
894 |
// // ---------------------------------------
|
895 |
// ri = (ROWID) _r.getObject(1);
|
896 |
// gid = ri.stringValue();
|
897 |
// aux = ValueFactory.createValue(gid);
|
898 |
//
|
899 |
// Integer intobj = new Integer(row);
|
900 |
// hashRelate.put(aux, intobj);
|
901 |
// rowToId.put(intobj, ri);
|
902 |
//
|
903 |
// if ((row % 5000) == 0) {
|
904 |
// // ------------------------------------------- cancel load
|
905 |
// if (cancelIDLoad) {
|
906 |
// hashRelate.clear();
|
907 |
// rowToId.clear();
|
908 |
//
|
909 |
// return;
|
910 |
// }
|
911 |
//
|
912 |
// // -------------------------------------------
|
913 |
// String fmt = OracleSpatialUtils.getFormattedInteger(row);
|
914 |
// logger.info("IDs read: " + fmt);
|
915 |
// }
|
916 |
//
|
917 |
// row++;
|
918 |
//
|
919 |
// // --------------------------------------- types
|
920 |
// info_aux = (ARRAY) _r.getObject(2);
|
921 |
//
|
922 |
// if (info_aux == null) {
|
923 |
// // logger.debug("NULL info array found in record: " + row);
|
924 |
// }
|
925 |
// else {
|
926 |
// info_aux_int = info_aux.getIntArray();
|
927 |
// size = info_aux_int.length / 3;
|
928 |
//
|
929 |
// for (int i = 0; i < size; i++) {
|
930 |
// types_aux = info_aux_int[(3 * i) + 1];
|
931 |
// types.add(new Integer(types_aux % 1000));
|
932 |
// }
|
933 |
// }
|
934 |
//
|
935 |
// // --------------------------------------- types end
|
936 |
// }
|
937 |
//
|
938 |
// _r.close();
|
939 |
//// ps.close();
|
940 |
// st.close();
|
941 |
// numReg = row;
|
942 |
//
|
943 |
// needsCollectionLayer = OracleSpatialUtils.hasSeveralGeometryTypes(types, false);
|
944 |
//
|
945 |
// if (needsCollectionLayer) {
|
946 |
// shapeType = FShape.MULTI;
|
947 |
// }
|
948 |
// }
|
949 |
// catch (SQLException e) {
|
950 |
// logger.error("While setting id-row hashmap: " +
|
951 |
// e.getMessage());
|
952 |
// }
|
953 |
// }
|
954 |
//
|
955 |
// public int getFieldCount() throws ReadDriverException {
|
956 |
// try {
|
957 |
// return metaData.getColumnCount();
|
958 |
// }
|
959 |
// catch (SQLException e) {
|
960 |
// logger.error("While getting field count: " + e.getMessage());
|
961 |
// throw new ReadDriverException(getName(), e);
|
962 |
// }
|
963 |
// }
|
964 |
//
|
965 |
// public String[] getFieldNames() {
|
966 |
// return fieldNames;
|
967 |
// }
|
968 |
//
|
969 |
// public String getTotalFields() {
|
970 |
// String strAux = "";
|
971 |
//
|
972 |
// for (int i = 0; i < fieldNames.length; i++) {
|
973 |
// if (i == 0) {
|
974 |
// strAux = fieldNames[i];
|
975 |
// }
|
976 |
// else {
|
977 |
// strAux = strAux + ", " + fieldNames[i];
|
978 |
// }
|
979 |
// }
|
980 |
//
|
981 |
// return strAux;
|
982 |
// }
|
983 |
//
|
984 |
// public int getFieldType(int idField) throws ReadDriverException {
|
985 |
// int i = 0;
|
986 |
//
|
987 |
// try {
|
988 |
// i = idField + 1; // idField viene basado en 0
|
989 |
//
|
990 |
// int __type = metaData.getColumnType(i);
|
991 |
// int size = metaData.getPrecision(i);
|
992 |
// int dec_pos = metaData.getScale(i);
|
993 |
//
|
994 |
// // we must add this entry because we did not remove the 'geometry' column
|
995 |
// if (__type == Types.STRUCT) {
|
996 |
// return Types.VARCHAR; // .STRUCT;
|
997 |
// // ----------------------------------------------------------------------
|
998 |
// }
|
999 |
//
|
1000 |
// if (__type == Types.VARCHAR) {
|
1001 |
// return Types.VARCHAR;
|
1002 |
// }
|
1003 |
//
|
1004 |
// if (__type == Types.FLOAT) {
|
1005 |
// return Types.FLOAT;
|
1006 |
// }
|
1007 |
//
|
1008 |
// if (__type == Types.DOUBLE) {
|
1009 |
// return Types.DOUBLE;
|
1010 |
// }
|
1011 |
//
|
1012 |
// if ((__type == Types.INTEGER)
|
1013 |
// || (__type == Types.SMALLINT)
|
1014 |
// || (__type == Types.TINYINT)
|
1015 |
// || (__type == Types.BIGINT)
|
1016 |
// || ((__type == Types.NUMERIC) && (dec_pos == 0))
|
1017 |
// ) {
|
1018 |
//
|
1019 |
// if (size > 10) {
|
1020 |
// return Types.BIGINT;
|
1021 |
// } else {
|
1022 |
// return Types.INTEGER;
|
1023 |
// }
|
1024 |
// }
|
1025 |
//
|
1026 |
// if (__type == Types.BIT) {
|
1027 |
// return Types.BIT;
|
1028 |
// }
|
1029 |
//
|
1030 |
// if (__type == Types.DATE) {
|
1031 |
// return Types.DATE;
|
1032 |
// }
|
1033 |
//
|
1034 |
// if (__type == Types.DECIMAL) {
|
1035 |
// return Types.DOUBLE;
|
1036 |
// }
|
1037 |
//
|
1038 |
// if (__type == Types.NUMERIC) {
|
1039 |
// return Types.DOUBLE;
|
1040 |
// }
|
1041 |
//
|
1042 |
// if (__type == Types.DATE) {
|
1043 |
// return Types.DATE;
|
1044 |
// }
|
1045 |
//
|
1046 |
// if (__type == Types.TIME) {
|
1047 |
// return Types.TIME;
|
1048 |
// }
|
1049 |
//
|
1050 |
// if (__type == Types.TIMESTAMP) {
|
1051 |
// return Types.TIMESTAMP;
|
1052 |
// }
|
1053 |
// }
|
1054 |
// catch (SQLException e) {
|
1055 |
// logger.error("Unknown field type of : " + i);
|
1056 |
// throw new ReadDriverException(getName(), e);
|
1057 |
// }
|
1058 |
//
|
1059 |
// return -1;
|
1060 |
// }
|
1061 |
//
|
1062 |
//
|
1063 |
// public String getFieldName(int fieldId) throws ReadDriverException {
|
1064 |
// return fieldNames[fieldId];
|
1065 |
// }
|
1066 |
//
|
1067 |
// public int getFieldWidth(int fieldId) {
|
1068 |
// int i = -1;
|
1069 |
//
|
1070 |
// try {
|
1071 |
// int aux = fieldId + 1; // fieldId viene basado en 0
|
1072 |
// i = metaData.getColumnDisplaySize(aux);
|
1073 |
// }
|
1074 |
// catch (SQLException e) {
|
1075 |
// logger.error("While getting field width: " + e.getMessage());
|
1076 |
// }
|
1077 |
//
|
1078 |
// if (i < 0) {
|
1079 |
// i = 255;
|
1080 |
// }
|
1081 |
//
|
1082 |
// return i;
|
1083 |
// }
|
1084 |
//
|
1085 |
// public Value getFieldValue(long rowIndex, int field_Id) throws ReadDriverException {
|
1086 |
// if (isNotAvailableYet) {
|
1087 |
// return nullVal;
|
1088 |
// }
|
1089 |
//
|
1090 |
// if ((singleCachedFeature != null) &&
|
1091 |
// (rowIndex == singleCachedFeatureRowNum)) {
|
1092 |
// return singleCachedFeature.getAttributes()[field_Id];
|
1093 |
// }
|
1094 |
//
|
1095 |
// // return ValueFactory.createNullValue();
|
1096 |
// ResultSet _r = null;
|
1097 |
// java.sql.PreparedStatement ps = null;
|
1098 |
//
|
1099 |
// try {
|
1100 |
// String rnq = getSearchId();
|
1101 |
// ROWID _id = (ROWID) rowToId.get(new Integer((int) rowIndex));
|
1102 |
//
|
1103 |
// ps = ((ConnectionJDBC)conn).getConnection().prepareStatement(rnq);
|
1104 |
// ps.setObject(1, _id);
|
1105 |
//
|
1106 |
// ps.execute();
|
1107 |
// _r = ps.getResultSet();
|
1108 |
//
|
1109 |
// if (!_r.next()) {
|
1110 |
// _r.close();
|
1111 |
// ps.close();
|
1112 |
// throw new SQLException("No row for ROWID: " + _id.toString() + ". Possibly deleted from another app.");
|
1113 |
// }
|
1114 |
//
|
1115 |
// } catch (SQLException se) {
|
1116 |
// logger.error("While getting row " + rowIndex + " : " + se.getMessage());
|
1117 |
// return ValueFactory.createNullValue();
|
1118 |
// }
|
1119 |
//
|
1120 |
// IFeature ife = null;
|
1121 |
// Value[] atts = null;
|
1122 |
//
|
1123 |
// try {
|
1124 |
// ROWID ri = (ROWID) _r.getObject(1);
|
1125 |
// atts = getAttributes(_r, true);
|
1126 |
//
|
1127 |
// String gid = ri.stringValue();
|
1128 |
// STRUCT _st = (oracle.sql.STRUCT) _r.getObject(oneBasedGeoColInd);
|
1129 |
// IGeometry theGeom = getGeometryUsing(_st, use_geotools);
|
1130 |
// ife = new DefaultFeature(theGeom, atts, gid);
|
1131 |
// _r.close();
|
1132 |
// ps.close();
|
1133 |
// } catch (SQLException se) {
|
1134 |
// logger.error("Error while doing next(): " + se.getMessage(), se);
|
1135 |
// return ValueFactory.createNullValue();
|
1136 |
// }
|
1137 |
//
|
1138 |
// // -------------------------------
|
1139 |
// singleCachedFeature = ife;
|
1140 |
// singleCachedFeatureRowNum = rowIndex;
|
1141 |
//
|
1142 |
// // -------------------------------
|
1143 |
// if (atts == null) {
|
1144 |
// return ValueFactory.createNullValue();
|
1145 |
// } else {
|
1146 |
// return atts[field_Id];
|
1147 |
// }
|
1148 |
// }
|
1149 |
//
|
1150 |
//
|
1151 |
//
|
1152 |
// public Rectangle2D getFullExtent() {
|
1153 |
// return full_Extent;
|
1154 |
// }
|
1155 |
//
|
1156 |
//
|
1157 |
//
|
1158 |
// private IGeometry getFMapGeometryCollection(Datum[] the_data, int dim) {
|
1159 |
// // int __srid) {
|
1160 |
//
|
1161 |
// NUMBER _srid = new NUMBER(0);
|
1162 |
// NUMBER main_type = new NUMBER((dim * 1000) +
|
1163 |
// OracleSpatialUtils.getStructType(the_data));
|
1164 |
//
|
1165 |
//
|
1166 |
// Datum[] all_info_array = null;
|
1167 |
// Object[] elems_info_aray = null;
|
1168 |
// Datum[] all_ords = null;
|
1169 |
//
|
1170 |
// Object[] ords_of_groups = null;
|
1171 |
// Object[] _elems_info_aray = null;
|
1172 |
// try {
|
1173 |
// all_info_array = ((ARRAY) the_data[3]).getOracleArray();
|
1174 |
// elems_info_aray = OracleSpatialUtils.groupByElement(all_info_array);
|
1175 |
// all_ords = ((ARRAY) the_data[4]).getOracleArray();
|
1176 |
//
|
1177 |
// ords_of_groups = OracleSpatialUtils.getOrdOfGroups(all_ords, elems_info_aray);
|
1178 |
// _elems_info_aray = new Object[elems_info_aray.length];
|
1179 |
// }
|
1180 |
// catch (SQLException e) {
|
1181 |
// logger.error("Unexpected error: " + e.getMessage());
|
1182 |
// }
|
1183 |
//
|
1184 |
//
|
1185 |
// for (int i = 0; i < elems_info_aray.length; i++) {
|
1186 |
// _elems_info_aray[i] = OracleSpatialUtils.updateIndexes((Datum[]) elems_info_aray[i]);
|
1187 |
// }
|
1188 |
//
|
1189 |
// // _elems_info_aray, ords_of_groups
|
1190 |
// int no_of_elems = ords_of_groups.length;
|
1191 |
// IGeometry[] geoms = new IGeometry[no_of_elems];
|
1192 |
//
|
1193 |
// for (int i = 0; i < no_of_elems; i++) {
|
1194 |
// Datum[] item_info_array = null;
|
1195 |
// Datum[] item_ords = null;
|
1196 |
// NUMBER gtype = null;
|
1197 |
//
|
1198 |
// try {
|
1199 |
// item_info_array = (Datum[]) _elems_info_aray[i];
|
1200 |
// item_ords = (Datum[]) ords_of_groups[i];
|
1201 |
//
|
1202 |
// gtype = new NUMBER((dim * 1000) +
|
1203 |
// (item_info_array[1].intValue() % 1000));
|
1204 |
//
|
1205 |
// if (tableHasSrid) {
|
1206 |
// _srid = new NUMBER(Integer.parseInt(oracleSRID));
|
1207 |
// }
|
1208 |
// }
|
1209 |
// catch (SQLException se) {
|
1210 |
// logger.error("Unexpected error: " + se.getMessage());
|
1211 |
// }
|
1212 |
//
|
1213 |
// // if it's the first geometry, the type is the collection's main type (no?) - no
|
1214 |
// // if (i == 0) gtype = main_type;
|
1215 |
//
|
1216 |
// STRUCT itemst = null;
|
1217 |
//
|
1218 |
// if (tableHasSrid) {
|
1219 |
//
|
1220 |
// itemst = OracleSpatialUtils.createStruct(gtype, _srid,
|
1221 |
// item_info_array, item_ords, ((ConnectionJDBC)conn).getConnection());
|
1222 |
// }
|
1223 |
// else {
|
1224 |
// itemst = OracleSpatialUtils.createStruct(gtype, null,
|
1225 |
// item_info_array, item_ords, ((ConnectionJDBC)conn).getConnection());
|
1226 |
// }
|
1227 |
//
|
1228 |
// geoms[i] = getFMapGeometry(itemst, true);
|
1229 |
// }
|
1230 |
//
|
1231 |
// return new FGeometryCollection(geoms);
|
1232 |
// }
|
1233 |
//
|
1234 |
//
|
1235 |
//
|
1236 |
//
|
1237 |
//
|
1238 |
//
|
1239 |
//
|
1240 |
//
|
1241 |
// private void cleanWhereClause() {
|
1242 |
// emptyWhereClause = false;
|
1243 |
//
|
1244 |
// String aux = getWhereClauseWithoutWhere();
|
1245 |
//
|
1246 |
// for (int i = 0; i < aux.length(); i++)
|
1247 |
// if (aux.substring(i, i + 1).compareTo(" ") != 0) {
|
1248 |
// return;
|
1249 |
// }
|
1250 |
//
|
1251 |
// getLyrDef().setWhereClause("");
|
1252 |
// emptyWhereClause = true;
|
1253 |
// }
|
1254 |
//
|
1255 |
//
|
1256 |
//
|
1257 |
// private String getMainSelect(String viewsdo, String idsLoadWhere) {
|
1258 |
// String resp = "";
|
1259 |
//
|
1260 |
// if (isGeogCS) {
|
1261 |
// String vport = "sdo_filter(" + geoColName +
|
1262 |
// ", SDO_CS.VIEWPORT_TRANSFORM(" + viewsdo + ", " + oracleSRID +
|
1263 |
// "), 'querytype=window') = 'TRUE'";
|
1264 |
//
|
1265 |
// resp = "select " + getStandardSelectExpression() + ", c." +
|
1266 |
// geoColName + " from " + getTableName() + " c where ";
|
1267 |
// if (idsLoadWhere.length() > 0) {
|
1268 |
// resp = resp + " (" + idsLoadWhere + ") AND ";
|
1269 |
// }
|
1270 |
// resp = resp + "(" + vport + ")";
|
1271 |
// }
|
1272 |
// else {
|
1273 |
// resp = "select " + getStandardSelectExpression() + ", c." +
|
1274 |
// geoColName + " from " + getTableName() + " c where ";
|
1275 |
// if (idsLoadWhere.length() > 0) {
|
1276 |
// resp = resp + " (" + idsLoadWhere + ") AND ";
|
1277 |
// }
|
1278 |
// resp = resp + "(" + "sdo_relate(" + geoColName + ", " + viewsdo +
|
1279 |
// ", 'mask=anyinteract querytype=window') = 'TRUE')";
|
1280 |
// }
|
1281 |
//
|
1282 |
//// return "select " + getStandardSelectExpression() + ", c." +
|
1283 |
//// geoColName + " from " + getTableName() + " c";
|
1284 |
// return resp;
|
1285 |
// }
|
1286 |
//
|
1287 |
// private String getCustomSelect(String[] atts, String viewsdo, String idsLoadWhere) {
|
1288 |
// String resp = "";
|
1289 |
//
|
1290 |
// String atts_enum = "";
|
1291 |
// if ((atts == null) || (atts.length == 0)) {
|
1292 |
//
|
1293 |
// } else {
|
1294 |
// atts_enum = " c.\"" + atts[0] + "\" ";
|
1295 |
// for (int i=1; i<atts.length; i++) {
|
1296 |
// atts_enum = atts_enum + ", " + atts[1];
|
1297 |
// }
|
1298 |
// }
|
1299 |
//
|
1300 |
// if (isGeogCS) {
|
1301 |
// String vport = "sdo_filter(" + geoColName +
|
1302 |
// ", SDO_CS.VIEWPORT_TRANSFORM(" + viewsdo + ", " + oracleSRID +
|
1303 |
// "), 'querytype=window') = 'TRUE'";
|
1304 |
//
|
1305 |
// resp = "select " + atts_enum + " from " + getTableName() + " c where ";
|
1306 |
// if (idsLoadWhere.length() > 0) {
|
1307 |
// resp = resp + " (" + idsLoadWhere + ") AND ";
|
1308 |
// }
|
1309 |
// resp = resp + "(" + vport + ")";
|
1310 |
// } else {
|
1311 |
// resp = "select " + atts_enum + " from " + getTableName() + " c where ";
|
1312 |
// if (idsLoadWhere.length() > 0) {
|
1313 |
// resp = resp + " (" + idsLoadWhere + ") AND ";
|
1314 |
// }
|
1315 |
// resp = resp + "(" + "sdo_relate(" + geoColName + ", " + viewsdo +
|
1316 |
// ", 'mask=anyinteract querytype=window') = 'TRUE')";
|
1317 |
// }
|
1318 |
//
|
1319 |
//// return "select " + getStandardSelectExpression() + ", c." +
|
1320 |
//// geoColName + " from " + getTableName() + " c";
|
1321 |
// return resp;
|
1322 |
// }
|
1323 |
//
|
1324 |
// public void setWorkingArea(Rectangle2D rect) {
|
1325 |
// }
|
1326 |
//
|
1327 |
// private void setWAStructt() {
|
1328 |
// }
|
1329 |
//
|
1330 |
//
|
1331 |
//
|
1332 |
// private int oracleTypeToFShapeTypeExceptPointTypes(int type) {
|
1333 |
// /*
|
1334 |
// * Tipos en Oracle Spatial usando JGeometry
|
1335 |
// *
|
1336 |
// * GTYPE_COLLECTION collection geometry type
|
1337 |
// * GTYPE_CURVE curve geoemtry type
|
1338 |
// * GTYPE_MULTICURVE multi-curve geometry type
|
1339 |
// * GTYPE_MULTIPOINT multi-point geometry type
|
1340 |
// * GTYPE_MULTIPOLYGON multi-polygon geometry type
|
1341 |
// * GTYPE_POINT point geometry type
|
1342 |
// * GTYPE_POLYGON polygon geometry type
|
1343 |
// *
|
1344 |
// * Tipos gvSIG FShape
|
1345 |
// *
|
1346 |
// * NULL = 0;
|
1347 |
// * POINT = 1;
|
1348 |
// * LINE = 2;
|
1349 |
// * POLYGON = 4;
|
1350 |
// * TEXT = 8;
|
1351 |
// * MULTI = 16;
|
1352 |
// * MULTIPOINT = 32;
|
1353 |
// * CIRCLE = 64;
|
1354 |
// * ARC = 128;
|
1355 |
// * ELLIPSE=256;
|
1356 |
// * Z=512
|
1357 |
// */
|
1358 |
// switch (type) {
|
1359 |
// case JGeometry_GTYPE_POLYGON:
|
1360 |
// case JGeometry_GTYPE_MULTIPOLYGON:
|
1361 |
// return FShape.POLYGON;
|
1362 |
//
|
1363 |
// case JGeometry_GTYPE_CURVE:
|
1364 |
// case JGeometry_GTYPE_MULTICURVE:
|
1365 |
// return FShape.LINE;
|
1366 |
// }
|
1367 |
//
|
1368 |
// logger.error("Unhandled Oracle Spatial geometry type: " + type +
|
1369 |
// " (conversion returned FShape.NULL)");
|
1370 |
//
|
1371 |
// return FShape.NULL;
|
1372 |
// }
|
1373 |
//
|
1374 |
// private String getValidViewConstructor(
|
1375 |
// STRUCT _st,
|
1376 |
// String ora_srid,
|
1377 |
// boolean _hassrid,
|
1378 |
// boolean _isgeocs) {
|
1379 |
//
|
1380 |
// String sdo = getSdoConstructor(_st, _hassrid, _isgeocs);
|
1381 |
// String resp = "";
|
1382 |
// if ((_hassrid) && (_isgeocs)) {
|
1383 |
// resp = "SDO_CS.VIEWPORT_TRANSFORM( " + sdo + " , " + ora_srid + ")";
|
1384 |
// } else {
|
1385 |
// resp = sdo;
|
1386 |
// }
|
1387 |
//
|
1388 |
// return resp;
|
1389 |
// }
|
1390 |
//
|
1391 |
//
|
1392 |
//
|
1393 |
// private Object[] getViewResultSet(STRUCT geoStruct, String fixsql,
|
1394 |
// boolean hasSrid) throws ReadDriverException {
|
1395 |
// String sdo_intersect = getSdoConstructor(geoStruct, hasSrid, isGeogCS);
|
1396 |
// String main_sel = "";
|
1397 |
//
|
1398 |
// if (fixsql == null) {
|
1399 |
// // main_sel = getMainSelect3(var_name);
|
1400 |
// String idswhere = getIdsQueryWhereClause(false);
|
1401 |
// main_sel = getMainSelect(sdo_intersect, idswhere);
|
1402 |
// }
|
1403 |
// else {
|
1404 |
// main_sel = fixsql;
|
1405 |
// }
|
1406 |
//
|
1407 |
// logger.debug("MAIN SEL = " + main_sel);
|
1408 |
//
|
1409 |
// ResultSet _rs = null;
|
1410 |
// Statement _stmnt = null;
|
1411 |
// Object[] _resp = new Object[2];
|
1412 |
//
|
1413 |
// try {
|
1414 |
// _stmnt = ((ConnectionJDBC)conn).getConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY,
|
1415 |
// ResultSet.CONCUR_READ_ONLY);
|
1416 |
// _stmnt.setFetchDirection(ResultSet.FETCH_FORWARD);
|
1417 |
// _stmnt.setFetchSize(FETCH_SIZE);
|
1418 |
//
|
1419 |
// _rs = _stmnt.executeQuery(main_sel);
|
1420 |
//
|
1421 |
// // stmnt.close();
|
1422 |
// }
|
1423 |
// catch (SQLException se) {
|
1424 |
// logger.error("Tablename: " + getTableName() + ". Error while getting main cursor: " + se.getMessage(),
|
1425 |
// se);
|
1426 |
// throw new ReadDriverException(getName(), se);
|
1427 |
// }
|
1428 |
//
|
1429 |
// // this method returns the statement too, so that it can be closed afterwards
|
1430 |
// _resp[0] = _rs;
|
1431 |
// _resp[1] = _stmnt;
|
1432 |
//
|
1433 |
// return _resp;
|
1434 |
// }
|
1435 |
//
|
1436 |
// private String getSdoConstructor(STRUCT geoStruct, boolean hasSrid, boolean _isGeogCS) {
|
1437 |
// String resp = "";
|
1438 |
//
|
1439 |
// try {
|
1440 |
// String mdsys_sdo_elem_info_array = "mdsys.sdo_elem_info_array(1, 1003, 3)";
|
1441 |
// String mdsys_sdo_ordinate_array = "";
|
1442 |
// Datum[] vertices = ((ARRAY) geoStruct.getOracleAttributes()[4]).getOracleArray();
|
1443 |
//
|
1444 |
// for (int i = 0; i < vertices.length; i++) {
|
1445 |
// mdsys_sdo_ordinate_array = mdsys_sdo_ordinate_array +
|
1446 |
// vertices[i].doubleValue() + ", ";
|
1447 |
// }
|
1448 |
//
|
1449 |
// mdsys_sdo_ordinate_array = mdsys_sdo_ordinate_array.substring(0,
|
1450 |
// mdsys_sdo_ordinate_array.length() - 2);
|
1451 |
// mdsys_sdo_ordinate_array = "mdsys.sdo_ordinate_array(" +
|
1452 |
// mdsys_sdo_ordinate_array + ")";
|
1453 |
//
|
1454 |
// String aux = "";
|
1455 |
//
|
1456 |
// if (hasSrid) {
|
1457 |
// aux = oracleSRID;
|
1458 |
//
|
1459 |
// if (_isGeogCS) {
|
1460 |
// aux = "0";
|
1461 |
// }
|
1462 |
// }
|
1463 |
// else {
|
1464 |
// aux = "null";
|
1465 |
// }
|
1466 |
//
|
1467 |
// resp = "mdsys.sdo_geometry(2003, " + aux + ", null, " +
|
1468 |
// mdsys_sdo_elem_info_array + ", " + mdsys_sdo_ordinate_array +
|
1469 |
// ")";
|
1470 |
// }
|
1471 |
// catch (Exception ex) {
|
1472 |
// logger.error("While getting sdo contructor: " +
|
1473 |
// ex.getMessage());
|
1474 |
// }
|
1475 |
//
|
1476 |
// return resp;
|
1477 |
// }
|
1478 |
//
|
1479 |
// private String getIdsQueryWhereClause(boolean with_where) {
|
1480 |
// String resp = "";
|
1481 |
//
|
1482 |
// String _where = "";
|
1483 |
// if (with_where) _where = " where ";
|
1484 |
//
|
1485 |
// if (workingAreaInTablesCSStruct == null) {
|
1486 |
// if (emptyWhereClause) {
|
1487 |
// // return "select rowid from " + getTableName();
|
1488 |
// } else {
|
1489 |
// resp = resp + _where + "(" + getWhereClauseWithoutWhere()
|
1490 |
// + ")";
|
1491 |
// }
|
1492 |
// } else {
|
1493 |
// String waqry = getValidViewConstructor(workingAreaInTablesCSStruct,
|
1494 |
// oracleSRID, tableHasSrid, isGeogCS);
|
1495 |
//
|
1496 |
// if (emptyWhereClause) {
|
1497 |
// resp = resp + _where + "(sdo_relate(" + geoColName + ", " + waqry
|
1498 |
// + ", 'mask=anyinteract querytype=window') = 'TRUE')";
|
1499 |
// } else {
|
1500 |
// resp = resp + _where + "((" + getWhereClauseWithoutWhere()
|
1501 |
// + ") AND (" + "sdo_relate(" + geoColName + ", " + waqry
|
1502 |
// + ", 'mask=anyinteract querytype=window') = 'TRUE'))";
|
1503 |
// }
|
1504 |
// }
|
1505 |
//
|
1506 |
// // resp = resp + " order by rowid";
|
1507 |
// return resp;
|
1508 |
// }
|
1509 |
//
|
1510 |
// public String getIdAndElemInfoFullResulltSetQuery() {
|
1511 |
// String resp = "select rowid, c." + geoColName + ".SDO_ELEM_INFO from " +
|
1512 |
// getTableName() + " c";
|
1513 |
//
|
1514 |
// resp = resp + getIdsQueryWhereClause(true);
|
1515 |
// return resp;
|
1516 |
// }
|
1517 |
//
|
1518 |
// private String getSearchId() {
|
1519 |
// if (emptyWhereClause) {
|
1520 |
// return "select " + getStandardSelectExpression() + ", c." +
|
1521 |
// geoColName + " from " + getTableName() + " c where rowid = ?";
|
1522 |
// }
|
1523 |
// else {
|
1524 |
// return "select " + getStandardSelectExpression() + ", c." +
|
1525 |
// geoColName + " from " + getTableName() + " c " + " where " + "((" +
|
1526 |
// getWhereClauseWithoutWhere() + ") and (rowid = ?))";
|
1527 |
// }
|
1528 |
// }
|
1529 |
//
|
1530 |
// public int getShapeType() {
|
1531 |
// return shapeType;
|
1532 |
// }
|
1533 |
//
|
1534 |
// public void setShapeType(int t) {
|
1535 |
// shapeType = t;
|
1536 |
// }
|
1537 |
//
|
1538 |
//
|
1539 |
// private String getWhereClauseWithoutWhere() {
|
1540 |
// String resp = "";
|
1541 |
// String old = getLyrDef().getWhereClause();
|
1542 |
// resp = old;
|
1543 |
//
|
1544 |
// if (old.length() <= 6) {
|
1545 |
// return old;
|
1546 |
// }
|
1547 |
//
|
1548 |
// if (old.substring(0, 6).compareToIgnoreCase("where ") == 0) {
|
1549 |
// resp = resp.substring(6, resp.length());
|
1550 |
// }
|
1551 |
//
|
1552 |
// return resp;
|
1553 |
// }
|
1554 |
//
|
1555 |
//
|
1556 |
//
|
1557 |
// public static String fieldTypeToSqlStringType(FieldDescription fieldDesc) {
|
1558 |
// String aux = "VARCHAR2(" + VARCHAR2_STANDARD_SIZE + " BYTE)"; // Por defecto.
|
1559 |
//
|
1560 |
// switch (fieldDesc.getFieldType()) {
|
1561 |
// case Types.SMALLINT:
|
1562 |
// aux = "NUMBER(5, 0)";
|
1563 |
//
|
1564 |
// break;
|
1565 |
//
|
1566 |
// case Types.INTEGER:
|
1567 |
// aux = "NUMBER(12, 0)";
|
1568 |
//
|
1569 |
// break;
|
1570 |
//
|
1571 |
// case Types.BIGINT:
|
1572 |
// aux = "NUMBER(38, 0)";
|
1573 |
//
|
1574 |
// break;
|
1575 |
//
|
1576 |
// case Types.BOOLEAN:
|
1577 |
// aux = "NUMBER(1, 0)";
|
1578 |
//
|
1579 |
// break;
|
1580 |
//
|
1581 |
// case Types.DECIMAL:
|
1582 |
// aux = "NUMBER";
|
1583 |
//
|
1584 |
// break;
|
1585 |
//
|
1586 |
// case Types.NUMERIC:
|
1587 |
// aux = "NUMBER";
|
1588 |
//
|
1589 |
// break;
|
1590 |
//
|
1591 |
// case Types.DOUBLE:
|
1592 |
// aux = "FLOAT";
|
1593 |
//
|
1594 |
// break;
|
1595 |
//
|
1596 |
// case Types.FLOAT:
|
1597 |
// aux = "FLOAT";
|
1598 |
//
|
1599 |
// break;
|
1600 |
//
|
1601 |
// case Types.CHAR:
|
1602 |
// aux = "CHAR(1 BYTE)";
|
1603 |
//
|
1604 |
// break;
|
1605 |
//
|
1606 |
// case Types.VARCHAR:
|
1607 |
// aux = "NVARCHAR2(" + nvarchar2Limited(fieldDesc.getFieldLength()) + ")";
|
1608 |
//
|
1609 |
// break;
|
1610 |
//
|
1611 |
// case Types.LONGVARCHAR:
|
1612 |
// aux = "NVARCHAR2(" + nvarchar2Limited(fieldDesc.getFieldLength()) + ")";
|
1613 |
//
|
1614 |
// break;
|
1615 |
// }
|
1616 |
//
|
1617 |
// return aux;
|
1618 |
// }
|
1619 |
//
|
1620 |
// // -----------------------------------------------------------
|
1621 |
// // -----------------------------------------------------------
|
1622 |
// public static String getDropTableSql(DBLayerDefinition dbLayerDef) {
|
1623 |
// return "DROP TABLE " + dbLayerDef.getTableName() +
|
1624 |
// " CASCADE CONSTRAINTS";
|
1625 |
// }
|
1626 |
//
|
1627 |
// public static String getTableCreationSql(DBLayerDefinition dbLayerDef) {
|
1628 |
// FieldDescription[] flds = dbLayerDef.getFieldsDesc();
|
1629 |
//
|
1630 |
// String type = "";
|
1631 |
// String name = "";
|
1632 |
// String table_name = dbLayerDef.getTableName().toUpperCase();
|
1633 |
//
|
1634 |
// String resp = "CREATE TABLE " + table_name + " ( ";
|
1635 |
//
|
1636 |
// for (int i = 0; i < flds.length; i++) {
|
1637 |
// name = flds[i].getFieldName();
|
1638 |
//
|
1639 |
// // -------------- FORBIDDEN FIELD NAMES -----------------
|
1640 |
// if (!isOracleAllowedFieldname(name)) {
|
1641 |
// continue;
|
1642 |
// }
|
1643 |
//
|
1644 |
// // ------------------------------------------------------
|
1645 |
// if (name.compareToIgnoreCase(DEFAULT_GEO_FIELD) == 0) {
|
1646 |
// }
|
1647 |
// else {
|
1648 |
// name = getValidOracleID(name, i, false);
|
1649 |
// resp = resp + "\"" + name + "\" ";
|
1650 |
// type = fieldTypeToSqlStringType(flds[i]);
|
1651 |
// resp = resp + type + ", ";
|
1652 |
// }
|
1653 |
// }
|
1654 |
//
|
1655 |
// resp = resp + "\"" + DEFAULT_GEO_FIELD + "\" ";
|
1656 |
// resp = resp + "\"MDSYS\".\"SDO_GEOMETRY\"";
|
1657 |
// resp = resp + ", ";
|
1658 |
//
|
1659 |
// String pk = "CONSTRAINT " + getDerivedNAme(table_name, "PK") +
|
1660 |
// " PRIMARY KEY (\"" + OracleSpatialDriver.DEFAULT_ID_FIELD_CASE_SENSITIVE +
|
1661 |
// "\") ENABLE";
|
1662 |
//
|
1663 |
// resp = resp + pk + " )";
|
1664 |
//
|
1665 |
// return resp;
|
1666 |
// }
|
1667 |
//
|
1668 |
// private static String getDerivedNAme(String tname, String suffix) {
|
1669 |
//
|
1670 |
// int ind = tname.lastIndexOf(".");
|
1671 |
// if (ind == -1) {
|
1672 |
//
|
1673 |
// int l = Math.min(28, tname.length());
|
1674 |
// return tname.substring(0, l) + "_" + suffix;
|
1675 |
//
|
1676 |
// } else {
|
1677 |
//
|
1678 |
// String pre = tname.substring(0, ind);
|
1679 |
// String post = tname.substring(ind + 1, tname.length());
|
1680 |
// int lpost = Math.min(24, post.length());
|
1681 |
// int lpre = Math.min(3, pre.length());
|
1682 |
// return pre.substring(0, lpre) + "_" + post.substring(0, lpost) + "_" + suffix;
|
1683 |
// }
|
1684 |
//
|
1685 |
// }
|
1686 |
//
|
1687 |
// public static String getIndexCreationSql(DBLayerDefinition dbLayerDef) {
|
1688 |
// String resp = "CREATE INDEX " + getDerivedNAme(dbLayerDef.getTableName(), "SX") +
|
1689 |
// " ON " + dbLayerDef.getTableName() + " (\"" +
|
1690 |
// OracleSpatialDriver.DEFAULT_GEO_FIELD +
|
1691 |
// "\") INDEXTYPE IS \"MDSYS\".\"SPATIAL_INDEX\" ";
|
1692 |
//
|
1693 |
// return resp;
|
1694 |
// }
|
1695 |
//
|
1696 |
// public static String getRemoveMetadataSql(DBLayerDefinition dbLayerDef) {
|
1697 |
//
|
1698 |
// String tname = dbLayerDef.getTableName();
|
1699 |
// int ind = tname.lastIndexOf(".");
|
1700 |
// if (ind != -1) {
|
1701 |
// String schema = tname.substring(0, ind);
|
1702 |
// tname = tname.substring(ind + 1, tname.length());
|
1703 |
// return "DELETE FROM " + USER_ORACLE_GEOMETADATA_VIEW +
|
1704 |
// " WHERE TABLE_NAME = '" + tname + "'";
|
1705 |
//
|
1706 |
// } else{
|
1707 |
// return "DELETE FROM " + USER_ORACLE_GEOMETADATA_VIEW +
|
1708 |
// " WHERE TABLE_NAME = '" + tname + "'";
|
1709 |
// }
|
1710 |
// }
|
1711 |
//
|
1712 |
// /**
|
1713 |
// * UTility method to get the SQL sentence needed to update the geographic metadata table
|
1714 |
// * with a new bounding box and SRS
|
1715 |
// *
|
1716 |
// * @param tName table name
|
1717 |
// * @param ora_srid new SRS
|
1718 |
// * @param bbox new bounding box
|
1719 |
// * @param dim geometries dimension
|
1720 |
// * @param withsrid False if the SRS is set to NULL. True otherwise.
|
1721 |
// * @return the SQL sentence to perform the update
|
1722 |
// */
|
1723 |
// public static String getMetadataUpdateSql(String schema, String tName, String ora_srid,
|
1724 |
// Rectangle2D bbox, int dim, boolean withsrid) {
|
1725 |
//
|
1726 |
// String[] dim_name = new String[dim];
|
1727 |
// double tolerance = 0.5;
|
1728 |
//
|
1729 |
// String _ora_srid = ora_srid;
|
1730 |
// if (_ora_srid == null) _ora_srid = "NULL";
|
1731 |
//
|
1732 |
// if (_ora_srid.compareTo(GEODETIC_SRID) == 0) {
|
1733 |
// dim_name[0] = "LONGITUDE";
|
1734 |
// dim_name[1] = "LATITUDE";
|
1735 |
// }
|
1736 |
// else {
|
1737 |
// dim_name[0] = "X";
|
1738 |
// dim_name[1] = "Y";
|
1739 |
//
|
1740 |
// if (dim > 2) {
|
1741 |
// dim_name[2] = "Z";
|
1742 |
//
|
1743 |
// if (dim > 3) {
|
1744 |
// dim_name[3] = "T";
|
1745 |
// }
|
1746 |
// }
|
1747 |
// }
|
1748 |
//
|
1749 |
// double minx = bbox.getMinX();
|
1750 |
// double miny = bbox.getMinY();
|
1751 |
// double maxx = bbox.getMaxX();
|
1752 |
// double maxy = bbox.getMaxY();
|
1753 |
//
|
1754 |
// String resp = "INSERT INTO " + USER_ORACLE_GEOMETADATA_VIEW + " " +
|
1755 |
// " ( TABLE_NAME, COLUMN_NAME, DIMINFO, SRID ) " + " VALUES ("
|
1756 |
// + "'" + tName + "', "
|
1757 |
// + "'" + DEFAULT_GEO_FIELD + "', " +
|
1758 |
// "MDSYS.SDO_DIM_ARRAY( " + "MDSYS.SDO_DIM_ELEMENT ('" + dim_name[0] + "', " +
|
1759 |
// minx + ", " + maxx + ", " + tolerance + " ), " +
|
1760 |
// "MDSYS.SDO_DIM_ELEMENT ('" + dim_name[1] + "', " + miny + ", " +
|
1761 |
// maxy + ", " + tolerance + " ))";
|
1762 |
//
|
1763 |
// if (dim > 2) {
|
1764 |
// resp = resp.substring(0, resp.length() - 1) + ",";
|
1765 |
// resp = resp + "MDSYS.SDO_DIM_ELEMENT ('" + dim_name[2] +
|
1766 |
// "', 0.0, 100.0, " + tolerance + " ))";
|
1767 |
//
|
1768 |
// if (dim > 3) {
|
1769 |
// resp = resp.substring(0, resp.length() - 1) + ",";
|
1770 |
// resp = resp + "MDSYS.SDO_DIM_ELEMENT ('" + dim_name[3] +
|
1771 |
// "', 0.0, 100.0, " + tolerance + " ))";
|
1772 |
// }
|
1773 |
// }
|
1774 |
//
|
1775 |
// if (withsrid) {
|
1776 |
// resp = resp + ", " + _ora_srid + " )";
|
1777 |
// }
|
1778 |
// else {
|
1779 |
// resp = resp + ", NULL )";
|
1780 |
// }
|
1781 |
//
|
1782 |
// return resp;
|
1783 |
// }
|
1784 |
//
|
1785 |
// /**
|
1786 |
// * Gets the SQL sentence to perform an insertion.
|
1787 |
// *
|
1788 |
// * @param feat feature to be added
|
1789 |
// * @param dbLayerDef layer definition
|
1790 |
// * @param rowInd row index
|
1791 |
// * @param _geoColName geometry field name
|
1792 |
// * @return the SQL sentence to perform the insertion
|
1793 |
// */
|
1794 |
// public static String getRowInsertSql(IFeature feat,
|
1795 |
// DBLayerDefinition dbLayerDef, int rowInd,
|
1796 |
// String _geoColName,
|
1797 |
// String geo_val) {
|
1798 |
//
|
1799 |
// String name = "";
|
1800 |
// int ftype = -1;
|
1801 |
// String aux_orig = "";
|
1802 |
// String aux_limited = "";
|
1803 |
// String aux_quotes_ok = "";
|
1804 |
//
|
1805 |
// FieldDescription[] fieldsDescr = dbLayerDef.getFieldsDesc();
|
1806 |
//
|
1807 |
// String resp = "INSERT INTO " + dbLayerDef.getTableName() + " ( ";
|
1808 |
//
|
1809 |
// for (int i = 0; i < fieldsDescr.length; i++) {
|
1810 |
// name = fieldsDescr[i].getFieldName();
|
1811 |
// ftype = fieldsDescr[i].getFieldType();
|
1812 |
//
|
1813 |
// // -------------- FORBIDDEN FIELD NAMES & TYPES ---------
|
1814 |
// if (!isOracleAllowedFieldname(name)) continue;
|
1815 |
// if (!isUserEditableType(ftype, name, _geoColName)) continue;
|
1816 |
// // ------------------------------------------------------
|
1817 |
// if (name.compareToIgnoreCase(_geoColName) == 0) {
|
1818 |
// }
|
1819 |
// else {
|
1820 |
// name = getValidOracleID(name, i, false);
|
1821 |
// resp = resp + "\"" + name + "\"" + " , ";
|
1822 |
// }
|
1823 |
// }
|
1824 |
//
|
1825 |
// resp = resp + _geoColName + " ) VALUES ( ";
|
1826 |
//
|
1827 |
// for (int i = 0; i < fieldsDescr.length; i++) {
|
1828 |
// name = fieldsDescr[i].getFieldName();
|
1829 |
// ftype = fieldsDescr[i].getFieldType();
|
1830 |
//
|
1831 |
// // -------------- FORBIDDEN FIELD NAMES/Types -----------
|
1832 |
// if (!isOracleAllowedFieldname(name)) continue;
|
1833 |
// if (!isUserEditableType(ftype, name, _geoColName)) continue;
|
1834 |
// // ------------------------------------------------------
|
1835 |
// String sur = getValueSurroundFromType(fieldsDescr[i]);
|
1836 |
//
|
1837 |
// if (name.compareToIgnoreCase(_geoColName) == 0) {
|
1838 |
// }
|
1839 |
// else {
|
1840 |
// if (name.compareTo(OracleSpatialDriver.DEFAULT_ID_FIELD_CASE_SENSITIVE) == 0) {
|
1841 |
// resp = resp + rowInd + " , ";
|
1842 |
// }
|
1843 |
// else {
|
1844 |
// Value attValue = feat.getAttribute(i);
|
1845 |
//
|
1846 |
// if (attValue.toString() == null) {
|
1847 |
// resp = resp + "NULL , ";
|
1848 |
// }
|
1849 |
// else {
|
1850 |
// if (sur.length() > 0) {
|
1851 |
// aux_orig = attValue.toString();
|
1852 |
// aux_limited = cropStringValue(aux_orig, i,
|
1853 |
// fieldsDescr);
|
1854 |
// aux_quotes_ok = avoidQuoteProblem(aux_limited);
|
1855 |
//
|
1856 |
// resp = resp + sur + aux_quotes_ok + sur + " , ";
|
1857 |
// }
|
1858 |
// else {
|
1859 |
// String _aux = attValue.toString();
|
1860 |
//
|
1861 |
// if (_aux.length() == 0) {
|
1862 |
// _aux = "NULL";
|
1863 |
// }
|
1864 |
//
|
1865 |
// resp = resp + _aux + " , ";
|
1866 |
// }
|
1867 |
// }
|
1868 |
// }
|
1869 |
// }
|
1870 |
// }
|
1871 |
//
|
1872 |
// resp = resp + " " + geo_val + " )";
|
1873 |
// /*
|
1874 |
// String test = "SDO_UTIL.APPEND(SDO_GEOMETRY("
|
1875 |
// + "2002, NULL, NULL,"
|
1876 |
// + "SDO_ELEM_INFO_ARRAY(1, 2, 2),"
|
1877 |
// + "SDO_ORDINATE_ARRAY(500000, 4000000, 1000000, 5000000, 500000, 5000000)"
|
1878 |
// + "), ? )";
|
1879 |
//
|
1880 |
// resp = resp + " " + test + " )";
|
1881 |
// */
|
1882 |
// return resp;
|
1883 |
// }
|
1884 |
//
|
1885 |
// private static boolean isUserEditableType(int ftype, String item_name, String geo_name) {
|
1886 |
//
|
1887 |
// if (item_name.compareToIgnoreCase(geo_name) == 0) {
|
1888 |
// return true;
|
1889 |
// }
|
1890 |
//
|
1891 |
// if ((ftype == Types.BINARY)
|
1892 |
// || (ftype == Types.ARRAY)
|
1893 |
// || (ftype == Types.BLOB)
|
1894 |
// || (ftype == Types.CLOB)
|
1895 |
// || (ftype == Types.STRUCT)
|
1896 |
// ) {
|
1897 |
// return false;
|
1898 |
// }
|
1899 |
// return true;
|
1900 |
// }
|
1901 |
//
|
1902 |
// /**
|
1903 |
// * Gets the SQL sentence to perform an update.
|
1904 |
// *
|
1905 |
// * @param feat feature to be updated
|
1906 |
// * @param dbLayerDef layer definition
|
1907 |
// * @param rowInd row index
|
1908 |
// * @param geoFieldName geometry field name
|
1909 |
// * @return the SQL sentence to perform the update
|
1910 |
// */
|
1911 |
// public static String getRowUpdateSql(IFeature feat,
|
1912 |
// DBLayerDefinition dbLayerDef, int rowInd, String geoFieldName) {
|
1913 |
// String name = "";
|
1914 |
// String aux_orig = "";
|
1915 |
// String aux_limited = "";
|
1916 |
// String aux_quotes_ok = "";
|
1917 |
//
|
1918 |
// Value[] atts = feat.getAttributes();
|
1919 |
// FieldDescription[] _fieldsDescr = dbLayerDef.getFieldsDesc();
|
1920 |
//
|
1921 |
// String resp = "UPDATE " + dbLayerDef.getTableName() + " SET ";
|
1922 |
//
|
1923 |
// for (int i = 0; i < _fieldsDescr.length; i++) {
|
1924 |
// name = _fieldsDescr[i].getFieldName();
|
1925 |
//
|
1926 |
// // -------------- FORBIDDEN FIELD NAMES -----------------
|
1927 |
// if (!isOracleAllowedFieldname(name)) {
|
1928 |
// logger.info("Field: " + name + " will not be updated.");
|
1929 |
// continue;
|
1930 |
// }
|
1931 |
//
|
1932 |
// if (isStructAndNotGeoField(_fieldsDescr[i].getFieldType(), name,
|
1933 |
// geoFieldName)) {
|
1934 |
// logger.info("Field: " + name + " will not be updated (it's a struct).");
|
1935 |
// continue;
|
1936 |
// }
|
1937 |
//
|
1938 |
// // ------------------------------------------------------
|
1939 |
// if (name.compareToIgnoreCase(geoFieldName) == 0) {
|
1940 |
// // resp = resp + "\"" + name + "\"" + " = ?, ";
|
1941 |
// }
|
1942 |
// else {
|
1943 |
// String sur = getValueSurroundFromType(_fieldsDescr[i]);
|
1944 |
// aux_orig = atts[i].toString();
|
1945 |
// aux_limited = cropStringValue(aux_orig, i, _fieldsDescr);
|
1946 |
// aux_quotes_ok = avoidQuoteProblem(aux_limited);
|
1947 |
// resp = resp + "\"" + name + "\"" + " = " + sur + aux_quotes_ok +
|
1948 |
// sur + ", ";
|
1949 |
// }
|
1950 |
// }
|
1951 |
//
|
1952 |
// resp = resp + "\"" + geoFieldName + "\" = ?";
|
1953 |
// resp = resp + " WHERE ROWID ='" + feat.getID() + "'";
|
1954 |
//
|
1955 |
// return resp;
|
1956 |
// }
|
1957 |
//
|
1958 |
// private static boolean isStructAndNotGeoField(int ftype, String fldname,
|
1959 |
// String geoname) {
|
1960 |
// if (ftype == Types.STRUCT) {
|
1961 |
// if (fldname.compareToIgnoreCase(geoname) != 0) {
|
1962 |
// return true;
|
1963 |
// }
|
1964 |
// }
|
1965 |
//
|
1966 |
// return false;
|
1967 |
// }
|
1968 |
//
|
1969 |
// /**
|
1970 |
// * Gets the SQL sentence to perform a deletion.
|
1971 |
// *
|
1972 |
// * @param dbLayerDef layer definition
|
1973 |
// * @param id ROWID of the record to be deleted
|
1974 |
// * @return the SQL sentence to perform the deletion
|
1975 |
// */
|
1976 |
// public static String getRowDeleteSql(DBLayerDefinition dbLayerDef, String id) {
|
1977 |
// String resp = "DELETE FROM " + dbLayerDef.getTableName();
|
1978 |
// resp = resp + " WHERE ROWID ='" + id + "'";
|
1979 |
//
|
1980 |
// return resp;
|
1981 |
// }
|
1982 |
//
|
1983 |
// private static String cropStringValue(String orig_val, int i,
|
1984 |
// FieldDescription[] _flds) {
|
1985 |
//
|
1986 |
// if (orig_val == null) {
|
1987 |
// return "NULL";
|
1988 |
// }
|
1989 |
//
|
1990 |
// if (NumberUtilities.isNumeric(_flds[i].getFieldType())
|
1991 |
// && (orig_val.length() == 0)) {
|
1992 |
// return "NULL";
|
1993 |
// }
|
1994 |
//
|
1995 |
// int tpe = _flds[i].getFieldType();
|
1996 |
// int max_size = OracleSpatialUtils.maxSizeForFieldType(tpe);
|
1997 |
//
|
1998 |
// if (max_size == -1) {
|
1999 |
// return orig_val;
|
2000 |
// }
|
2001 |
//
|
2002 |
// int or_size = orig_val.length();
|
2003 |
//
|
2004 |
// if (or_size <= max_size) {
|
2005 |
// return orig_val;
|
2006 |
// }
|
2007 |
//
|
2008 |
// return orig_val.substring(0, max_size);
|
2009 |
// }
|
2010 |
//
|
2011 |
// private static String avoidQuoteProblem(String str) {
|
2012 |
// return str.replaceAll("'", "''");
|
2013 |
// }
|
2014 |
//
|
2015 |
// private static String getValueSurroundFromType(FieldDescription fieldDesc) {
|
2016 |
// if (NumberUtilities.isNumeric(fieldDesc.getFieldType())) {
|
2017 |
// return "";
|
2018 |
// }
|
2019 |
//
|
2020 |
// return "'";
|
2021 |
// }
|
2022 |
//
|
2023 |
// /**
|
2024 |
// * Utility function to translate a SRS code from EPSG to Oracle.
|
2025 |
// * Uses a datasource based on a DBF file.
|
2026 |
// *
|
2027 |
// * @param epsg the EPSG code
|
2028 |
// * @return the Oracle code
|
2029 |
// */
|
2030 |
// public static String epsgSridToOracleSrid(String _epsg) throws Exception {
|
2031 |
//
|
2032 |
// String epsg = removePrefix(_epsg);
|
2033 |
//
|
2034 |
// String resp = "8307";
|
2035 |
//
|
2036 |
// // --------------------------------------------
|
2037 |
// String sql = "select ORACLE from " + ORACLE_EPSG_TABLE_NAME +
|
2038 |
// " where EPSG = " + epsg + " and PRF_ORACLE = 1;";
|
2039 |
// DataSource ds = null;
|
2040 |
//
|
2041 |
// try {
|
2042 |
// ds = LayerFactory.getDataSourceFactory()
|
2043 |
// .executeSQL(sql,
|
2044 |
// DataSourceFactory.AUTOMATIC_OPENING); //.MANUAL_OPENING);
|
2045 |
//
|
2046 |
// if (ds.getRowCount() == 0) {
|
2047 |
// logger.error("EPSG code not found in table: " + epsg);
|
2048 |
// throw new Exception("Unknown EPSG: " + epsg);
|
2049 |
// }
|
2050 |
//
|
2051 |
// if (ds.getRowCount() > 1) {
|
2052 |
// logger.error("===============");
|
2053 |
// logger.error(
|
2054 |
// "DBF file is wrong: More than one preferred Oracle Spatial code found for EPSG code: " +
|
2055 |
// epsg);
|
2056 |
//
|
2057 |
// for (int i = 0; i < ds.getRowCount(); i++) {
|
2058 |
// int aux = (int) Math.round(((DoubleValue) ds.getRow(i)[0]).doubleValue());
|
2059 |
//
|
2060 |
// if (i == 0) {
|
2061 |
// resp = "" + aux;
|
2062 |
// }
|
2063 |
//
|
2064 |
// logger.error("" + aux);
|
2065 |
// }
|
2066 |
//
|
2067 |
// logger.error("===============");
|
2068 |
//
|
2069 |
// return resp;
|
2070 |
// }
|
2071 |
//
|
2072 |
// resp = "" +
|
2073 |
// Math.round(((DoubleValue) ds.getRow(0)[0]).doubleValue());
|
2074 |
// }
|
2075 |
// catch (Exception pe) {
|
2076 |
// logger.error("Error with SQL statement. " + pe.getMessage());
|
2077 |
// }
|
2078 |
//
|
2079 |
// return resp;
|
2080 |
// }
|
2081 |
//
|
2082 |
// /**
|
2083 |
// * Utility function to translate a SRS code from Oracle to EPSG.
|
2084 |
// * Uses a datasource based on a DBF file.
|
2085 |
// *
|
2086 |
// * @param ora the Oracle code
|
2087 |
// * @return the EPSG code
|
2088 |
// */
|
2089 |
// public static String oracleSridToEpsgSrid(String ora) throws Exception {
|
2090 |
//
|
2091 |
// if (ora == null) return null;
|
2092 |
//
|
2093 |
// String resp = "4326";
|
2094 |
//
|
2095 |
// // --------------------------------------------
|
2096 |
// String sql = "select EPSG from " + ORACLE_EPSG_TABLE_NAME +
|
2097 |
// " where ORACLE = " + ora + ";";
|
2098 |
// DataSource ds = null;
|
2099 |
//
|
2100 |
// try {
|
2101 |
// ds = LayerFactory.getDataSourceFactory()
|
2102 |
// .executeSQL(sql,
|
2103 |
// DataSourceFactory.AUTOMATIC_OPENING);
|
2104 |
//
|
2105 |
// if (ds.getRowCount() == 0) {
|
2106 |
// logger.error("Oracle Spatial code not found in table: " + ora);
|
2107 |
// throw new Exception("Unknown Oracle code: " + ora);
|
2108 |
// }
|
2109 |
//
|
2110 |
// if (ds.getRowCount() > 1) {
|
2111 |
// logger.error("===============");
|
2112 |
// logger.error(
|
2113 |
// "DBF file is wrong: More than one EPSG code found for Oracle Spatial code: " +
|
2114 |
// ora);
|
2115 |
//
|
2116 |
// for (int i = 0; i < ds.getRowCount(); i++) {
|
2117 |
// String aux = "" +
|
2118 |
// Math.round(((DoubleValue) ds.getRow(i)[0]).doubleValue());
|
2119 |
//
|
2120 |
// if (i == 0) {
|
2121 |
// resp = aux;
|
2122 |
// }
|
2123 |
//
|
2124 |
// logger.error("" + aux);
|
2125 |
// }
|
2126 |
//
|
2127 |
// logger.error("===============");
|
2128 |
//
|
2129 |
// return resp;
|
2130 |
// }
|
2131 |
//
|
2132 |
// resp = "" +
|
2133 |
// Math.round(((DoubleValue) ds.getRow(0)[0]).doubleValue());
|
2134 |
// }
|
2135 |
// catch (Exception pe) {
|
2136 |
// logger.error("Error with SQL statement. " + pe.getMessage());
|
2137 |
// }
|
2138 |
//
|
2139 |
// return resp;
|
2140 |
// }
|
2141 |
//
|
2142 |
// /**
|
2143 |
// * This methos creates the datasource used to translate the SRS codes:
|
2144 |
// * EPSG <--> Oracle.
|
2145 |
// *
|
2146 |
// * It's called from several places, so checks that the datasource does not exist.
|
2147 |
// */
|
2148 |
//
|
2149 |
//
|
2150 |
// /**
|
2151 |
// * Utility method to get a valid Oracle identifier (in terms of length)
|
2152 |
// *
|
2153 |
// * @param str Proposed string
|
2154 |
// * @param ind field index of the given field name (used by the method to
|
2155 |
// * improve the renaming)
|
2156 |
// * @return an acceptable oracle identifier.
|
2157 |
// */
|
2158 |
// public static String getValidOracleID(String _str, int ind, boolean force_uppercase) {
|
2159 |
//
|
2160 |
// String str = _str;
|
2161 |
// if (force_uppercase) str = _str.toUpperCase();
|
2162 |
//
|
2163 |
// if (str.length() <= MAX_ID_LENGTH) {
|
2164 |
// return str;
|
2165 |
// }
|
2166 |
//
|
2167 |
// String resp = str.substring(0, MAX_ID_LENGTH - 7);
|
2168 |
// resp = resp + str.substring(MAX_ID_LENGTH - 6, MAX_ID_LENGTH - 5);
|
2169 |
// resp = resp + str.substring(MAX_ID_LENGTH - 4, MAX_ID_LENGTH - 3);
|
2170 |
// resp = resp + str.substring(MAX_ID_LENGTH - 2, MAX_ID_LENGTH - 1);
|
2171 |
// resp = resp + "_" + (ind % 1000);
|
2172 |
//
|
2173 |
// return resp;
|
2174 |
// }
|
2175 |
//
|
2176 |
// private static ArrayList ensureSensibleShell(ArrayList cc) {
|
2177 |
// if (sameCoordinate((Coordinate) cc.get(0),
|
2178 |
// (Coordinate) cc.get(cc.size() - 1))) {
|
2179 |
// if (cc.size() == 2) {
|
2180 |
// ArrayList resp = new ArrayList();
|
2181 |
// resp.add(cc.get(0));
|
2182 |
//
|
2183 |
// Coordinate newcoo = new Coordinate((Coordinate) cc.get(0));
|
2184 |
// newcoo.x = newcoo.x + IRRELEVANT_DISTANCE;
|
2185 |
// resp.add(newcoo);
|
2186 |
//
|
2187 |
// newcoo = new Coordinate((Coordinate) cc.get(0));
|
2188 |
// newcoo.x = newcoo.x + IRRELEVANT_DISTANCE;
|
2189 |
// newcoo.y = newcoo.y - IRRELEVANT_DISTANCE;
|
2190 |
// resp.add(newcoo);
|
2191 |
//
|
2192 |
// resp.add(cc.get(0));
|
2193 |
//
|
2194 |
// return resp;
|
2195 |
// }
|
2196 |
//
|
2197 |
// if (cc.size() == 3) {
|
2198 |
// cc.remove(1);
|
2199 |
//
|
2200 |
// return ensureSensibleShell(cc);
|
2201 |
// }
|
2202 |
//
|
2203 |
// return cc;
|
2204 |
// }
|
2205 |
// else {
|
2206 |
// cc.add(cc.get(0));
|
2207 |
//
|
2208 |
// return cc;
|
2209 |
// }
|
2210 |
// }
|
2211 |
//
|
2212 |
// private static ArrayList ensureSensibleHole(ArrayList cc) {
|
2213 |
// if (sameCoordinate((Coordinate) cc.get(0),
|
2214 |
// (Coordinate) cc.get(cc.size() - 1))) {
|
2215 |
// if (cc.size() == 2) {
|
2216 |
// ArrayList resp = new ArrayList();
|
2217 |
// resp.add(cc.get(0));
|
2218 |
//
|
2219 |
// Coordinate newcoo = new Coordinate((Coordinate) cc.get(0));
|
2220 |
// newcoo.x = newcoo.x - IRRELEVANT_DISTANCE;
|
2221 |
// resp.add(newcoo);
|
2222 |
//
|
2223 |
// newcoo = new Coordinate((Coordinate) cc.get(0));
|
2224 |
// newcoo.x = newcoo.x - IRRELEVANT_DISTANCE;
|
2225 |
// newcoo.y = newcoo.y + IRRELEVANT_DISTANCE;
|
2226 |
// resp.add(newcoo);
|
2227 |
//
|
2228 |
// resp.add(cc.get(0));
|
2229 |
//
|
2230 |
// return resp;
|
2231 |
// }
|
2232 |
//
|
2233 |
// if (cc.size() == 3) {
|
2234 |
// cc.remove(1);
|
2235 |
//
|
2236 |
// return ensureSensibleHole(cc);
|
2237 |
// }
|
2238 |
//
|
2239 |
// return cc;
|
2240 |
// }
|
2241 |
// else {
|
2242 |
// cc.add(cc.get(0));
|
2243 |
//
|
2244 |
// return cc;
|
2245 |
// }
|
2246 |
// }
|
2247 |
//
|
2248 |
// private static ArrayList ensureSensibleLineString(ArrayList cc) {
|
2249 |
// if (cc.size() == 2) {
|
2250 |
// if (sameCoordinate((Coordinate) cc.get(0),
|
2251 |
// (Coordinate) cc.get(cc.size() - 1))) {
|
2252 |
// ArrayList resp = new ArrayList();
|
2253 |
// resp.add(cc.get(0));
|
2254 |
//
|
2255 |
// Coordinate newc = new Coordinate((Coordinate) cc.get(0));
|
2256 |
// newc.x = newc.x + IRRELEVANT_DISTANCE;
|
2257 |
// resp.add(newc);
|
2258 |
//
|
2259 |
// return resp;
|
2260 |
// }
|
2261 |
// }
|
2262 |
//
|
2263 |
// return cc;
|
2264 |
// }
|
2265 |
//
|
2266 |
// private static boolean sameCoordinate(Coordinate c1, Coordinate c2) {
|
2267 |
// if (c1.x != c2.x) {
|
2268 |
// return false;
|
2269 |
// }
|
2270 |
//
|
2271 |
// if (c1.y != c2.y) {
|
2272 |
// return false;
|
2273 |
// }
|
2274 |
//
|
2275 |
// return true;
|
2276 |
// }
|
2277 |
//
|
2278 |
// private static ArrayList getClosedRelevantPolygon(ArrayList cc) {
|
2279 |
// if (cc.size() == 2) {
|
2280 |
// return null;
|
2281 |
// }
|
2282 |
//
|
2283 |
// if (cc.size() == 3) {
|
2284 |
// if (sameCoordinate((Coordinate) cc.get(0), (Coordinate) cc.get(1))) {
|
2285 |
// return null;
|
2286 |
// }
|
2287 |
//
|
2288 |
// if (sameCoordinate((Coordinate) cc.get(0), (Coordinate) cc.get(2))) {
|
2289 |
// return null;
|
2290 |
// }
|
2291 |
//
|
2292 |
// if (sameCoordinate((Coordinate) cc.get(1), (Coordinate) cc.get(2))) {
|
2293 |
// return null;
|
2294 |
// }
|
2295 |
//
|
2296 |
// cc.add(cc.get(0));
|
2297 |
//
|
2298 |
// return cc;
|
2299 |
// }
|
2300 |
//
|
2301 |
// if (!sameCoordinate((Coordinate) cc.get(0),
|
2302 |
// (Coordinate) cc.get(cc.size() - 1))) {
|
2303 |
// cc.add(cc.get(0));
|
2304 |
// }
|
2305 |
//
|
2306 |
// return cc;
|
2307 |
// }
|
2308 |
//
|
2309 |
// private static MultiPolygon getMinMultiPolygon(Coordinate c) {
|
2310 |
// Coordinate[] p = new Coordinate[4];
|
2311 |
// p[0] = c;
|
2312 |
//
|
2313 |
// Coordinate nc = new Coordinate(c);
|
2314 |
// nc.x = nc.x + IRRELEVANT_DISTANCE;
|
2315 |
//
|
2316 |
// Coordinate nc2 = new Coordinate(nc);
|
2317 |
// nc2.y = nc2.y - IRRELEVANT_DISTANCE;
|
2318 |
// p[1] = nc;
|
2319 |
// p[2] = nc2;
|
2320 |
// p[3] = new Coordinate(c);
|
2321 |
//
|
2322 |
// CoordinateArraySequence cs = new CoordinateArraySequence(p);
|
2323 |
// LinearRing ls = new LinearRing(cs, geomFactory);
|
2324 |
// Polygon po = new Polygon(ls, null, geomFactory);
|
2325 |
// Polygon[] pos = new Polygon[1];
|
2326 |
// pos[0] = po;
|
2327 |
//
|
2328 |
// MultiPolygon mpo = new MultiPolygon(pos, geomFactory);
|
2329 |
//
|
2330 |
// return mpo;
|
2331 |
// }
|
2332 |
//
|
2333 |
// public String getSourceProjection(IConnection conn, DBLayerDefinition lyrDef) {
|
2334 |
//
|
2335 |
// String resp = null;
|
2336 |
// try {
|
2337 |
// Statement _st = ((ConnectionJDBC) conn).getConnection().createStatement();
|
2338 |
// String[] tokens = lyrDef.getName().split("\\u002E", 2);
|
2339 |
// String qry;
|
2340 |
// if (tokens.length > 1) {
|
2341 |
// qry = "select * from " + ALL_ORACLE_GEOMETADATA_VIEW +
|
2342 |
// " where OWNER = '" + tokens[0] + "' AND TABLE_NAME = '" +
|
2343 |
// tokens[1] + "'";
|
2344 |
// } else {
|
2345 |
// qry = "select * from " + ALL_ORACLE_GEOMETADATA_VIEW +
|
2346 |
// " where TABLE_NAME = " + "'" + lyrDef.getName() + "'";
|
2347 |
// }
|
2348 |
// ResultSet _rs = _st.executeQuery(qry);
|
2349 |
//
|
2350 |
// if (_rs.next()) {
|
2351 |
// String aux = getOracleSridFromCurrentRecord(_rs);
|
2352 |
// try {
|
2353 |
// resp = oracleSridToEpsgSrid(aux);
|
2354 |
// } catch (Exception e) {
|
2355 |
// logger.error("Unknown oracle SRID: " + aux);
|
2356 |
// }
|
2357 |
// } else {
|
2358 |
//
|
2359 |
// }
|
2360 |
// } catch (Exception ex) {
|
2361 |
// logger.error("While getting Source Projection: " + ex.getMessage());
|
2362 |
// }
|
2363 |
//
|
2364 |
// if (resp != null) {
|
2365 |
// return resp;
|
2366 |
// } else {
|
2367 |
// return getDestProjection();
|
2368 |
// }
|
2369 |
//
|
2370 |
// }
|
2371 |
//
|
2372 |
// public String getDestProjection() {
|
2373 |
// return removePrefix(destProj);
|
2374 |
// }
|
2375 |
//
|
2376 |
// public void setDestProjection(String toEPSG) {
|
2377 |
// destProj = toEPSG;
|
2378 |
// try {
|
2379 |
// destProjOracle = epsgSridToOracleSrid(destProj);
|
2380 |
// isDestGeogCS = OracleSpatialUtils.getIsGCS(destProjOracle, true);
|
2381 |
//
|
2382 |
// } catch (Exception e) {
|
2383 |
// logger.error("Unknown EPSG code: " + destProj);
|
2384 |
// destProjOracle = oracleSRID;
|
2385 |
// isDestGeogCS = false;
|
2386 |
// }
|
2387 |
//
|
2388 |
// }
|
2389 |
//
|
2390 |
// public String getDestProjectionOracleCode() {
|
2391 |
// return destProjOracle;
|
2392 |
// }
|
2393 |
//
|
2394 |
// public boolean getIsDestProjectionGeog() {
|
2395 |
// return isDestGeogCS;
|
2396 |
// }
|
2397 |
//
|
2398 |
// public String getTableProjectionOracleCode() {
|
2399 |
// return oracleSRID;
|
2400 |
// }
|
2401 |
//
|
2402 |
// public boolean canReproject(String toEPSGdestinyProjection) {
|
2403 |
// return false;
|
2404 |
// }
|
2405 |
//
|
2406 |
// /**
|
2407 |
// * Utility function. Says whether a given field name can be a user field name
|
2408 |
// * or not (for example, "ROWID" is not a valid one because it's a system
|
2409 |
// * reserved word).
|
2410 |
// *
|
2411 |
// * @param str proposed firld name
|
2412 |
// * @return whether it is valid or not for Oracle databases
|
2413 |
// */
|
2414 |
// private static boolean isOracleAllowedFieldname(String str) {
|
2415 |
// if (str.compareToIgnoreCase("rowid") == 0) {
|
2416 |
// return false;
|
2417 |
// }
|
2418 |
//
|
2419 |
// if (str.compareToIgnoreCase("rownum") == 0) {
|
2420 |
// return false;
|
2421 |
// }
|
2422 |
//
|
2423 |
// return true;
|
2424 |
// }
|
2425 |
//
|
2426 |
// public Hashtable getHashRelate() {
|
2427 |
// return hashRelate;
|
2428 |
// }
|
2429 |
//
|
2430 |
// public void setHashRelate(Hashtable m) {
|
2431 |
// hashRelate = m;
|
2432 |
// }
|
2433 |
//
|
2434 |
// public void setNumReg(int n) {
|
2435 |
// numReg = n;
|
2436 |
// }
|
2437 |
//
|
2438 |
// private int[] getRandomSample(int maxn_one_based, int n) {
|
2439 |
// int[] resp = new int[n];
|
2440 |
//
|
2441 |
// if (maxn_one_based <= n) {
|
2442 |
// resp = new int[maxn_one_based];
|
2443 |
//
|
2444 |
// for (int i = 0; i < maxn_one_based; i++) {
|
2445 |
// resp[i] = i;
|
2446 |
// }
|
2447 |
// }
|
2448 |
// else {
|
2449 |
// Random rnd = new Random();
|
2450 |
//
|
2451 |
// for (int i = 0; i < n; i++) {
|
2452 |
// resp[i] = rnd.nextInt(maxn_one_based);
|
2453 |
// }
|
2454 |
// }
|
2455 |
//
|
2456 |
// return resp;
|
2457 |
// }
|
2458 |
//
|
2459 |
// private String getRowIdRestrictionCondition(int nrecords) {
|
2460 |
// int[] zero_based_rows = getRandomSample(nrecords,
|
2461 |
// GEODETIC_FULLEXTENT_SAMPLE_SIZE);
|
2462 |
// String resp = "(";
|
2463 |
// Object aux = "";
|
2464 |
// ROWID riaux = null;
|
2465 |
//
|
2466 |
// for (int i = 0; i < zero_based_rows.length; i++) {
|
2467 |
// aux = rowToId.get(new Integer(zero_based_rows[i]));
|
2468 |
// riaux = (ROWID) aux;
|
2469 |
// resp = resp + "(ROWID = '" + riaux.stringValue() + "') OR ";
|
2470 |
// }
|
2471 |
//
|
2472 |
// resp = resp.substring(0, resp.length() - 4);
|
2473 |
// resp = resp + ")";
|
2474 |
//
|
2475 |
// return resp;
|
2476 |
// }
|
2477 |
//
|
2478 |
// private Rectangle2D getBoundingFromSample(int n_max) {
|
2479 |
// String _qry = "SELECT " + geoColName + " FROM " + getTableName() +
|
2480 |
// " WHERE " + getRowIdRestrictionCondition(n_max);
|
2481 |
// STRUCT auxstr = null;
|
2482 |
// IGeometry theGeom = null;
|
2483 |
// Rectangle2D resp = null;
|
2484 |
//
|
2485 |
// try {
|
2486 |
// Statement st = ((ConnectionJDBC)conn).getConnection().createStatement();
|
2487 |
// ResultSet rs = st.executeQuery(_qry);
|
2488 |
//
|
2489 |
// if (rs.next()) {
|
2490 |
// auxstr = (STRUCT) rs.getObject(1);
|
2491 |
//
|
2492 |
// if (auxstr != null) {
|
2493 |
// theGeom = getGeometryUsing(auxstr, use_geotools);
|
2494 |
//
|
2495 |
// if (resp == null) {
|
2496 |
// resp = theGeom.getBounds2D();
|
2497 |
// }
|
2498 |
// else {
|
2499 |
// resp.add(theGeom.getBounds2D());
|
2500 |
// }
|
2501 |
// }
|
2502 |
//
|
2503 |
// while (rs.next()) {
|
2504 |
// auxstr = (STRUCT) rs.getObject(1);
|
2505 |
//
|
2506 |
// if (auxstr != null) {
|
2507 |
// theGeom = getGeometryUsing(auxstr, use_geotools);
|
2508 |
//
|
2509 |
// if (resp == null) {
|
2510 |
// resp = theGeom.getBounds2D();
|
2511 |
// }
|
2512 |
// else {
|
2513 |
// resp.add(theGeom.getBounds2D());
|
2514 |
// }
|
2515 |
// }
|
2516 |
// }
|
2517 |
//
|
2518 |
// rs.close();
|
2519 |
// st.close();
|
2520 |
// }
|
2521 |
// else {
|
2522 |
// throw new SQLException("Empty resultset from this query: " +
|
2523 |
// _qry);
|
2524 |
// }
|
2525 |
// }
|
2526 |
// catch (SQLException se) {
|
2527 |
// logger.error("While getting sample full extent: " +
|
2528 |
// se.getMessage());
|
2529 |
// }
|
2530 |
//
|
2531 |
// if (resp == null) {
|
2532 |
// logger.warn(
|
2533 |
// "Did not find a geometry to compute sample bbox. Returned geographic bbox for whole world.");
|
2534 |
//
|
2535 |
// return new Rectangle2D.Double(-180, -90, 360, 180);
|
2536 |
// }
|
2537 |
//
|
2538 |
// return resp;
|
2539 |
// }
|
2540 |
//
|
2541 |
// /**
|
2542 |
// * Does what it says, puts the LinearRing in counter clock wise
|
2543 |
// * order.
|
2544 |
// * @param ls The ring to set.
|
2545 |
// * @param gf a GeometryFactory object
|
2546 |
// * @return A new ring in CCW order.
|
2547 |
// *
|
2548 |
// */
|
2549 |
// public static LinearRing putInCCWOrderLR(LineString ls, GeometryFactory gf) {
|
2550 |
// Coordinate[] cc = ls.getCoordinates();
|
2551 |
//
|
2552 |
// if (CGAlgorithms.isCCW(cc)) {
|
2553 |
// return gf.createLinearRing(cc);
|
2554 |
// }
|
2555 |
// else {
|
2556 |
// if (ls instanceof LinearRing) {
|
2557 |
// return reverseRing((LinearRing) ls, gf);
|
2558 |
// }
|
2559 |
// else {
|
2560 |
// return reverseLineString(ls, gf);
|
2561 |
// }
|
2562 |
// }
|
2563 |
// }
|
2564 |
//
|
2565 |
// /**
|
2566 |
// * Does what it says, reverses the order of the Coordinates in the ring.
|
2567 |
// * @param lr The ring to reverse.
|
2568 |
// * @return A new ring with the reversed Coordinates.
|
2569 |
// *
|
2570 |
// */
|
2571 |
// public static LinearRing reverseRing(LinearRing lr, GeometryFactory gf) {
|
2572 |
// int numPoints = lr.getNumPoints() - 1;
|
2573 |
// Coordinate[] newCoords = new Coordinate[numPoints + 1];
|
2574 |
//
|
2575 |
// for (int t = numPoints; t >= 0; t--) {
|
2576 |
// newCoords[t] = lr.getCoordinateN(numPoints - t);
|
2577 |
// }
|
2578 |
//
|
2579 |
// return gf.createLinearRing(newCoords);
|
2580 |
// }
|
2581 |
//
|
2582 |
// /**
|
2583 |
// * Does what it says, reverses the order of the Coordinates in the linestring.
|
2584 |
// * @param ls The ls to reverse.
|
2585 |
// * @param gf a GeometryFactory object
|
2586 |
// * @return A new ls with the reversed Coordinates.
|
2587 |
// *
|
2588 |
// */
|
2589 |
// public static LinearRing reverseLineString(LineString ls, GeometryFactory gf) {
|
2590 |
// int numPoints = ls.getNumPoints() - 1;
|
2591 |
// Coordinate[] newCoords = new Coordinate[numPoints + 1];
|
2592 |
//
|
2593 |
// for (int t = numPoints; t >= 0; t--) {
|
2594 |
// newCoords[t] = ls.getCoordinateN(numPoints - t);
|
2595 |
// }
|
2596 |
//
|
2597 |
// return gf.createLinearRing(newCoords);
|
2598 |
// }
|
2599 |
//
|
2600 |
// private static Geometry putInCCWOrder(Geometry ge, GeometryFactory gf) {
|
2601 |
// if (ge instanceof MultiPolygon) {
|
2602 |
// MultiPolygon mp = (MultiPolygon) ge;
|
2603 |
// int size = ge.getNumGeometries();
|
2604 |
// Polygon[] pols = new Polygon[size];
|
2605 |
//
|
2606 |
// for (int i = 0; i < size; i++)
|
2607 |
// pols[i] = (Polygon) putInCCWOrder((Polygon) mp.getGeometryN(i),
|
2608 |
// gf);
|
2609 |
//
|
2610 |
// return new MultiPolygon(pols, gf);
|
2611 |
// }
|
2612 |
// else {
|
2613 |
// if (ge instanceof Polygon) {
|
2614 |
// Polygon p = (Polygon) ge;
|
2615 |
// LinearRing exterior = putInCCWOrderLR(p.getExteriorRing(), gf);
|
2616 |
// int nholes = p.getNumInteriorRing();
|
2617 |
//
|
2618 |
// if (nholes > 0) {
|
2619 |
// LinearRing[] holes = new LinearRing[nholes];
|
2620 |
//
|
2621 |
// for (int i = 0; i < nholes; i++) {
|
2622 |
// holes[i] = putInCCWOrderLR(p.getInteriorRingN(i), gf);
|
2623 |
// }
|
2624 |
//
|
2625 |
// return gf.createPolygon(exterior, holes);
|
2626 |
// }
|
2627 |
// else {
|
2628 |
// return gf.createPolygon(exterior, null);
|
2629 |
// }
|
2630 |
// }
|
2631 |
// else {
|
2632 |
// return ge;
|
2633 |
// }
|
2634 |
// }
|
2635 |
// }
|
2636 |
//
|
2637 |
// /**
|
2638 |
// * Converts from IGeometry to STRUCT
|
2639 |
// *
|
2640 |
// * @param ig the geometry to convert
|
2641 |
// * @param _forced_type forced type to use
|
2642 |
// * @param _conn connection
|
2643 |
// * @param _o_srid SRS (oracle code)
|
2644 |
// * @param withSrid whether this STRUCT has a non-NULL SRS
|
2645 |
// * @param agu_bien whether or not to check the correctness of the holes
|
2646 |
// * @param _isGeoCS whether the SRS is geodetic or not
|
2647 |
// * @return the generated STRUCT
|
2648 |
// */
|
2649 |
// public static STRUCT iGeometryToSTRUCT(IGeometry ig, int _forced_type,
|
2650 |
// IConnection _conn, String _o_srid, boolean withSrid, boolean agu_bien,
|
2651 |
// boolean _isGeoCS) {
|
2652 |
// if (ig instanceof FGeometryCollection) {
|
2653 |
// FGeometryCollection coll = (FGeometryCollection) ig;
|
2654 |
//
|
2655 |
// return OracleSpatialUtils.appendGeometriesInStruct(coll,
|
2656 |
// _forced_type, _conn, _o_srid, withSrid, agu_bien, _isGeoCS);
|
2657 |
//
|
2658 |
// // logger.error("Collections no soportadas por ahora.");
|
2659 |
// // return null;
|
2660 |
// }
|
2661 |
// else {
|
2662 |
// Shape shp = ig.getInternalShape();
|
2663 |
//
|
2664 |
// return shapeToStruct(shp, _forced_type, _conn, _o_srid, withSrid,
|
2665 |
// agu_bien, false, _isGeoCS);
|
2666 |
// }
|
2667 |
// }
|
2668 |
//
|
2669 |
// public STRUCT shapeToStruct(Shape shp, int force_type, boolean hasSrid,
|
2670 |
// boolean agu_bien, boolean isView) {
|
2671 |
//
|
2672 |
// if (shp == null) return null;
|
2673 |
// return shapeToStruct(shp, force_type, conn, oracleSRID, hasSrid,
|
2674 |
// agu_bien, isView, isGeogCS);
|
2675 |
// }
|
2676 |
//
|
2677 |
// public static STRUCT shapeToStruct(Shape shp, int forced_type,
|
2678 |
// IConnection _conn, String o_srid, boolean hasSrid, boolean agu_bien,
|
2679 |
// boolean isView, boolean _isGeoCS) {
|
2680 |
// int _srid = -1;
|
2681 |
//
|
2682 |
// if ((o_srid != null) && (o_srid.length() > 0)) {
|
2683 |
// _srid = Integer.parseInt(o_srid);
|
2684 |
// }
|
2685 |
//
|
2686 |
// if (shp == null) {
|
2687 |
// logger.info("Shape is null. shapeToStruct(Shape) returned null.");
|
2688 |
//
|
2689 |
// return null;
|
2690 |
// }
|
2691 |
//
|
2692 |
// if (shp instanceof Rectangle2D) {
|
2693 |
// return OracleSpatialUtils.rectangleToStruct((Rectangle2D) shp, hasSrid, isView,
|
2694 |
// _isGeoCS, o_srid, _conn);
|
2695 |
// }
|
2696 |
//
|
2697 |
// try {
|
2698 |
// STRUCT the_struct = OracleSpatialUtils.fShapeToSTRUCT(shp, _conn,
|
2699 |
// _srid, agu_bien, hasSrid);
|
2700 |
//
|
2701 |
// return the_struct;
|
2702 |
// }
|
2703 |
// catch (SQLException ex) {
|
2704 |
// logger.error("While creating STRUCT: " + ex.getMessage());
|
2705 |
//
|
2706 |
// return null;
|
2707 |
// }
|
2708 |
// }
|
2709 |
//
|
2710 |
// // -------------------------- not ready yet ----------------
|
2711 |
// public int getRowIndexByFID(IFeature _fid) {
|
2712 |
// if (isNotAvailableYet) {
|
2713 |
// return -1;
|
2714 |
// }
|
2715 |
// else {
|
2716 |
// return super.getRowIndexByFID(_fid);
|
2717 |
// }
|
2718 |
// }
|
2719 |
//
|
2720 |
// public int getShapeCount() throws ReadDriverException {
|
2721 |
// if (isNotAvailableYet) {
|
2722 |
// return 0;
|
2723 |
// }
|
2724 |
// else {
|
2725 |
// return numReg;
|
2726 |
// }
|
2727 |
// }
|
2728 |
//
|
2729 |
// public void setNotAvailableYet(boolean nav) {
|
2730 |
// isNotAvailableYet = nav;
|
2731 |
// }
|
2732 |
//
|
2733 |
// // -------------------------------------------------------
|
2734 |
// // -------------------------------------------------------
|
2735 |
// public String[] getTableNames(IConnection conn, String catalog)
|
2736 |
// throws DBException {
|
2737 |
// try{
|
2738 |
// DatabaseMetaData dbmd = ((ConnectionJDBC)conn).getConnection().getMetaData();
|
2739 |
// String[] types = { "TABLE", "VIEW" };
|
2740 |
// // String[] types = { "VIEW" };
|
2741 |
//
|
2742 |
// ResultSet rs = null;
|
2743 |
// rs = getTableNamesFromTable(dbmd.getTables(catalog, ORACLE_GEO_SCHEMA,
|
2744 |
// ALL_ORACLE_GEOMETADATA_VIEW, types), ((ConnectionJDBC)conn).getConnection());
|
2745 |
//// rs = dbmd.getTables(catalog, ORACLE_GEO_SCHEMA,
|
2746 |
//// ORACLE_GEOMETADATA_VIEW, types);
|
2747 |
// TreeMap ret = new TreeMap();
|
2748 |
//
|
2749 |
// while (rs.next()) {
|
2750 |
// String nomCompleto = rs.getString("OWNER") + "." +rs.getString("TABLE_NAME");
|
2751 |
// ret.put(nomCompleto, nomCompleto);
|
2752 |
// }
|
2753 |
//
|
2754 |
// return (String[]) ret.keySet().toArray(new String[0]);
|
2755 |
// }catch (SQLException e) {
|
2756 |
// throw new DBException(e);
|
2757 |
// }
|
2758 |
// }
|
2759 |
//
|
2760 |
// private ResultSet getTableNamesFromTable(ResultSet res, Connection con)
|
2761 |
// throws SQLException {
|
2762 |
// String tablename = "";
|
2763 |
//
|
2764 |
// if (res.next()) {
|
2765 |
// tablename = res.getString("TABLE_NAME");
|
2766 |
//
|
2767 |
// // debug
|
2768 |
// writeMetaTableToLog(con, tablename);
|
2769 |
//
|
2770 |
// Statement __st = con.createStatement();
|
2771 |
//
|
2772 |
// String sql = "(" + "(select TABLE_NAME from USER_TABLES) " +
|
2773 |
// "union (select VIEW_NAME from USER_VIEWS)) " +
|
2774 |
// "intersect (select TABLE_NAME from " + tablename + ")";
|
2775 |
// sql = "SELECT TABLE_NAME, OWNER FROM " + tablename + "";
|
2776 |
// ResultSet rs = __st.executeQuery(sql);
|
2777 |
//
|
2778 |
// return rs;
|
2779 |
// }
|
2780 |
// else {
|
2781 |
// logger.error("Error while getting geometry tables.");
|
2782 |
//
|
2783 |
// return null;
|
2784 |
// }
|
2785 |
// }
|
2786 |
//
|
2787 |
// private void writeMetaTableToLog(Connection con, String tname) {
|
2788 |
//
|
2789 |
// logger.debug("======================================================");
|
2790 |
// logger.debug("= " + ALL_ORACLE_GEOMETADATA_VIEW + " (1 EVERY 10 TABLES) ========");
|
2791 |
// logger.debug("======================================================");
|
2792 |
//
|
2793 |
// try {
|
2794 |
// Statement _stmt = con.createStatement();
|
2795 |
// String sql = "SELECT * FROM " + tname;
|
2796 |
// ResultSet res = _stmt.executeQuery(sql);
|
2797 |
//
|
2798 |
// int count = 0;
|
2799 |
// while (res.next()) {
|
2800 |
//
|
2801 |
// if ((count % 10) == 0) {
|
2802 |
// logger.debug(
|
2803 |
// "OWNER: " + res.getString("OWNER")
|
2804 |
// + ", TABLE_NAME: " + res.getString("TABLE_NAME")
|
2805 |
// + ", COLUMN_NAME: " + res.getString("COLUMN_NAME")
|
2806 |
// + ", SRID: " + res.getString("SRID"));
|
2807 |
// ARRAY _aux = (ARRAY) res.getObject("DIMINFO");
|
2808 |
// String dinfo = OracleSpatialUtils.getDimInfoAsString(_aux);
|
2809 |
// logger.debug("DIMINFO: " + dinfo);
|
2810 |
// logger.debug("=========");
|
2811 |
// }
|
2812 |
// count++;
|
2813 |
//
|
2814 |
// }
|
2815 |
// } catch (Throwable th) {
|
2816 |
//
|
2817 |
// }
|
2818 |
// }
|
2819 |
//
|
2820 |
// /**
|
2821 |
// * Gets the field names that can act as row id (always ROWID)
|
2822 |
// */
|
2823 |
// public String[] getIdFieldsCandidates(IConnection conn, String table_name)
|
2824 |
// throws DBException {
|
2825 |
// try{
|
2826 |
// String rowid_avail_test = "SELECT ROWID FROM " + table_name + " WHERE ROWNUM = 1";
|
2827 |
// Statement _st = ((ConnectionJDBC)conn).getConnection().createStatement();
|
2828 |
// ResultSet _rs = _st.executeQuery(rowid_avail_test);
|
2829 |
// _rs.close();
|
2830 |
// _st.close();
|
2831 |
//
|
2832 |
// String[] resp = { "ROWID" };
|
2833 |
// return resp;
|
2834 |
// }catch (SQLException e) {
|
2835 |
// throw new DBException(e);
|
2836 |
// }
|
2837 |
// }
|
2838 |
//
|
2839 |
// /**
|
2840 |
// * Gets the field names that can act as geometry fields
|
2841 |
// * (queries the user's geographic metadata).
|
2842 |
// */
|
2843 |
// public String[] getGeometryFieldsCandidates(IConnection conn,
|
2844 |
// String table_name) throws DBException {
|
2845 |
// try{
|
2846 |
// Statement _st = ((ConnectionJDBC)conn).getConnection().createStatement();
|
2847 |
// String[] tokens = table_name.split("\\u002E", 2);
|
2848 |
// String qry;
|
2849 |
// if (tokens.length > 1)
|
2850 |
// {
|
2851 |
// qry = "select * from " + ALL_ORACLE_GEOMETADATA_VIEW +
|
2852 |
// " where OWNER = '" + tokens[0] + "' AND TABLE_NAME = '" +
|
2853 |
// tokens[1] + "'";
|
2854 |
// }
|
2855 |
// else
|
2856 |
// {
|
2857 |
// qry = "select * from " + ALL_ORACLE_GEOMETADATA_VIEW +
|
2858 |
// " where TABLE_NAME = " + "'" + table_name + "'";
|
2859 |
//
|
2860 |
// }
|
2861 |
// ResultSet _rs = _st.executeQuery(qry);
|
2862 |
//
|
2863 |
// ArrayList aux = new ArrayList();
|
2864 |
//
|
2865 |
// while (_rs.next()) {
|
2866 |
// String _geo = _rs.getString("COLUMN_NAME");
|
2867 |
// aux.add(_geo);
|
2868 |
// }
|
2869 |
//
|
2870 |
// _rs.close();
|
2871 |
// _st.close();
|
2872 |
//
|
2873 |
// String[] resp = (String[]) aux.toArray(new String[0]);
|
2874 |
//
|
2875 |
// return checkIndexes(conn, resp, table_name);
|
2876 |
// }catch (SQLException e) {
|
2877 |
// throw new DBException(e);
|
2878 |
// }
|
2879 |
// }
|
2880 |
//
|
2881 |
// private String[] checkIndexes(IConnection c, String[] all, String long_table_name) throws DBException {
|
2882 |
//
|
2883 |
// ArrayList good_ones = new ArrayList();
|
2884 |
// try{
|
2885 |
// String t = long_table_name;
|
2886 |
// if (t.lastIndexOf(".") != -1) t = t.substring(t.lastIndexOf(".") + 1, t.length());
|
2887 |
//
|
2888 |
// for (int i=0; i<all.length; i++) {
|
2889 |
//
|
2890 |
// String qry = "SELECT SRID, DIMINFO FROM " + ALL_ORACLE_GEOMETADATA_VIEW +
|
2891 |
// " WHERE TABLE_NAME = " + "'" + t.toUpperCase() +
|
2892 |
// "' AND COLUMN_NAME = '" + all[i].toUpperCase() + "'";
|
2893 |
//
|
2894 |
// Statement _st = ((ConnectionJDBC)c).getConnection().createStatement();
|
2895 |
// ResultSet _rs = _st.executeQuery(qry);
|
2896 |
// if (_rs.next()) {
|
2897 |
// String _srid = toString((BigDecimal) _rs.getObject(1));
|
2898 |
// ARRAY diminfo = (ARRAY) _rs.getObject(2);
|
2899 |
// int len = diminfo.getOracleArray().length;
|
2900 |
// if (allowsGeoQueries(((ConnectionJDBC)c).getConnection(), long_table_name, all[i], _srid, len)) {
|
2901 |
// good_ones.add(all[i]);
|
2902 |
// }
|
2903 |
// }
|
2904 |
// _rs.close();
|
2905 |
// _st.close();
|
2906 |
// }
|
2907 |
//
|
2908 |
// if (good_ones.size() == 0) {
|
2909 |
// throw new SQLException("no_indexes_on_declared_geo_fields");
|
2910 |
// }
|
2911 |
// }catch (SQLException e) {
|
2912 |
// throw new DBException(e);
|
2913 |
// }
|
2914 |
// return (String[]) good_ones.toArray(new String[0]);
|
2915 |
// }
|
2916 |
//
|
2917 |
// private String toString(BigDecimal number) {
|
2918 |
//
|
2919 |
// if (number == null) return "NULL";
|
2920 |
// return "" + number.intValue();
|
2921 |
// }
|
2922 |
//
|
2923 |
// private boolean allowsGeoQueries(Connection c, String _t, String gf, String _srid, int dims) {
|
2924 |
// String p = getPointConstructor(dims, _srid);
|
2925 |
// String qry = "";
|
2926 |
// qry = "SELECT * FROM " + _t.toUpperCase()
|
2927 |
// + " WHERE SDO_RELATE(" + "\"" + gf + "\", " + p + ", 'mask=TOUCH') = 'TRUE'"
|
2928 |
// + " AND ROWNUM = 1";
|
2929 |
//
|
2930 |
// try {
|
2931 |
// Statement _st = c.createStatement();
|
2932 |
// ResultSet _rs = _st.executeQuery(qry);
|
2933 |
// _rs.close();
|
2934 |
// _st.close();
|
2935 |
// } catch (Exception ex) {
|
2936 |
// return false;
|
2937 |
// }
|
2938 |
// return true;
|
2939 |
// }
|
2940 |
//
|
2941 |
// private String getPointConstructor(int dims, String _srid) {
|
2942 |
//
|
2943 |
// String coord = "";
|
2944 |
// for (int i=0; i<dims; i++) coord = coord + "0, ";
|
2945 |
// coord = coord.substring(0, coord.length() - 2);
|
2946 |
//
|
2947 |
// return "MDSYS.SDO_GEOMETRY(" + (dims * 1000 + 1) + ", " + _srid + ", NULL, " +
|
2948 |
// "MDSYS.SDO_ELEM_INFO_ARRAY(1, 1, 1), MDSYS.SDO_ORDINATE_ARRAY(" + coord + "))";
|
2949 |
// }
|
2950 |
//
|
2951 |
// private boolean stringInArrayListOfStrings(ArrayList l, String str) {
|
2952 |
//
|
2953 |
// if (l == null) return false;
|
2954 |
// if (str == null) return false;
|
2955 |
//
|
2956 |
// String item = "";
|
2957 |
// for (int i=0; i<l.size(); i++) {
|
2958 |
// if (l.get(i) instanceof String) {
|
2959 |
// item = (String) l.get(i);
|
2960 |
// if (item.compareToIgnoreCase(str) == 0) return true;
|
2961 |
// }
|
2962 |
// }
|
2963 |
// return false;
|
2964 |
// }
|
2965 |
//
|
2966 |
// /**
|
2967 |
// * Utility method to check if a given table is empty.
|
2968 |
// */
|
2969 |
// public boolean isEmptyTable(Connection conn, String tableName) {
|
2970 |
// boolean res = true;
|
2971 |
//
|
2972 |
// try {
|
2973 |
// Statement st = conn.createStatement();
|
2974 |
// ResultSet rs = null;
|
2975 |
// rs = st.executeQuery("select * from " + tableName +
|
2976 |
// " where rownum = 1");
|
2977 |
// res = !rs.next();
|
2978 |
// rs.close();
|
2979 |
// st.close();
|
2980 |
// }
|
2981 |
// catch (Exception ex) {
|
2982 |
// res = true;
|
2983 |
// }
|
2984 |
//
|
2985 |
// return res;
|
2986 |
// }
|
2987 |
//
|
2988 |
// /**
|
2989 |
// * Gets all the fields from a table name.
|
2990 |
// */
|
2991 |
// public String[] getAllFields(IConnection conn, String table_name)
|
2992 |
// throws DBException {
|
2993 |
// try{
|
2994 |
// Statement st = ((ConnectionJDBC)conn).getConnection().createStatement();
|
2995 |
// ResultSet rs = st.executeQuery("select * from " + table_name +
|
2996 |
// " where rownum = 1");
|
2997 |
// ResultSetMetaData rsmd = rs.getMetaData();
|
2998 |
// String[] ret = new String[rsmd.getColumnCount()];
|
2999 |
//
|
3000 |
// for (int i = 0; i < ret.length; i++) {
|
3001 |
// ret[i] = rsmd.getColumnName(i + 1);
|
3002 |
// }
|
3003 |
//
|
3004 |
// rs.close();
|
3005 |
// st.close();
|
3006 |
//
|
3007 |
// return ret;
|
3008 |
// }catch (SQLException e) {
|
3009 |
// throw new DBException(e);
|
3010 |
// }
|
3011 |
// }
|
3012 |
//
|
3013 |
// /**
|
3014 |
// * Gets all field type names from a table.
|
3015 |
// */
|
3016 |
// public String[] getAllFieldTypeNames(IConnection conn, String table_name)
|
3017 |
// throws DBException {
|
3018 |
// try{
|
3019 |
// Statement st = ((ConnectionJDBC)conn).getConnection().createStatement();
|
3020 |
// ResultSet rs = st.executeQuery("select * from " + table_name +
|
3021 |
// " where rownum = 1");
|
3022 |
// ResultSetMetaData rsmd = rs.getMetaData();
|
3023 |
// String[] ret = new String[rsmd.getColumnCount()];
|
3024 |
//
|
3025 |
// for (int i = 0; i < ret.length; i++) {
|
3026 |
// if (rsmd.getColumnType(i + 1) == Types.NUMERIC) {
|
3027 |
// int scale = rsmd.getScale(i+1);
|
3028 |
// if (scale >= 0) {
|
3029 |
// String prec_dec = " (" + rsmd.getPrecision(i+1) + ", " + scale + ")";
|
3030 |
// ret[i] = rsmd.getColumnTypeName(i + 1) + prec_dec;
|
3031 |
// } else {
|
3032 |
// ret[i] = rsmd.getColumnTypeName(i + 1);
|
3033 |
// }
|
3034 |
// } else {
|
3035 |
// ret[i] = rsmd.getColumnTypeName(i + 1);
|
3036 |
// }
|
3037 |
// }
|
3038 |
//
|
3039 |
// rs.close();
|
3040 |
// st.close();
|
3041 |
//
|
3042 |
// close();
|
3043 |
//
|
3044 |
// return ret;
|
3045 |
// }catch (SQLException e) {
|
3046 |
// throw new DBException(e);
|
3047 |
// }
|
3048 |
// }
|
3049 |
//
|
3050 |
// /**
|
3051 |
// * Gets Oracle's specific connection string for the given parameters.
|
3052 |
// */
|
3053 |
// public String getConnectionString(String host, String port, String dbname,
|
3054 |
// String user, String pw) {
|
3055 |
// String _pw = pw;
|
3056 |
//
|
3057 |
// if (_pw == null) {
|
3058 |
// _pw = "null";
|
3059 |
// }
|
3060 |
//
|
3061 |
// String fullstr = CONN_STR_BEGIN;
|
3062 |
// fullstr = fullstr + user.toLowerCase() + "/" + _pw;
|
3063 |
// fullstr = fullstr + "@" + host.toLowerCase();
|
3064 |
// fullstr = fullstr + ":" + port;
|
3065 |
// fullstr = fullstr + ":" + dbname.toLowerCase();
|
3066 |
//
|
3067 |
// return fullstr;
|
3068 |
// }
|
3069 |
//
|
3070 |
// /**
|
3071 |
// * Gets the Pracle geometries writer associated with this driver.
|
3072 |
// */
|
3073 |
// public IWriter getWriter() {
|
3074 |
// // on(VectorialEditableDBAdapter.java:290)
|
3075 |
// if (writer == null) {
|
3076 |
//
|
3077 |
// long count = 0;
|
3078 |
// try {
|
3079 |
// count = getRowCount();
|
3080 |
// } catch (ReadDriverException e1) {
|
3081 |
// logger.error("While getting row count: " + e1.getMessage());
|
3082 |
// }
|
3083 |
//
|
3084 |
// writer = new OracleSpatialWriter(count);
|
3085 |
// writer.setDriver(this);
|
3086 |
// writer.setLyrShapeType(getShapeType());
|
3087 |
// writer.setGeoCS(isGeogCS());
|
3088 |
// writer.setGeoColName(geoColName);
|
3089 |
// writer.setSRID(oracleSRID);
|
3090 |
//
|
3091 |
// try {
|
3092 |
// DBLayerDefinition db_lyr_def = getLyrDef();
|
3093 |
// if (db_lyr_def == null) {
|
3094 |
// logger.warn("Found a null DB layer definition, method initialize of OracleWriter not called.");
|
3095 |
// } else {
|
3096 |
// writer.initialize(getLyrDef());
|
3097 |
// }
|
3098 |
//
|
3099 |
// } catch (InitializeWriterException e) {
|
3100 |
// logger.error("While initializing OS Writer: " + e.getMessage(), e);
|
3101 |
// }
|
3102 |
//
|
3103 |
// writer.setStoreWithSrid(tableHasSrid);
|
3104 |
// }
|
3105 |
//
|
3106 |
// return writer;
|
3107 |
// }
|
3108 |
//
|
3109 |
// /**
|
3110 |
// * Tells whether the SRS is geodetic or not-
|
3111 |
// * @return whether the SRS is geodetic or not
|
3112 |
// */
|
3113 |
// public boolean isGeogCS() {
|
3114 |
// return isGeogCS;
|
3115 |
// }
|
3116 |
//
|
3117 |
// /**
|
3118 |
// * Adds a row id to the inner set od IDs.
|
3119 |
// * @param id
|
3120 |
// */
|
3121 |
// public void addRow(String id) {
|
3122 |
// Value aux = ValueFactory.createValue(id);
|
3123 |
// Integer intobj = new Integer(numReg);
|
3124 |
// hashRelate.put(aux, intobj);
|
3125 |
// rowToId.put(intobj, id);
|
3126 |
//
|
3127 |
// numReg++;
|
3128 |
// }
|
3129 |
//
|
3130 |
// /**
|
3131 |
// * Removes a row id to the inner set od IDs.
|
3132 |
// * @param id
|
3133 |
// */
|
3134 |
// public void deleteRow(String id) {
|
3135 |
// Value aux = ValueFactory.createValue(id);
|
3136 |
// Integer intobj = (Integer) hashRelate.get(aux);
|
3137 |
// hashRelate.remove(aux);
|
3138 |
// rowToId.remove(intobj);
|
3139 |
//
|
3140 |
// numReg--;
|
3141 |
// }
|
3142 |
//
|
3143 |
// private String getStandardSelectExpression() {
|
3144 |
//
|
3145 |
// String resp = "";
|
3146 |
//
|
3147 |
// String[] flds = getLyrDef().getFieldNames();
|
3148 |
// int size = flds.length;
|
3149 |
//
|
3150 |
// for (int i = 0; i < size; i++) {
|
3151 |
// if (i > 0) {
|
3152 |
// resp = resp + "c.\"" + flds[i] + "\", ";
|
3153 |
// } else {
|
3154 |
// resp = resp + flds[i] + ", ";
|
3155 |
// }
|
3156 |
// }
|
3157 |
//
|
3158 |
// resp = resp.substring(0, resp.length() - 2);
|
3159 |
// return resp;
|
3160 |
// }
|
3161 |
//
|
3162 |
// /**
|
3163 |
// * Allows the method to decide what to do with the geometry field name
|
3164 |
// * (remove/add it from the user selected fields).
|
3165 |
// *
|
3166 |
// * @param flds
|
3167 |
// * @param geof
|
3168 |
// * @return the possibly modified field names
|
3169 |
// */
|
3170 |
// public String[] manageGeometryField(String[] flds, String geof) {
|
3171 |
// return addEndIfNotContained(flds, geof);
|
3172 |
// }
|
3173 |
//
|
3174 |
// /**
|
3175 |
// * Allows the method to decide what to do with the ID field name
|
3176 |
// * (remove/add it from the user selected fields).
|
3177 |
// *
|
3178 |
// * @param flds
|
3179 |
// * @param idf
|
3180 |
// * @return the possibly modified field names
|
3181 |
// */
|
3182 |
// public String[] manageIdField(String[] flds, String idf) {
|
3183 |
// return addStartIfNotContained(flds, idf);
|
3184 |
// }
|
3185 |
//
|
3186 |
// private String[] addEndIfNotContained(String[] arr, String item) {
|
3187 |
// if (contains(arr, item)) {
|
3188 |
// return arr;
|
3189 |
// }
|
3190 |
// else {
|
3191 |
// int size = arr.length;
|
3192 |
// String[] resp = new String[size + 1];
|
3193 |
//
|
3194 |
// for (int i = 0; i < size; i++) {
|
3195 |
// resp[i] = arr[i];
|
3196 |
// }
|
3197 |
//
|
3198 |
// resp[size] = item;
|
3199 |
//
|
3200 |
// return resp;
|
3201 |
// }
|
3202 |
// }
|
3203 |
//
|
3204 |
// private String[] addStartIfNotContained(String[] arr, String item) {
|
3205 |
// if (contains(arr, item)) {
|
3206 |
// return arr;
|
3207 |
// }
|
3208 |
// else {
|
3209 |
// int size = arr.length;
|
3210 |
// String[] resp = new String[size + 1];
|
3211 |
//
|
3212 |
// for (int i = 1; i <= size; i++) {
|
3213 |
// resp[i] = arr[i];
|
3214 |
// }
|
3215 |
//
|
3216 |
// resp[0] = item;
|
3217 |
//
|
3218 |
// return resp;
|
3219 |
// }
|
3220 |
// }
|
3221 |
//
|
3222 |
// private boolean contains(String[] arr, String item) {
|
3223 |
// for (int i = 0; i < arr.length; i++) {
|
3224 |
// if (arr[i].compareTo(item) == 0) {
|
3225 |
// return true;
|
3226 |
// }
|
3227 |
// }
|
3228 |
//
|
3229 |
// return false;
|
3230 |
// }
|
3231 |
//
|
3232 |
// /**
|
3233 |
// * This method is called when the user removes the layer from the view.
|
3234 |
// * If the IDs were being loaded, the driver will check this field and will
|
3235 |
// * let the thread 'die' quietly.
|
3236 |
// *
|
3237 |
// */
|
3238 |
// public void remove() {
|
3239 |
// cancelIDLoad = true;
|
3240 |
// }
|
3241 |
//
|
3242 |
// private boolean realiableExtent(Rectangle2D ext, boolean isgeodetic) {
|
3243 |
// // if (!isgeodetic) return true;
|
3244 |
// if ((ext.getMinX() > -179.9) || (ext.getMinX() < -180.1)) return true;
|
3245 |
// if ((ext.getMinY() > -89.9) || (ext.getMinY() < -90.1)) return true;
|
3246 |
// if ((ext.getWidth() < 359.9) || (ext.getWidth() > 360.1)) return true;
|
3247 |
// if ((ext.getHeight() < 179.9) || (ext.getHeight() > 180.1)) return true;
|
3248 |
// return false;
|
3249 |
// }
|
3250 |
//
|
3251 |
// private Rectangle2D getFastEstimatedExtent(
|
3252 |
// String tname,
|
3253 |
// String gfield,
|
3254 |
// IConnection c,
|
3255 |
// int sample_size,
|
3256 |
// double enlargement,
|
3257 |
// boolean is_geo) {
|
3258 |
//
|
3259 |
// Rectangle2D world = new Rectangle2D.Double(-180, -90, 360, 180);
|
3260 |
// Rectangle2D resp_aux = null;
|
3261 |
// String qry = "SELECT " + gfield + " FROM " + tname + " WHERE ROWNUM <= " + sample_size;
|
3262 |
// ResultSet _rs = null;
|
3263 |
//
|
3264 |
// try {
|
3265 |
// PreparedStatement _st = ((ConnectionJDBC)c).getConnection().prepareStatement(qry);
|
3266 |
// _rs = _st.executeQuery();
|
3267 |
// while (_rs.next()) {
|
3268 |
// STRUCT aux = (STRUCT) _rs.getObject(1);
|
3269 |
// IGeometry ig = getGeometryUsing(aux, false);
|
3270 |
//
|
3271 |
// if (ig == null) continue;
|
3272 |
//
|
3273 |
// if (resp_aux == null) {
|
3274 |
// resp_aux = ig.getBounds2D();
|
3275 |
// } else {
|
3276 |
// resp_aux.add(ig.getBounds2D());
|
3277 |
// }
|
3278 |
//
|
3279 |
// }
|
3280 |
// } catch (Exception ex) {
|
3281 |
// logger.error("While getting random sample: " + ex.getMessage());
|
3282 |
// }
|
3283 |
//
|
3284 |
// if (resp_aux == null) {
|
3285 |
// logger.warn("ERROR, ESTIMATED BB = WORLD");
|
3286 |
// return world;
|
3287 |
// }
|
3288 |
//
|
3289 |
// double w = resp_aux.getWidth();
|
3290 |
// double h = resp_aux.getHeight();
|
3291 |
// double x = resp_aux.getMinX();
|
3292 |
// double y = resp_aux.getMinY();
|
3293 |
//
|
3294 |
// // enlarge n times:
|
3295 |
// double newx = x - (0.5 * (enlargement - 1)) * w;
|
3296 |
// double newy = y - (0.5 * (enlargement - 1)) * h;
|
3297 |
// Rectangle2D resp_aux_large = new Rectangle2D.Double(newx, newy,
|
3298 |
// enlargement * w,
|
3299 |
// enlargement * h);
|
3300 |
//
|
3301 |
// if (is_geo) {
|
3302 |
// Rectangle2D.intersect(world, resp_aux_large, resp_aux);
|
3303 |
// logger.debug("FAST BB: " + resp_aux.toString());
|
3304 |
// return resp_aux;
|
3305 |
// } else {
|
3306 |
// logger.debug("FAST BB: " + resp_aux_large.toString());
|
3307 |
// return resp_aux_large;
|
3308 |
// }
|
3309 |
//
|
3310 |
// }
|
3311 |
//
|
3312 |
// private Rectangle2D getEstimatedExtent(
|
3313 |
// String tname,
|
3314 |
// String gfield,
|
3315 |
// IConnection c,
|
3316 |
// int sample_size,
|
3317 |
// double enlargement,
|
3318 |
// boolean is_geo) {
|
3319 |
//
|
3320 |
// Rectangle2D world = new Rectangle2D.Double(-180, -90, 360, 180);
|
3321 |
//
|
3322 |
// ArrayList ids = new ArrayList();
|
3323 |
// int _rnd_index = 0;
|
3324 |
// ROWID _id = null;
|
3325 |
// Random rnd = new Random(System.currentTimeMillis());
|
3326 |
//
|
3327 |
// for (int i=0; i<sample_size; i++) {
|
3328 |
// _rnd_index = rnd.nextInt(numReg);
|
3329 |
// _id = (ROWID) rowToId.get(new Integer((int) _rnd_index));
|
3330 |
// ids.add(_id.stringValue());
|
3331 |
// }
|
3332 |
//
|
3333 |
// String qry = "SELECT " + gfield + " FROM " + tname + " WHERE (";
|
3334 |
// for (int i=0; i<ids.size(); i++) {
|
3335 |
// qry = qry + "(ROWID = '" + ((String) ids.get(i)) + "') OR ";
|
3336 |
// }
|
3337 |
// qry = qry.substring(0, qry.length() - 4) + ")";
|
3338 |
//
|
3339 |
// Rectangle2D resp_aux = null;
|
3340 |
// ResultSet _rs = null;
|
3341 |
//
|
3342 |
// try {
|
3343 |
// PreparedStatement _st = ((ConnectionJDBC)c).getConnection().prepareStatement(qry);
|
3344 |
// _rs = _st.executeQuery();
|
3345 |
// while (_rs.next()) {
|
3346 |
// STRUCT aux = (STRUCT) _rs.getObject(1);
|
3347 |
// IGeometry ig = getGeometryUsing(aux, false);
|
3348 |
//
|
3349 |
// if (ig == null) continue;
|
3350 |
//
|
3351 |
// if (resp_aux == null) {
|
3352 |
// resp_aux = ig.getBounds2D();
|
3353 |
// } else {
|
3354 |
// resp_aux.add(ig.getBounds2D());
|
3355 |
// }
|
3356 |
//
|
3357 |
// }
|
3358 |
// } catch (Exception ex) {
|
3359 |
// logger.error("While getting random sample: " + ex.getMessage());
|
3360 |
// }
|
3361 |
//
|
3362 |
// if (resp_aux == null) {
|
3363 |
// logger.warn("ERROR, ESTIMATED BB = WORLD");
|
3364 |
// return world;
|
3365 |
// }
|
3366 |
//
|
3367 |
// double w = resp_aux.getWidth();
|
3368 |
// double h = resp_aux.getHeight();
|
3369 |
// double x = resp_aux.getMinX();
|
3370 |
// double y = resp_aux.getMinY();
|
3371 |
//
|
3372 |
// // enlarge 10 times:
|
3373 |
// double newx = x - (0.5 * (enlargement - 1)) * w;
|
3374 |
// double newy = y - (0.5 * (enlargement - 1)) * h;
|
3375 |
// Rectangle2D resp_aux_large = new Rectangle2D.Double(newx, newy,
|
3376 |
// enlargement * w,
|
3377 |
// enlargement * h);
|
3378 |
//
|
3379 |
// if (is_geo) {
|
3380 |
// Rectangle2D.intersect(world, resp_aux_large, resp_aux);
|
3381 |
// logger.debug("ESTIMATED BB: " + resp_aux.toString());
|
3382 |
// return resp_aux;
|
3383 |
// } else {
|
3384 |
// logger.debug("ESTIMATED BB: " + resp_aux_large.toString());
|
3385 |
// return resp_aux_large;
|
3386 |
// }
|
3387 |
//
|
3388 |
// }
|
3389 |
//
|
3390 |
// public void setUserName(String u) {
|
3391 |
// userName = u;
|
3392 |
// }
|
3393 |
//
|
3394 |
// public String getUserName() {
|
3395 |
// return userName;
|
3396 |
// }
|
3397 |
//
|
3398 |
// public static final int JGeometry_GTYPE_COLLECTION = 4;
|
3399 |
// public static final int JGeometry_GTYPE_CURVE = 2;
|
3400 |
// public static final int JGeometry_GTYPE_MULTICURVE = 6;
|
3401 |
// public static final int JGeometry_GTYPE_MULTIPOINT = 5;
|
3402 |
// public static final int JGeometry_GTYPE_MULTIPOLYGON = 7;
|
3403 |
// public static final int JGeometry_GTYPE_POINT = 1;
|
3404 |
// public static final int JGeometry_GTYPE_POLYGON = 3;
|
3405 |
//
|
3406 |
//
|
3407 |
// // ------------------------------
|
3408 |
//
|
3409 |
// public void setXMLEntity(XMLEntity xml) throws XMLException {
|
3410 |
//
|
3411 |
// super.setXMLEntity(xml);
|
3412 |
// workingAreaInTablesCS = workingArea;
|
3413 |
//
|
3414 |
// try {
|
3415 |
// int[] ftypes = xml.getIntArrayProperty("fieldTypes");
|
3416 |
// setLyrDefFieldTypes(ftypes);
|
3417 |
// } catch (Exception ex) {
|
3418 |
// logger.warn("Apparently, an old GVP file has been opened," +
|
3419 |
// " field type values are not accurate after this point.");
|
3420 |
// }
|
3421 |
//
|
3422 |
// }
|
3423 |
//
|
3424 |
// public XMLEntity getXMLEntity() {
|
3425 |
// // ---------------------
|
3426 |
//
|
3427 |
// XMLEntity xml = new XMLEntity();
|
3428 |
// xml.putProperty("className", getClass().getName());
|
3429 |
//
|
3430 |
// xml.putProperty("catalog", getLyrDef().getCatalogName());
|
3431 |
//
|
3432 |
// int aux = userName.indexOf("@");
|
3433 |
// if (aux != -1)
|
3434 |
// userName = userName.substring(0, aux);
|
3435 |
// xml.putProperty("username", userName);
|
3436 |
//
|
3437 |
// xml.putProperty("driverclass", ORACLE_JAR_FILE_NAME);
|
3438 |
//
|
3439 |
// xml.putProperty("tablename", getTableName());
|
3440 |
// xml.putProperty("fields", lyrDef.getFieldNames());
|
3441 |
// xml.putProperty("fieldTypes", getLyrDefFieldTypes());
|
3442 |
// xml.putProperty("FID", lyrDef.getFieldID());
|
3443 |
// xml.putProperty("THE_GEOM", lyrDef.getFieldGeometry());
|
3444 |
// xml.putProperty("whereclause", getWhereClause());
|
3445 |
// xml.putProperty("SRID", lyrDef.getSRID_EPSG());
|
3446 |
//
|
3447 |
// xml.putProperty("host", host);
|
3448 |
// xml.putProperty("port", port);
|
3449 |
// xml.putProperty("dbName", dbName);
|
3450 |
// xml.putProperty("connName", connName);
|
3451 |
//
|
3452 |
// if (workingAreaInTablesCS != null) {
|
3453 |
// xml.putProperty("minXworkArea", workingAreaInTablesCS.getMinX());
|
3454 |
// xml.putProperty("minYworkArea", workingAreaInTablesCS.getMinY());
|
3455 |
// xml.putProperty("HworkArea", workingAreaInTablesCS.getHeight());
|
3456 |
// xml.putProperty("WworkArea", workingAreaInTablesCS.getWidth());
|
3457 |
// }
|
3458 |
//
|
3459 |
// return xml;
|
3460 |
// }
|
3461 |
//
|
3462 |
// private int[] getLyrDefFieldTypes() {
|
3463 |
// FieldDescription[] fd = lyrDef.getFieldsDesc();
|
3464 |
// int sz = fd.length;
|
3465 |
// int[] resp = new int[sz];
|
3466 |
// for (int i=0; i<sz; i++) resp[i] = fd[i].getFieldType();
|
3467 |
// return resp;
|
3468 |
// }
|
3469 |
//
|
3470 |
// private void setLyrDefFieldTypes(int[] tt) {
|
3471 |
// FieldDescription[] fd = lyrDef.getFieldsDesc();
|
3472 |
//
|
3473 |
// int sz_fd = fd.length;
|
3474 |
// int sz_tt = tt.length;
|
3475 |
// int sz = sz_tt;
|
3476 |
//
|
3477 |
// if (sz_tt != sz_fd) {
|
3478 |
// logger.error("Field count does not match. lyrDef has " + sz_fd + " fields," +
|
3479 |
// " but this method was called with " + sz_tt + " items (?)");
|
3480 |
// sz = Math.min(sz_fd, sz_tt);
|
3481 |
// }
|
3482 |
//
|
3483 |
// for (int i=0; i<sz; i++) lyrDef.getFieldsDesc()[i].setFieldType(tt[i]);
|
3484 |
// }
|
3485 |
//
|
3486 |
// public String[] getTableFields(IConnection conex, String table) throws DBException {
|
3487 |
// try{
|
3488 |
// Statement st = ((ConnectionJDBC)conex).getConnection().createStatement();
|
3489 |
// // ResultSet rs = dbmd.getTables(catalog, null, dbLayerDefinition.getTable(), null);
|
3490 |
// ResultSet rs = st.executeQuery("select * from " + table + " LIMIT 1");
|
3491 |
// ResultSetMetaData rsmd = rs.getMetaData();
|
3492 |
//
|
3493 |
// String[] ret = new String[rsmd.getColumnCount()];
|
3494 |
//
|
3495 |
// for (int i = 0; i < ret.length; i++) {
|
3496 |
// ret[i] = rsmd.getColumnName(i+1);
|
3497 |
// }
|
3498 |
//
|
3499 |
// return ret;
|
3500 |
// }catch (SQLException e) {
|
3501 |
// throw new DBException(e);
|
3502 |
// }
|
3503 |
// }
|
3504 |
//
|
3505 |
// // Overwritten to keep old behavior: returns "schema.table_name" if
|
3506 |
// // schema is not current user
|
3507 |
// public String getTableName() {
|
3508 |
// return fullTableName;
|
3509 |
// }
|
3510 |
//
|
3511 |
// private Timestamp flexibleTimeStamp(String s) {
|
3512 |
//
|
3513 |
// String aux = s.replace('-', ' ');
|
3514 |
// aux = aux.replace(':', ' ');
|
3515 |
// aux = aux.replace('.', ' ');
|
3516 |
// // sample: 2007 12 31 23 59 59 9999
|
3517 |
// String[] parts = aux.trim().split(" ");
|
3518 |
//
|
3519 |
// int year;
|
3520 |
// int month;
|
3521 |
// int day;
|
3522 |
// int hour;
|
3523 |
// int minute;
|
3524 |
// int second;
|
3525 |
// int a_nanos;
|
3526 |
//
|
3527 |
// if (parts.length == 7) {
|
3528 |
//
|
3529 |
// try {
|
3530 |
//
|
3531 |
// year = Integer.parseInt(parts[0]) - 1900;
|
3532 |
// month = Integer.parseInt(parts[1]) - 1;
|
3533 |
// day = Integer.parseInt(parts[2]);
|
3534 |
// hour = Integer.parseInt(parts[3]);
|
3535 |
// minute = Integer.parseInt(parts[4]);
|
3536 |
// second = Integer.parseInt(parts[5]);
|
3537 |
// a_nanos = Integer.parseInt(parts[6]);
|
3538 |
//
|
3539 |
// } catch (Exception ex) {
|
3540 |
// logger.debug("Bad time stamp: " + ex.getMessage());
|
3541 |
// return new Timestamp(1970, 1, 1, 0, 0, 0, 0);
|
3542 |
// }
|
3543 |
//
|
3544 |
// } else {
|
3545 |
//
|
3546 |
// if (parts.length == 6) {
|
3547 |
//
|
3548 |
// try {
|
3549 |
// year = Integer.parseInt(parts[0]) - 1900;
|
3550 |
// month = Integer.parseInt(parts[1]) - 1;
|
3551 |
// day = Integer.parseInt(parts[2]);
|
3552 |
// hour = Integer.parseInt(parts[3]);
|
3553 |
// minute = Integer.parseInt(parts[4]);
|
3554 |
// second = Integer.parseInt(parts[5]);
|
3555 |
// a_nanos = 0;
|
3556 |
//
|
3557 |
// } catch (Exception ex) {
|
3558 |
//
|
3559 |
// logger.debug("Bad time stamp: " + ex.getMessage());
|
3560 |
// return new Timestamp(1970, 1, 1, 0, 0, 0, 0);
|
3561 |
// }
|
3562 |
//
|
3563 |
// } else {
|
3564 |
//
|
3565 |
// logger.debug("Bad time stamp: " + s);
|
3566 |
// return new Timestamp(1970, 1, 1, 0, 0, 0, 0);
|
3567 |
//
|
3568 |
// }
|
3569 |
// }
|
3570 |
//
|
3571 |
// return new Timestamp(year, month, day, hour, minute, second, a_nanos);
|
3572 |
// }
|
3573 |
//
|
3574 |
// public void write(DataWare arg0) throws WriteDriverException, ReadDriverException {
|
3575 |
// }
|
3576 |
//
|
3577 |
// public static int nvarchar2Limited(int n) {
|
3578 |
//
|
3579 |
// if (n <= VARCHAR2_STANDARD_SIZE) return VARCHAR2_STANDARD_SIZE;
|
3580 |
// if (n <= VARCHAR2_LONG_SIZE) return n;
|
3581 |
//
|
3582 |
// return VARCHAR2_LONG_SIZE;
|
3583 |
// }
|
3584 |
//
|
3585 |
//
|
3586 |
//
|
3587 |
//
|
3588 |
//
|
3589 |
// public static String removePrefix(String str) {
|
3590 |
//
|
3591 |
// int colon_ind = str.indexOf(":");
|
3592 |
// if (colon_ind != -1) {
|
3593 |
// return str.substring(colon_ind + 1);
|
3594 |
// } else {
|
3595 |
// return str;
|
3596 |
// }
|
3597 |
// }
|
3598 |
//
|
3599 |
//
|
3600 |
//
|
3601 |
// private class AnEmptyFeatureIterator implements IFeatureIterator {
|
3602 |
// public boolean hasNext() throws ReadDriverException { return false; }
|
3603 |
// public IFeature next() throws ReadDriverException { return null; }
|
3604 |
// public void closeIterator() throws ReadDriverException { }
|
3605 |
// }
|
3606 |
//
|
3607 |
// private Value objToValue(Object obj, int idFld) {
|
3608 |
//
|
3609 |
// if (obj == null) {
|
3610 |
// return ValueFactory.createNullValue();
|
3611 |
// } else {
|
3612 |
//
|
3613 |
// String objToString = obj.toString();
|
3614 |
//
|
3615 |
// if (obj instanceof String) {
|
3616 |
// objToString = (String) obj;
|
3617 |
// return ValueFactory.createValue(objToString);
|
3618 |
// } else {
|
3619 |
// if (obj instanceof ROWID) {
|
3620 |
// objToString = ((ROWID) obj).stringValue();
|
3621 |
// return ValueFactory.createValue(objToString);
|
3622 |
// } else {
|
3623 |
// if (obj instanceof STRUCT) {
|
3624 |
// objToString = "STRUCT";
|
3625 |
// return ValueFactory.createValue(objToString);
|
3626 |
// } else {
|
3627 |
// if (obj instanceof TIMESTAMP) {
|
3628 |
// TIMESTAMP aux = (TIMESTAMP) obj;
|
3629 |
// objToString = aux.stringValue();
|
3630 |
// Timestamp ts = flexibleTimeStamp(objToString);
|
3631 |
// return ValueFactory.createValue(ts);
|
3632 |
//
|
3633 |
// } else {
|
3634 |
//
|
3635 |
// // last try
|
3636 |
// int _type = -1;
|
3637 |
// try {
|
3638 |
// _type = getFieldType(idFld);
|
3639 |
// if (_type == Types.DATE) {
|
3640 |
// objToString = objToString.replace('-', '/');
|
3641 |
// }
|
3642 |
// return ValueFactory.createValueByType(objToString, _type);
|
3643 |
// } catch (Exception ex) {
|
3644 |
// logger.debug("Failed to create Value: _type = "
|
3645 |
// + _type + ", objToString = " + objToString);
|
3646 |
// return ValueFactory.createNullValue();
|
3647 |
// }
|
3648 |
//
|
3649 |
// }
|
3650 |
// }
|
3651 |
// }
|
3652 |
// }
|
3653 |
// }
|
3654 |
// }
|
3655 |
//
|
3656 |
// public Value[] getAttributes(ResultSet rs, boolean use_main_metadata) {
|
3657 |
// Value[] res = null;
|
3658 |
//
|
3659 |
// int fcount = 0;
|
3660 |
//
|
3661 |
// try {
|
3662 |
// if (use_main_metadata) {
|
3663 |
// fcount = metaData.getColumnCount();
|
3664 |
// } else {
|
3665 |
// fcount = rs.getMetaData().getColumnCount();
|
3666 |
// }
|
3667 |
//
|
3668 |
// res = new Value[fcount];
|
3669 |
//
|
3670 |
// for (int i = 0; i < fcount; i++) {
|
3671 |
// Object obj = rs.getObject(i + 1);
|
3672 |
// res[i] = objToValue(obj, i);
|
3673 |
// }
|
3674 |
//
|
3675 |
// } catch (Exception se) {
|
3676 |
// logger.error("While getting resultset attribute values: " + se.getMessage());
|
3677 |
// res = new Value[fcount];
|
3678 |
// for (int i=0; i<fcount; i++) res[i] = ValueFactory.createNullValue();
|
3679 |
// }
|
3680 |
//
|
3681 |
// return res;
|
3682 |
// }
|
3683 |
//
|
3684 |
// public boolean canWriteGeometry(int gvSIGgeometryType) {
|
3685 |
// if (writer == null) {
|
3686 |
// return true;
|
3687 |
// } else {
|
3688 |
// return writer.canWriteGeometry(gvSIGgeometryType);
|
3689 |
// }
|
3690 |
//
|
3691 |
// }
|
3692 |
|
3693 |
|
3694 |
|
3695 |
} |