root / branches / v10 / extensions / extSDE / src / com / iver / cit / gvsig / fmap / drivers / sde / ArcSdeDriver.java @ 10942
History | View | Annotate | Download (28.5 KB)
1 |
/*
|
---|---|
2 |
* Created on 13-may-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
package com.iver.cit.gvsig.fmap.drivers.sde; |
45 |
|
46 |
import java.awt.geom.Rectangle2D; |
47 |
import java.io.IOException; |
48 |
import java.sql.Connection; |
49 |
import java.sql.Types; |
50 |
import java.util.Hashtable; |
51 |
import java.util.Vector; |
52 |
|
53 |
import com.esri.sde.sdk.client.SeColumnDefinition; |
54 |
import com.esri.sde.sdk.client.SeConnection; |
55 |
import com.esri.sde.sdk.client.SeException; |
56 |
import com.esri.sde.sdk.client.SeExtent; |
57 |
import com.esri.sde.sdk.client.SeFilter; |
58 |
import com.esri.sde.sdk.client.SeLayer; |
59 |
import com.esri.sde.sdk.client.SeObjectId; |
60 |
import com.esri.sde.sdk.client.SeQuery; |
61 |
import com.esri.sde.sdk.client.SeQueryInfo; |
62 |
import com.esri.sde.sdk.client.SeRow; |
63 |
import com.esri.sde.sdk.client.SeShape; |
64 |
import com.esri.sde.sdk.client.SeShapeFilter; |
65 |
import com.esri.sde.sdk.client.SeSqlConstruct; |
66 |
import com.esri.sde.sdk.client.SeTable; |
67 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
68 |
import com.hardcode.gdbms.engine.data.edition.DataWare; |
69 |
import com.hardcode.gdbms.engine.values.Value; |
70 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
71 |
import com.iver.cit.gvsig.fmap.DriverException; |
72 |
import com.iver.cit.gvsig.fmap.DriverJdbcNotFoundExceptionType; |
73 |
import com.iver.cit.gvsig.fmap.Messages; |
74 |
import com.iver.cit.gvsig.fmap.core.FShape; |
75 |
import com.iver.cit.gvsig.fmap.core.ICanReproject; |
76 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
77 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
78 |
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition; |
79 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
80 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
81 |
import com.iver.cit.gvsig.fmap.drivers.VectorialSDEDriver; |
82 |
import com.iver.cit.gvsig.fmap.edition.IWriteable; |
83 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
84 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
85 |
import com.iver.utiles.XMLEntity; |
86 |
import com.iver.utiles.swing.JPasswordDlg; |
87 |
|
88 |
|
89 |
/**
|
90 |
* Driver of ArcSDE.
|
91 |
* @author Vicente Caballero Navarro
|
92 |
* @uml.dependency supplier="com.iver.cit.gvsig.fmap.drivers.sde.ArcSdeFeatureIterator"
|
93 |
* @uml.dependency supplier="com.iver.cit.gvsig.fmap.drivers.sde.SDELayerDefinition"
|
94 |
*/
|
95 |
public class ArcSdeDriver implements ICanReproject, IWriteable, |
96 |
VectorialSDEDriver { |
97 |
protected static Hashtable poolPassw = new Hashtable(); |
98 |
private SeLayer layer;
|
99 |
private SeQuery query;
|
100 |
private SeQuery queryAux;
|
101 |
private SeSqlConstruct sqlConstruct;
|
102 |
private SeColumnDefinition[] colDefs; |
103 |
private SeRow row = null; |
104 |
private int numReg = -1; |
105 |
/**
|
106 |
* @uml.property name="fullExtent"
|
107 |
*/
|
108 |
private Rectangle2D fullExtent = null; |
109 |
private Hashtable hashRelate = null; |
110 |
private int idSpatialColumn = -1; |
111 |
/**
|
112 |
* @uml.property name="fields"
|
113 |
*/
|
114 |
private String[] fields; |
115 |
private int[] fieldTypes; |
116 |
private long lastRowServed = -1; |
117 |
private SeConnection conn = null; |
118 |
private String strEPSG; |
119 |
private String originalEPSG = null; |
120 |
/**
|
121 |
* @uml.property name="sqlTotal"
|
122 |
*/
|
123 |
private String sqlTotal; |
124 |
private long posActual = -1; |
125 |
private SeRow cachedRow = null; |
126 |
/**
|
127 |
* @uml.property name="lyrDef"
|
128 |
*/
|
129 |
protected SDELayerDefinition lyrDef = null; |
130 |
/**
|
131 |
* @uml.property name="workingArea"
|
132 |
*/
|
133 |
protected Rectangle2D workingArea; |
134 |
protected String driverClass; |
135 |
protected String className; |
136 |
protected String catalogName; |
137 |
|
138 |
/**
|
139 |
* Recorre el recordset creando una tabla Hash que usaremos para relacionar
|
140 |
* el n?mero de un registro con su identificador ?nico. Debe ser llamado
|
141 |
* en el setData justo despu?s de crear el recorset principal
|
142 |
*/
|
143 |
protected void doRelateID_FID() { |
144 |
hashRelate = new Hashtable(); |
145 |
|
146 |
try {
|
147 |
if (row == null) { |
148 |
System.out.println(" No rows fetched"); |
149 |
|
150 |
return;
|
151 |
} |
152 |
|
153 |
int index = 0; |
154 |
|
155 |
while (row != null) { |
156 |
SeShape shpVal = row.getShape(idSpatialColumn); |
157 |
SeObjectId objID = shpVal.getFeatureId(); |
158 |
String theKey = "" + objID.longValue(); |
159 |
hashRelate.put(theKey, new Integer(index)); |
160 |
row = query.fetch(); |
161 |
index++; |
162 |
} |
163 |
|
164 |
numReg = index; |
165 |
} catch (SeException e) {
|
166 |
e.printStackTrace(); |
167 |
} |
168 |
} |
169 |
/**
|
170 |
* @return
|
171 |
* @uml.property name="fullExtent"
|
172 |
*/
|
173 |
public Rectangle2D getFullExtent() { |
174 |
return fullExtent;
|
175 |
} |
176 |
public IGeometry getShape(int index) { |
177 |
SeRow row; |
178 |
|
179 |
try {
|
180 |
row = obtainRow(index); |
181 |
|
182 |
SeShape spVal = row.getShape(idSpatialColumn); |
183 |
IGeometry geom = ArcSdeFeatureIterator.getGeometry(spVal); |
184 |
return geom;
|
185 |
} catch (SeException e) {
|
186 |
e.printStackTrace(); |
187 |
} |
188 |
return null; |
189 |
} |
190 |
|
191 |
public IFeatureIterator getFeatureIterator(String sql) |
192 |
throws DriverException {
|
193 |
return null; |
194 |
} |
195 |
|
196 |
public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG) |
197 |
throws DriverException {
|
198 |
/*
|
199 |
* Generate a rectangular shape that will be used as a filter
|
200 |
*/
|
201 |
try {
|
202 |
SeShape shape = new SeShape(layer.getCoordRef());
|
203 |
|
204 |
SeExtent extent = new SeExtent(r.getMinX(), r.getMinY(),
|
205 |
r.getMaxX(), r.getMaxY()); |
206 |
shape.generateRectangle(extent); |
207 |
|
208 |
SeShape[] shapes = new SeShape[1]; |
209 |
shapes[0] = shape;
|
210 |
|
211 |
/*
|
212 |
* Retrieve all the shapes that are contained within the
|
213 |
* rectangles envelope.
|
214 |
*/
|
215 |
SeShapeFilter[] filters = new SeShapeFilter[1]; |
216 |
SeShapeFilter filter = null;
|
217 |
|
218 |
filter = new SeShapeFilter(layer.getName(),
|
219 |
layer.getSpatialColumn(), shape, SeFilter.METHOD_ENVP); |
220 |
filters[0] = filter;
|
221 |
|
222 |
SeQuery spatialQuery = null;
|
223 |
SeSqlConstruct sqlCons = new SeSqlConstruct(layer.getName());
|
224 |
|
225 |
spatialQuery = new SeQuery(conn, fields, sqlCons);
|
226 |
|
227 |
/*
|
228 |
* Set spatial constraints
|
229 |
*/
|
230 |
spatialQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false,
|
231 |
filters); |
232 |
|
233 |
spatialQuery.prepareQuery(); |
234 |
|
235 |
spatialQuery.execute(); |
236 |
|
237 |
return new ArcSdeFeatureIterator(spatialQuery); |
238 |
} catch (SeException e) {
|
239 |
e.printStackTrace(); |
240 |
return null; |
241 |
} |
242 |
} |
243 |
|
244 |
public void close() { |
245 |
} |
246 |
|
247 |
public void open() throws DriverException { |
248 |
} |
249 |
|
250 |
public int getRowIndexByFID(IFeature FID) { |
251 |
int resul;
|
252 |
String strID = FID.getID();
|
253 |
Integer rowIndex = (Integer) hashRelate.get(strID); |
254 |
|
255 |
if (rowIndex == null) { |
256 |
System.err.println("Error: No se ha encontrado " + strID + |
257 |
" dentro del Hash");
|
258 |
} |
259 |
resul = rowIndex.intValue(); |
260 |
return resul;
|
261 |
} |
262 |
|
263 |
public String getGeometryField(String fieldName) { |
264 |
return layer.getSpatialColumn();
|
265 |
} |
266 |
|
267 |
public int getShapeCount() throws IOException { |
268 |
return numReg;
|
269 |
} |
270 |
|
271 |
public DriverAttributes getDriverAttributes() {
|
272 |
return null; |
273 |
} |
274 |
|
275 |
public String getName() { |
276 |
return "ArcSDE driver"; |
277 |
} |
278 |
|
279 |
/**
|
280 |
* @return
|
281 |
* @uml.property name="fields"
|
282 |
*/
|
283 |
public String[] getFields() { |
284 |
String[] attributes = new String[fields.length - 1]; |
285 |
for (int i = 1; i < fields.length; i++) |
286 |
attributes[i - 1] = fields[i];
|
287 |
return attributes;
|
288 |
} |
289 |
|
290 |
public String getTableName() { |
291 |
return layer.getName();
|
292 |
} |
293 |
|
294 |
private SeRow obtainRow(long rowIndex) throws SeException { |
295 |
if (rowIndex != posActual) {
|
296 |
if (rowIndex == 0) { |
297 |
if (query != null) { |
298 |
if (query.inProgress()) {
|
299 |
query.close(); |
300 |
} |
301 |
} |
302 |
query = new SeQuery(conn, fields, sqlConstruct);
|
303 |
query.prepareQuery(); |
304 |
query.execute(); |
305 |
|
306 |
lastRowServed = -1;
|
307 |
} |
308 |
|
309 |
if (lastRowServed == (rowIndex - 1)) { |
310 |
row = query.fetch(); |
311 |
lastRowServed++; |
312 |
} else {
|
313 |
if (queryAux != null) { |
314 |
queryAux.close(); |
315 |
} |
316 |
|
317 |
queryAux = new SeQuery(conn, fields, sqlConstruct);
|
318 |
|
319 |
SeObjectId rowID = new SeObjectId(rowIndex + 1); |
320 |
row = queryAux.fetchRow(layer.getName(), rowID, fields); |
321 |
} |
322 |
|
323 |
posActual = rowIndex; |
324 |
cachedRow = row; |
325 |
} |
326 |
|
327 |
return cachedRow;
|
328 |
} |
329 |
|
330 |
public Value getFieldValue(long rowIndex, int fieldId) |
331 |
throws com.hardcode.gdbms.engine.data.driver.DriverException {
|
332 |
SeRow row; |
333 |
Value val = null;
|
334 |
|
335 |
try {
|
336 |
int idFieldArcSDE = fieldId + 1; // SIEMPRE CONTANDO CON |
337 |
// QUE NOS HAN PASADO EL PRIMER CAMPO EL DE SHAPE
|
338 |
row = obtainRow(rowIndex); |
339 |
|
340 |
int dataType = colDefs[idFieldArcSDE].getType();
|
341 |
|
342 |
switch (dataType) {
|
343 |
case SeColumnDefinition.TYPE_INT16:
|
344 |
val = ValueFactory.createValue(row.getShort(idFieldArcSDE) |
345 |
.intValue()); |
346 |
|
347 |
break;
|
348 |
|
349 |
case SeColumnDefinition.TYPE_INT32:
|
350 |
case SeColumnDefinition.TYPE_INT64:
|
351 |
val = ValueFactory.createValue(row.getInteger(idFieldArcSDE) |
352 |
.intValue()); |
353 |
|
354 |
break;
|
355 |
|
356 |
case SeColumnDefinition.TYPE_FLOAT32:
|
357 |
val = ValueFactory.createValue(row.getFloat(idFieldArcSDE) |
358 |
.floatValue()); |
359 |
|
360 |
break;
|
361 |
|
362 |
case SeColumnDefinition.TYPE_FLOAT64:
|
363 |
val = ValueFactory.createValue(row.getDouble(idFieldArcSDE) |
364 |
.doubleValue()); |
365 |
|
366 |
break;
|
367 |
|
368 |
case SeColumnDefinition.TYPE_DATE:
|
369 |
val = ValueFactory.createValue(row.getTime(idFieldArcSDE) |
370 |
.getTime()); |
371 |
|
372 |
break;
|
373 |
|
374 |
default:
|
375 |
|
376 |
String strAux = row.getString(idFieldArcSDE);
|
377 |
|
378 |
if (strAux == null) { |
379 |
strAux = "";
|
380 |
} |
381 |
|
382 |
val = ValueFactory.createValue(strAux); |
383 |
|
384 |
break;
|
385 |
} |
386 |
|
387 |
return val;
|
388 |
} catch (SeException e) {
|
389 |
e.printStackTrace(); |
390 |
} |
391 |
|
392 |
return ValueFactory.createNullValue();
|
393 |
} |
394 |
|
395 |
public int getFieldCount() |
396 |
throws com.hardcode.gdbms.engine.data.driver.DriverException {
|
397 |
return fields.length - 1; |
398 |
} |
399 |
|
400 |
public String getFieldName(int fieldId) |
401 |
throws com.hardcode.gdbms.engine.data.driver.DriverException {
|
402 |
return fields[fieldId + 1]; |
403 |
} |
404 |
|
405 |
public long getRowCount() { |
406 |
return numReg;
|
407 |
} |
408 |
|
409 |
public int getFieldType(int i) |
410 |
throws com.hardcode.gdbms.engine.data.driver.DriverException {
|
411 |
return fieldTypes[i];
|
412 |
} |
413 |
|
414 |
/**
|
415 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
|
416 |
*/
|
417 |
public int[] getPrimaryKeys() |
418 |
throws com.hardcode.gdbms.engine.data.driver.DriverException {
|
419 |
throw new UnsupportedOperationException(); |
420 |
} |
421 |
|
422 |
/**
|
423 |
* @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
|
424 |
*/
|
425 |
public void write(DataWare arg0) |
426 |
throws com.hardcode.gdbms.engine.data.driver.DriverException {
|
427 |
} |
428 |
|
429 |
public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG, |
430 |
String[] alphaNumericFieldsNeeded) throws DriverException { |
431 |
/*
|
432 |
* Generate a rectangular shape that will be used as a filter
|
433 |
*/
|
434 |
try {
|
435 |
SeShape shape = new SeShape(layer.getCoordRef());
|
436 |
|
437 |
SeExtent extent = new SeExtent(r.getMinX(), r.getMinY(),
|
438 |
r.getMaxX(), r.getMaxY()); |
439 |
shape.generateRectangle(extent); |
440 |
|
441 |
SeShape[] shapes = new SeShape[1]; |
442 |
shapes[0] = shape;
|
443 |
|
444 |
/*
|
445 |
* Retrieve all the shapes that are contained within the
|
446 |
* rectangles envelope.
|
447 |
*/
|
448 |
SeShapeFilter[] filters = new SeShapeFilter[1]; |
449 |
SeShapeFilter filter = null;
|
450 |
|
451 |
filter = new SeShapeFilter(layer.getName(),
|
452 |
layer.getSpatialColumn(), shape, SeFilter.METHOD_ENVP); |
453 |
filters[0] = filter;
|
454 |
|
455 |
SeQuery spatialQuery = null;
|
456 |
SeSqlConstruct sqlCons = new SeSqlConstruct(layer.getName());
|
457 |
|
458 |
spatialQuery = new SeQuery(conn, fields, sqlCons);
|
459 |
|
460 |
/*
|
461 |
* Set spatial constraints
|
462 |
*/
|
463 |
spatialQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false,
|
464 |
filters); |
465 |
|
466 |
spatialQuery.prepareQuery(); |
467 |
|
468 |
spatialQuery.execute(); |
469 |
|
470 |
return new ArcSdeFeatureIterator(spatialQuery); |
471 |
} catch (SeException e) {
|
472 |
e.printStackTrace(); |
473 |
|
474 |
return null; |
475 |
} |
476 |
} |
477 |
|
478 |
public boolean isWritable() { |
479 |
return true; |
480 |
} |
481 |
|
482 |
public void setData(Connection connection, DBLayerDefinition lyrDef) { |
483 |
setLyrDef(lyrDef); |
484 |
// Conexi?n:
|
485 |
SDELayerDefinition sdeDef = (SDELayerDefinition) lyrDef; |
486 |
String server = sdeDef.getHost();
|
487 |
int instance = Integer.parseInt(sdeDef.getPort()); |
488 |
String database = sdeDef.getSchema();
|
489 |
String user = sdeDef.getUser();
|
490 |
String password = sdeDef.getPassword();
|
491 |
String[] cols = sdeDef.getFieldNames(); |
492 |
String tableName = sdeDef.getTableName();
|
493 |
|
494 |
try {
|
495 |
conn = new SeConnection(server, instance, database, user, password);
|
496 |
} catch (SeException e) {
|
497 |
e.printStackTrace(); |
498 |
|
499 |
return;
|
500 |
} |
501 |
|
502 |
// Fetching data
|
503 |
String layerName = tableName;
|
504 |
SeObjectId layerID = null;
|
505 |
String strSpatialColumn = ""; |
506 |
|
507 |
try {
|
508 |
Vector theLayers = conn.getLayers();
|
509 |
|
510 |
for (int i = 0; i < theLayers.size(); i++) { |
511 |
SeLayer layer = (SeLayer) theLayers.elementAt(i); |
512 |
|
513 |
if (layer.getName().compareToIgnoreCase(layerName) == 0) { |
514 |
; |
515 |
} |
516 |
|
517 |
layerID = layer.getID(); |
518 |
strSpatialColumn = layer.getSpatialColumn(); |
519 |
} |
520 |
|
521 |
if (layerID == null) { |
522 |
System.err.println("Capa no encontrada"); |
523 |
|
524 |
return;
|
525 |
} |
526 |
|
527 |
// layerName = layer.getName();
|
528 |
layer = new SeLayer(conn, layerName, strSpatialColumn);
|
529 |
|
530 |
//TODO aqu? se puede saber la proyecci?n
|
531 |
//layer.getCoordRef().getSrid();
|
532 |
|
533 |
if ((cols != null) && (cols.length != 0)) { |
534 |
if (!cols[0].equals(lyrDef.getFieldGeometry())) { |
535 |
this.fields = new String[cols.length + 1]; |
536 |
this.fields[0] = lyrDef.getFieldGeometry(); |
537 |
|
538 |
for (int i = 1; i < fields.length; i++) { |
539 |
fields[i] = cols[i - 1];
|
540 |
} |
541 |
} else {
|
542 |
fields = cols; |
543 |
} |
544 |
} else {
|
545 |
SeSqlConstruct sqlConstruct = new SeSqlConstruct(tableName);
|
546 |
sqlTotal = sqlConstruct.getWhere(); |
547 |
|
548 |
SeTable table1 = new SeTable(conn, tableName);
|
549 |
|
550 |
/*
|
551 |
* Get the table's column definition.
|
552 |
*/
|
553 |
SeColumnDefinition[] tableDef = table1.describe();
|
554 |
this.fields = new String[tableDef.length]; |
555 |
|
556 |
/*
|
557 |
* Store the names of all the table's columns in the
|
558 |
* String array cols. This array specifies the columns
|
559 |
* to be retrieved from the database.
|
560 |
*/
|
561 |
int idField = 1; |
562 |
|
563 |
for (int i = 0; i < tableDef.length; i++) { |
564 |
if (tableDef[i].getType() == SeColumnDefinition.TYPE_SHAPE) {
|
565 |
this.fields[0] = tableDef[i].getName(); |
566 |
} else {
|
567 |
this.fields[idField] = tableDef[i].getName();
|
568 |
idField++; |
569 |
} |
570 |
} |
571 |
|
572 |
lyrDef.setFieldNames(fields); |
573 |
} |
574 |
|
575 |
sqlConstruct = new SeSqlConstruct(layerName);
|
576 |
|
577 |
// Create a query stream between the client and server
|
578 |
query = new SeQuery(conn, fields, sqlConstruct);
|
579 |
query.prepareQuery(); |
580 |
query.execute(); |
581 |
row = query.fetch(); |
582 |
|
583 |
if (row == null) { |
584 |
System.out.println("La tabla " + getName() + |
585 |
" no tiene registros");
|
586 |
|
587 |
return;
|
588 |
} |
589 |
|
590 |
colDefs = row.getColumns(); |
591 |
lyrDef.setShapeType(obtainShapeType(row.getShape(0).getType()));
|
592 |
fieldTypes = new int[colDefs.length - 1]; |
593 |
|
594 |
for (int colNum = 0; colNum < colDefs.length; colNum++) { |
595 |
SeColumnDefinition colDef = colDefs[colNum]; |
596 |
int dataType = colDef.getType();
|
597 |
|
598 |
switch (dataType) {
|
599 |
case SeColumnDefinition.TYPE_SHAPE:
|
600 |
|
601 |
if (colNum != 0) { |
602 |
System.err.println(
|
603 |
"Por favor, el campo de shapes deber ser el primero");
|
604 |
|
605 |
return;
|
606 |
} |
607 |
|
608 |
idSpatialColumn = colNum; |
609 |
|
610 |
break;
|
611 |
|
612 |
case SeColumnDefinition.TYPE_INT16:
|
613 |
case SeColumnDefinition.TYPE_INT32:
|
614 |
case SeColumnDefinition.TYPE_INT64:
|
615 |
fieldTypes[colNum - 1] = Types.INTEGER; |
616 |
|
617 |
break;
|
618 |
|
619 |
case SeColumnDefinition.TYPE_FLOAT32:
|
620 |
fieldTypes[colNum - 1] = Types.FLOAT; |
621 |
|
622 |
break;
|
623 |
|
624 |
case SeColumnDefinition.TYPE_FLOAT64:
|
625 |
fieldTypes[colNum - 1] = Types.DOUBLE; |
626 |
|
627 |
break;
|
628 |
|
629 |
case SeColumnDefinition.TYPE_DATE:
|
630 |
fieldTypes[colNum - 1] = Types.DATE; |
631 |
|
632 |
break;
|
633 |
|
634 |
default:
|
635 |
fieldTypes[colNum - 1] = Types.VARCHAR; |
636 |
|
637 |
break;
|
638 |
} |
639 |
} |
640 |
|
641 |
SeQuery extentQuery = new SeQuery(conn, fields, sqlConstruct);
|
642 |
SeQueryInfo queryInfo = new SeQueryInfo();
|
643 |
queryInfo.setConstruct(sqlConstruct); |
644 |
|
645 |
SeExtent seExtent = extentQuery.calculateLayerExtent(queryInfo); |
646 |
fullExtent = new Rectangle2D.Double(seExtent.getMinX(), |
647 |
seExtent.getMinY(), |
648 |
seExtent.getMaxX() - seExtent.getMinX(), |
649 |
seExtent.getMaxY() - seExtent.getMinY()); |
650 |
extentQuery.close(); |
651 |
|
652 |
doRelateID_FID(); |
653 |
} catch (SeException e) {
|
654 |
e.printStackTrace(); |
655 |
} |
656 |
} |
657 |
|
658 |
private int obtainShapeType(int type) { |
659 |
int shapeType = -1; |
660 |
|
661 |
switch (type) {
|
662 |
case SeLayer.TYPE_POINT:
|
663 |
shapeType = FShape.POINT; |
664 |
|
665 |
break;
|
666 |
|
667 |
case SeLayer.TYPE_LINE:
|
668 |
case SeLayer.TYPE_SIMPLE_LINE:
|
669 |
case SeLayer.TYPE_MULTI_LINE:
|
670 |
case SeLayer.TYPE_MULTI_SIMPLE_LINE:
|
671 |
shapeType = FShape.LINE; |
672 |
|
673 |
break;
|
674 |
|
675 |
case SeLayer.TYPE_POLYGON:
|
676 |
case SeLayer.TYPE_MULTI_POLYGON:
|
677 |
shapeType = FShape.POLYGON; |
678 |
|
679 |
break;
|
680 |
|
681 |
default:
|
682 |
shapeType = FShape.MULTI; |
683 |
} |
684 |
|
685 |
return shapeType;
|
686 |
} |
687 |
|
688 |
public String getCompleteWhere() { |
689 |
return null; |
690 |
} |
691 |
|
692 |
public String getConnectionStringBeginning() { |
693 |
return ""; |
694 |
} |
695 |
|
696 |
public int getDefaultPort() { |
697 |
return 5151; |
698 |
} |
699 |
|
700 |
public String getSourceProjection() { |
701 |
return originalEPSG;
|
702 |
} |
703 |
|
704 |
public String getDestProjection() { |
705 |
return strEPSG;
|
706 |
} |
707 |
|
708 |
public void setDestProjection(String toEPSG) { |
709 |
this.strEPSG = toEPSG;
|
710 |
} |
711 |
|
712 |
public boolean canReproject(String toEPSGdestinyProjection) { |
713 |
// TODO POR AHORA, REPROYECTA SIEMPRE gvSIG.
|
714 |
return false; |
715 |
} |
716 |
|
717 |
public IWriter getWriter() {
|
718 |
return null; |
719 |
} |
720 |
|
721 |
/**
|
722 |
* @return
|
723 |
* @uml.property name="sqlTotal"
|
724 |
*/
|
725 |
public String getSqlTotal() { |
726 |
return sqlTotal;
|
727 |
} |
728 |
|
729 |
public XMLEntity getXMLEntity() {
|
730 |
SDELayerDefinition sdeDef = (SDELayerDefinition) getLyrDef(); |
731 |
XMLEntity xml = new XMLEntity();
|
732 |
xml.putProperty("className", this.getClass().getName()); |
733 |
xml.putProperty("driverclass", this.getClass().getName()); |
734 |
xml.putProperty("catalog", sdeDef.getCatalogName());
|
735 |
|
736 |
// TODO: NO DEBEMOS GUARDAR EL NOMBRE DE USUARIO Y CONTRASE?A
|
737 |
// AQUI. Hay que utilizar un pool de conexiones
|
738 |
// y pedir al usuario que conecte a la base de datos
|
739 |
// en la primera capa. En el resto, usar la conexi?n
|
740 |
// creada con anterioridad.
|
741 |
String userName = sdeDef.getUser();
|
742 |
if (userName != null) { |
743 |
int aux = userName.indexOf("@"); |
744 |
|
745 |
if (aux != -1) { |
746 |
userName = userName.substring(0, aux);
|
747 |
} |
748 |
} |
749 |
|
750 |
xml.putProperty("username", userName);
|
751 |
|
752 |
xml.putProperty("tablename", getTableName());
|
753 |
xml.putProperty("fields", fields);
|
754 |
xml.putProperty("ID", sdeDef.getFieldID());
|
755 |
xml.putProperty("THE_GEOM", sdeDef.getFieldGeometry());
|
756 |
xml.putProperty("whereclause", getWhereClause());
|
757 |
xml.putProperty("SRID", sdeDef.getSRID_EPSG());
|
758 |
|
759 |
xml.putProperty("host", sdeDef.getHost());
|
760 |
xml.putProperty("port", sdeDef.getPort());
|
761 |
xml.putProperty("dbName", sdeDef.getSchema());
|
762 |
xml.putProperty("connName", sdeDef.getConnectionName());
|
763 |
|
764 |
if (getWorkingArea() != null) { |
765 |
xml.putProperty("minXworkArea", getWorkingArea().getMinX());
|
766 |
xml.putProperty("minYworkArea", getWorkingArea().getMinY());
|
767 |
xml.putProperty("HworkArea", getWorkingArea().getHeight());
|
768 |
xml.putProperty("WworkArea", getWorkingArea().getWidth());
|
769 |
} |
770 |
|
771 |
return xml;
|
772 |
} |
773 |
|
774 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
775 |
className = xml.getStringProperty("className");
|
776 |
catalogName = xml.getStringProperty("catalog");
|
777 |
lyrDef = new SDELayerDefinition();
|
778 |
|
779 |
if (xml.contains("username")) { |
780 |
lyrDef.setUser(xml.getStringProperty("username"));
|
781 |
} |
782 |
|
783 |
driverClass = xml.getStringProperty("driverclass");
|
784 |
lyrDef.setTableName(xml.getStringProperty("tablename"));
|
785 |
fields = xml.getStringArrayProperty("fields");
|
786 |
lyrDef.setFieldNames(fields); |
787 |
lyrDef.setFieldID(xml.getStringProperty("ID"));
|
788 |
lyrDef.setFieldGeometry(xml.getStringProperty("THE_GEOM"));
|
789 |
lyrDef.setWhereClause(xml.getStringProperty("whereclause"));
|
790 |
lyrDef.setSRID_EPSG(xml.getStringProperty("SRID"));
|
791 |
|
792 |
if (xml.contains("host")) { |
793 |
lyrDef.setHost(xml.getStringProperty("host"));
|
794 |
lyrDef.setPort(xml.getStringProperty("port"));
|
795 |
lyrDef.setSchema(xml.getStringProperty("dbName"));
|
796 |
lyrDef.setConnectionName(xml.getStringProperty("connName"));
|
797 |
} |
798 |
|
799 |
if (xml.contains("minXworkArea")) { |
800 |
double x = xml.getDoubleProperty("minXworkArea"); |
801 |
double y = xml.getDoubleProperty("minYworkArea"); |
802 |
double H = xml.getDoubleProperty("HworkArea"); |
803 |
double W = xml.getDoubleProperty("WworkArea"); |
804 |
workingArea = new Rectangle2D.Double(x, y, W, H); |
805 |
} |
806 |
|
807 |
lyrDef.setCatalogName(catalogName); |
808 |
lyrDef.setFieldNames(fields); |
809 |
|
810 |
if (workingArea != null) { |
811 |
lyrDef.setWorkingArea(workingArea); |
812 |
} |
813 |
|
814 |
setLyrDef(lyrDef); |
815 |
} |
816 |
|
817 |
public int getFieldWidth(int fieldId) { |
818 |
return colDefs[fieldId].getSize();
|
819 |
} |
820 |
|
821 |
public void setLyrDef(DBLayerDefinition lyrDef) { |
822 |
this.lyrDef = (SDELayerDefinition) lyrDef;
|
823 |
} |
824 |
|
825 |
/**
|
826 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver#setWorkingArea(java.awt.geom.Rectangle2D)
|
827 |
* @uml.property name="workingArea"
|
828 |
*/
|
829 |
public void setWorkingArea(Rectangle2D rect) { |
830 |
this.workingArea = rect;
|
831 |
} |
832 |
|
833 |
/**
|
834 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver#getWorkingArea()
|
835 |
* @uml.property name="workingArea"
|
836 |
*/
|
837 |
public Rectangle2D getWorkingArea() { |
838 |
return workingArea;
|
839 |
} |
840 |
|
841 |
/**
|
842 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeType()
|
843 |
*/
|
844 |
public int getShapeType() { |
845 |
return lyrDef.getShapeType();
|
846 |
} |
847 |
|
848 |
/* (non-Javadoc)
|
849 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver#getWhereClause()
|
850 |
*/
|
851 |
public String getWhereClause() { |
852 |
if (lyrDef.getWhereClause() == null) { |
853 |
return ""; |
854 |
} |
855 |
|
856 |
return lyrDef.getWhereClause().toUpperCase();
|
857 |
} |
858 |
|
859 |
/**
|
860 |
* @return
|
861 |
* @uml.property name="lyrDef"
|
862 |
*/
|
863 |
public DBLayerDefinition getLyrDef() {
|
864 |
return lyrDef;
|
865 |
} |
866 |
|
867 |
/**
|
868 |
* Empty method called when the layer is going to be removed from the view.
|
869 |
* Subclasses can overwrite it if needed.
|
870 |
*/
|
871 |
public void remove() { |
872 |
} |
873 |
|
874 |
/* (non-Javadoc)
|
875 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#reLoad()
|
876 |
*/
|
877 |
public void reload() throws IOException { |
878 |
setData(null, lyrDef);
|
879 |
} |
880 |
|
881 |
public void setDataSourceFactory(DataSourceFactory dsf) { |
882 |
// TODO Auto-generated method stub
|
883 |
} |
884 |
|
885 |
public void load() throws DriverException { |
886 |
try {
|
887 |
if (driverClass != null) { |
888 |
Class.forName(driverClass);
|
889 |
} |
890 |
|
891 |
String _drvName = getName();
|
892 |
|
893 |
String keyPool = _drvName.toLowerCase() + "_" + |
894 |
lyrDef.getHost().toLowerCase() + "_" + lyrDef.getPort() + "_" + |
895 |
lyrDef.getSchema().toLowerCase() + "_" +
|
896 |
lyrDef.getUser().toLowerCase(); |
897 |
|
898 |
String clave = null; |
899 |
|
900 |
if (poolPassw.containsKey(keyPool)) {
|
901 |
clave = (String) poolPassw.get(keyPool);
|
902 |
|
903 |
lyrDef.setPassword(clave); |
904 |
} else {
|
905 |
JPasswordDlg dlg = new JPasswordDlg();
|
906 |
String strMessage = Messages.getString("conectar_sde"); |
907 |
String strPassword = Messages.getString("password"); |
908 |
dlg.setMessage(strMessage + " [" + _drvName + ", " + |
909 |
lyrDef.getHost() + ", " + lyrDef.getPort() + ", " + |
910 |
lyrDef.getSchema() + ", " + lyrDef.getUser() + "]. " + |
911 |
strPassword + "?");
|
912 |
dlg.show(); |
913 |
clave = dlg.getPassword(); |
914 |
|
915 |
if (clave == null) { |
916 |
return;
|
917 |
} |
918 |
|
919 |
poolPassw.put(keyPool, clave); |
920 |
lyrDef.setPassword(clave); |
921 |
|
922 |
} |
923 |
|
924 |
DBLayerDefinition lyrDef = new DBLayerDefinition();
|
925 |
|
926 |
if (getLyrDef() == null) { |
927 |
lyrDef.setCatalogName(catalogName); |
928 |
lyrDef.setFieldNames(fields); |
929 |
if (workingArea != null) { |
930 |
lyrDef.setWorkingArea(workingArea); |
931 |
} |
932 |
} else {
|
933 |
lyrDef = getLyrDef(); |
934 |
} |
935 |
|
936 |
setData(null, lyrDef);
|
937 |
} catch (ClassNotFoundException e) { |
938 |
DriverJdbcNotFoundExceptionType type = new DriverJdbcNotFoundExceptionType();
|
939 |
type.setDriverJdbcClassName(driverClass); |
940 |
type.setLayerName(this.getLyrDef().getTableName());
|
941 |
throw new DriverException("Driver SDE no encontrado", e, type); |
942 |
} |
943 |
} |
944 |
|
945 |
public Object getConnection() { |
946 |
return conn;
|
947 |
} |
948 |
} |