root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / DefaultDBDriver.java @ 6535
History | View | Annotate | Download (22 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. 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 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.drivers; |
42 |
|
43 |
import java.awt.geom.Rectangle2D; |
44 |
import java.io.IOException; |
45 |
import java.sql.Connection; |
46 |
import java.sql.DatabaseMetaData; |
47 |
import java.sql.Driver; |
48 |
import java.sql.DriverManager; |
49 |
import java.sql.ResultSet; |
50 |
import java.sql.ResultSetMetaData; |
51 |
import java.sql.SQLException; |
52 |
import java.sql.Statement; |
53 |
import java.sql.Types; |
54 |
import java.util.Hashtable; |
55 |
|
56 |
import org.apache.log4j.Logger; |
57 |
|
58 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
59 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
60 |
import com.hardcode.gdbms.engine.values.Value; |
61 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
62 |
import com.iver.cit.gvsig.fmap.DriverException; |
63 |
import com.iver.cit.gvsig.fmap.Messages; |
64 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
65 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
66 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
67 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
68 |
import com.iver.utiles.XMLEntity; |
69 |
import com.iver.utiles.swing.JPasswordDlg; |
70 |
|
71 |
|
72 |
|
73 |
/**
|
74 |
* Clase abstracta qu
|
75 |
*/
|
76 |
public abstract class DefaultDBDriver implements VectorialJDBCDriver, ObjectDriver { |
77 |
private static Logger logger = Logger.getLogger(SelectableDataSource.class.getName()); |
78 |
private static Hashtable poolPassw = new Hashtable(); |
79 |
|
80 |
protected Connection conn; |
81 |
// protected String tableName;
|
82 |
// protected String whereClause;
|
83 |
// protected String fields;
|
84 |
// protected String sqlOrig;
|
85 |
private DBLayerDefinition lyrDef = null; |
86 |
protected ResultSet rs; |
87 |
protected boolean bCursorActivo = false; |
88 |
protected Statement st; |
89 |
protected int numReg=-1; |
90 |
|
91 |
private Rectangle2D fullExtent = null; |
92 |
|
93 |
// protected String strFID_FieldName;
|
94 |
// protected String idFID_FieldName;
|
95 |
|
96 |
protected Hashtable hashRelate; |
97 |
|
98 |
|
99 |
protected ResultSetMetaData metaData = null; |
100 |
protected Rectangle2D workingArea; |
101 |
private String driverClass; |
102 |
private String userName; |
103 |
private String dbUrl; |
104 |
private String className; |
105 |
private String catalogName; |
106 |
private String tableName; |
107 |
private String[] fields; |
108 |
private String FIDfield; |
109 |
private String geometryField; |
110 |
private String whereClause; |
111 |
private String strSRID; |
112 |
private double flatness; |
113 |
|
114 |
abstract public void setData(Connection conn, DBLayerDefinition lyrDef); |
115 |
|
116 |
/**
|
117 |
* @return devuelve la Conexi?n a la base de datos, para que
|
118 |
* el usuario pueda hacer la consulta que quiera, si lo desea.
|
119 |
* Por ejemplo, esto puede ser ?til para abrir un cuadro de dialogo
|
120 |
* avanazado y lanzar peticiones del tipo "Devuelveme un buffer
|
121 |
* a las autopistas", y con el resultset que te venga, escribir
|
122 |
* un shape, o cosas as?.
|
123 |
*/
|
124 |
public Connection getConnection() |
125 |
{ |
126 |
return conn;
|
127 |
} |
128 |
public String[] getFields() |
129 |
{ |
130 |
/* StringTokenizer tokenizer = new StringTokenizer(fields, ",");
|
131 |
String[] arrayFields = new String[tokenizer.countTokens()];
|
132 |
int i=0;
|
133 |
while (tokenizer.hasMoreTokens())
|
134 |
{
|
135 |
arrayFields[i] = tokenizer.nextToken();
|
136 |
i++;
|
137 |
}
|
138 |
return arrayFields; */
|
139 |
return lyrDef.getFieldNames();
|
140 |
|
141 |
} |
142 |
/**
|
143 |
* First, the geometry field. After, the rest of fields
|
144 |
* @return
|
145 |
*/
|
146 |
public String getTotalFields() |
147 |
{ |
148 |
String strAux = getGeometryField(getLyrDef().getFieldGeometry());
|
149 |
String[] fieldNames = getLyrDef().getFieldNames(); |
150 |
for (int i=0; i< fieldNames.length; i++) |
151 |
{ |
152 |
strAux = strAux + ", " + fieldNames[i];
|
153 |
} |
154 |
return strAux;
|
155 |
} |
156 |
|
157 |
public String getWhereClause() |
158 |
{ |
159 |
return lyrDef.getWhereClause();
|
160 |
} |
161 |
public String getTableName() |
162 |
{ |
163 |
return lyrDef.getTableName();
|
164 |
} |
165 |
|
166 |
|
167 |
/**
|
168 |
* @throws DriverIOException
|
169 |
* @throws DriverException
|
170 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeCount()
|
171 |
*/
|
172 |
public int getShapeCount() throws IOException { |
173 |
if (numReg == -1) |
174 |
{ |
175 |
try
|
176 |
{ |
177 |
Statement s = conn.createStatement();
|
178 |
ResultSet r = s.executeQuery("SELECT COUNT(*) AS NUMREG FROM " + lyrDef.getTableName() + " " + getCompleteWhere()); |
179 |
r.next(); |
180 |
numReg = r.getInt(1);
|
181 |
System.err.println("numReg = " + numReg); |
182 |
} |
183 |
catch (SQLException e) |
184 |
{ |
185 |
throw new IOException(e.getMessage()); |
186 |
} |
187 |
} |
188 |
|
189 |
return numReg;
|
190 |
} |
191 |
|
192 |
/**
|
193 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getFullExtent()
|
194 |
*/
|
195 |
public Rectangle2D getFullExtent(){ |
196 |
// Por defecto recorremos todas las geometrias.
|
197 |
// Las bases de datos como PostGIS pueden y deben
|
198 |
// sobreescribir este m?todo.
|
199 |
if (fullExtent == null) |
200 |
{ |
201 |
try
|
202 |
{ |
203 |
IFeatureIterator itGeom = getFeatureIterator("SELECT " +
|
204 |
getGeometryField(getLyrDef().getFieldGeometry()) + ", " + getLyrDef().getFieldID() + " FROM " + |
205 |
getLyrDef().getTableName() + " " + getCompleteWhere());
|
206 |
IGeometry geom; |
207 |
int cont = 0; |
208 |
while (itGeom.hasNext())
|
209 |
{ |
210 |
geom = itGeom.next().getGeometry(); |
211 |
if (cont==0) |
212 |
fullExtent = geom.getBounds2D(); |
213 |
else
|
214 |
fullExtent.add(geom.getBounds2D()); |
215 |
cont++; |
216 |
} |
217 |
} |
218 |
catch (DriverException e) {
|
219 |
// TODO Auto-generated catch block
|
220 |
e.printStackTrace(); |
221 |
} |
222 |
|
223 |
} |
224 |
return fullExtent;
|
225 |
} |
226 |
|
227 |
|
228 |
/**
|
229 |
* @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeType()
|
230 |
*/
|
231 |
public int getShapeType() { |
232 |
/* IGeometry geom;
|
233 |
if (shapeType == -1)
|
234 |
{
|
235 |
shapeType = FShape.MULTI;
|
236 |
try {
|
237 |
geom = getShape(0);
|
238 |
if (geom != null)
|
239 |
shapeType = geom.getGeometryType();
|
240 |
} catch (IOException e) {
|
241 |
// e.printStackTrace();
|
242 |
}
|
243 |
}
|
244 |
return shapeType; */
|
245 |
return lyrDef.getShapeType();
|
246 |
} |
247 |
|
248 |
public int getFieldType(int idField) throws com.hardcode.gdbms.engine.data.driver.DriverException |
249 |
{ |
250 |
String str = ""; |
251 |
try {
|
252 |
int i = idField + 2; // idField viene basado en 1, y |
253 |
// adem?s nos saltamos el campo de geometry
|
254 |
str = metaData.getColumnClassName(i); |
255 |
if (metaData.getColumnType(i) == Types.VARCHAR) |
256 |
return Types.VARCHAR; |
257 |
if (metaData.getColumnType(i) == Types.FLOAT) |
258 |
return Types.FLOAT; |
259 |
if (metaData.getColumnType(i) == Types.DOUBLE) |
260 |
return Types.DOUBLE; |
261 |
if (metaData.getColumnType(i) == Types.INTEGER) |
262 |
return Types.INTEGER; |
263 |
if (metaData.getColumnType(i) == Types.BIGINT) |
264 |
return Types.BIGINT; |
265 |
if (metaData.getColumnType(i) == Types.BIT) |
266 |
return Types.BIT; |
267 |
if (metaData.getColumnType(i) == Types.DATE) |
268 |
return Types.DATE; |
269 |
if (metaData.getColumnType(i) == Types.DECIMAL) |
270 |
return Types.DOUBLE; |
271 |
if (metaData.getColumnType(i) == Types.NUMERIC) |
272 |
return Types.DOUBLE; |
273 |
|
274 |
} catch (SQLException e) { |
275 |
throw new com.hardcode.gdbms.engine.data.driver.DriverException(e); |
276 |
} |
277 |
throw new com.hardcode.gdbms.engine.data.driver.DriverException("Tipo no soportado: " + str); |
278 |
} |
279 |
/**
|
280 |
* Obtiene el valor que se encuentra en la fila y columna indicada
|
281 |
* Esta es la implementaci?n por defecto. Si lo del absolute
|
282 |
* no va bien, como es el caso del PostGis, el driver lo
|
283 |
* tiene que reimplementar
|
284 |
*
|
285 |
* @param rowIndex fila
|
286 |
* @param fieldId columna
|
287 |
*
|
288 |
* @return subclase de Value con el valor del origen de datos
|
289 |
*
|
290 |
* @throws DriverException Si se produce un error accediendo al DataSource
|
291 |
*/
|
292 |
public Value getFieldValue(long rowIndex, int idField) |
293 |
throws com.hardcode.gdbms.engine.data.driver.DriverException
|
294 |
{ |
295 |
int i = (int) (rowIndex + 1); |
296 |
int fieldId = idField+2; |
297 |
try {
|
298 |
rs.absolute(i); |
299 |
if (metaData.getColumnType(fieldId) == Types.VARCHAR) |
300 |
{ |
301 |
String strAux = rs.getString(fieldId);
|
302 |
if (strAux == null) strAux = ""; |
303 |
return ValueFactory.createValue(strAux);
|
304 |
} |
305 |
if (metaData.getColumnType(fieldId) == Types.FLOAT) |
306 |
return ValueFactory.createValue(rs.getFloat(fieldId));
|
307 |
if (metaData.getColumnType(fieldId) == Types.DOUBLE) |
308 |
return ValueFactory.createValue(rs.getDouble(fieldId));
|
309 |
if (metaData.getColumnType(fieldId) == Types.INTEGER) |
310 |
return ValueFactory.createValue(rs.getInt(fieldId));
|
311 |
if (metaData.getColumnType(fieldId) == Types.BIGINT) |
312 |
return ValueFactory.createValue(rs.getLong(fieldId));
|
313 |
if (metaData.getColumnType(fieldId) == Types.BIT) |
314 |
return ValueFactory.createValue(rs.getBoolean(fieldId));
|
315 |
if (metaData.getColumnType(fieldId) == Types.DATE) |
316 |
return ValueFactory.createValue(rs.getDate(fieldId));
|
317 |
} catch (SQLException e) { |
318 |
throw new com.hardcode.gdbms.engine.data.driver.DriverException("Tipo no soportado: columna " + fieldId ); |
319 |
} |
320 |
return null; |
321 |
|
322 |
|
323 |
} |
324 |
|
325 |
/**
|
326 |
* Obtiene el n?mero de campos del DataSource
|
327 |
*
|
328 |
* @return
|
329 |
*
|
330 |
* @throws DriverException Si se produce alg?n error accediendo al
|
331 |
* DataSource
|
332 |
*/
|
333 |
public int getFieldCount() throws com.hardcode.gdbms.engine.data.driver.DriverException |
334 |
{ |
335 |
try {
|
336 |
// Suponemos que el primer campo es el de las geometries, y no lo
|
337 |
// contamos
|
338 |
return rs.getMetaData().getColumnCount()-1; |
339 |
} catch (SQLException e) { |
340 |
throw new com.hardcode.gdbms.engine.data.driver.DriverException(e); |
341 |
} |
342 |
|
343 |
} |
344 |
|
345 |
/**
|
346 |
* Devuelve el nombre del campo fieldId-?simo
|
347 |
*
|
348 |
* @param fieldId ?ndice del campo cuyo nombre se quiere obtener
|
349 |
*
|
350 |
* @return
|
351 |
* @throws com.hardcode.gdbms.engine.data.driver.DriverException
|
352 |
*
|
353 |
* @throws DriverException Si se produce alg?n error accediendo al
|
354 |
* DataSource
|
355 |
*/
|
356 |
public String getFieldName(int fieldId) throws com.hardcode.gdbms.engine.data.driver.DriverException |
357 |
{ |
358 |
try {
|
359 |
return rs.getMetaData().getColumnName(fieldId+2); |
360 |
} catch (SQLException e) { |
361 |
throw new com.hardcode.gdbms.engine.data.driver.DriverException(e); |
362 |
} |
363 |
} |
364 |
|
365 |
/**
|
366 |
* Obtiene el n?mero de registros del DataSource
|
367 |
*
|
368 |
* @return
|
369 |
*
|
370 |
* @throws DriverException Si se produce alg?n error accediendo al
|
371 |
* DataSource
|
372 |
*/
|
373 |
public long getRowCount() |
374 |
{ |
375 |
try {
|
376 |
return getShapeCount();
|
377 |
} catch (IOException e) { |
378 |
// TODO Auto-generated catch block
|
379 |
e.printStackTrace(); |
380 |
} |
381 |
return -1; |
382 |
} |
383 |
|
384 |
public void close() |
385 |
{ |
386 |
} |
387 |
|
388 |
/**
|
389 |
* Recorre el recordset creando una tabla Hash que usaremos para
|
390 |
* relacionar el n?mero de un registro con su identificador ?nico.
|
391 |
* Debe ser llamado en el setData justo despu?s de crear el recorset
|
392 |
* principal
|
393 |
* @throws SQLException
|
394 |
*/
|
395 |
protected void doRelateID_FID() throws SQLException |
396 |
{ |
397 |
hashRelate = new Hashtable(); |
398 |
|
399 |
|
400 |
String strSQL = "SELECT " + getLyrDef().getFieldID() + " FROM " + getLyrDef().getTableName() |
401 |
+ " " + getCompleteWhere() + " ORDER BY " + getLyrDef().getFieldID(); |
402 |
Statement s = getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); |
403 |
ResultSet r = s.executeQuery(strSQL);
|
404 |
int id=0; |
405 |
int gid;
|
406 |
int index = 0; |
407 |
while (r.next())
|
408 |
{ |
409 |
String aux = r.getString(1); |
410 |
Value val = ValueFactory.createValue(aux); |
411 |
hashRelate.put(val, new Integer(index)); |
412 |
System.out.println("ASOCIANDO CLAVE " + aux + " CON VALOR " + index); |
413 |
index++; |
414 |
} |
415 |
numReg = index; |
416 |
r.close(); |
417 |
// rs.beforeFirst();
|
418 |
|
419 |
} |
420 |
|
421 |
/* (non-Javadoc)
|
422 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver#getRowIndexByFID(java.lang.Object)
|
423 |
*/
|
424 |
public int getRowIndexByFID(IFeature FID) |
425 |
{ |
426 |
int resul;
|
427 |
// Object obj = FID.getAttribute(lyrDef.getIdFieldID());
|
428 |
String theId = FID.getID();
|
429 |
Value aux = ValueFactory.createValue(theId); |
430 |
// System.err.println("Mirando si existe " + aux.toString());
|
431 |
if (hashRelate.containsKey(aux))
|
432 |
{ |
433 |
Integer rowIndex = (Integer) hashRelate.get(aux); |
434 |
resul = rowIndex.intValue(); |
435 |
// System.err.println("Row asociada a " + aux.toString() + ":" + resul);
|
436 |
return resul;
|
437 |
} |
438 |
else
|
439 |
return -1; |
440 |
} |
441 |
|
442 |
/* (non-Javadoc)
|
443 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver#setXMLEntity(com.iver.utiles.XMLEntity)
|
444 |
*/
|
445 |
public void setXMLEntity(XMLEntity xml) throws XMLException |
446 |
{ |
447 |
|
448 |
className = xml.getStringProperty("className");
|
449 |
dbUrl = xml.getStringProperty("dbURL");
|
450 |
catalogName = xml.getStringProperty("catalog");
|
451 |
userName =xml.getStringProperty("username");
|
452 |
driverClass =xml.getStringProperty("driverclass");
|
453 |
tableName = xml.getStringProperty("tablename");
|
454 |
fields = xml.getStringArrayProperty("fields");
|
455 |
FIDfield = xml.getStringProperty("FID");
|
456 |
geometryField = xml.getStringProperty("THE_GEOM");
|
457 |
whereClause = xml.getStringProperty("whereclause");
|
458 |
strSRID = xml.getStringProperty("SRID");
|
459 |
if (xml.contains("minXworkArea")) |
460 |
{ |
461 |
double x = xml.getDoubleProperty("minXworkArea"); |
462 |
double y = xml.getDoubleProperty("minYworkArea"); |
463 |
double H = xml.getDoubleProperty("HworkArea"); |
464 |
double W = xml.getDoubleProperty("WworkArea"); |
465 |
workingArea = new Rectangle2D.Double(x,y,W,H); |
466 |
} |
467 |
|
468 |
DBLayerDefinition lyrDef = new DBLayerDefinition();
|
469 |
lyrDef.setCatalogName(catalogName); |
470 |
lyrDef.setTableName(tableName); |
471 |
lyrDef.setFieldNames(fields); |
472 |
lyrDef.setFieldID(FIDfield); |
473 |
lyrDef.setFieldGeometry(geometryField); |
474 |
lyrDef.setWhereClause(whereClause); |
475 |
// lyrDef.setClassToInstantiate(driverClass);
|
476 |
if (workingArea != null) |
477 |
lyrDef.setWorkingArea(workingArea); |
478 |
|
479 |
lyrDef.setSRID_EPSG(strSRID); |
480 |
|
481 |
setLyrDef(lyrDef); |
482 |
|
483 |
} |
484 |
|
485 |
public void load() throws DriverException{ |
486 |
try {
|
487 |
Class.forName(driverClass);
|
488 |
|
489 |
String keyPool = dbUrl + "_" + userName; |
490 |
Connection newConn = null; |
491 |
String clave = null; |
492 |
if (!poolPassw.containsKey(keyPool))
|
493 |
{ |
494 |
JPasswordDlg dlg = new JPasswordDlg();
|
495 |
String strMessage = Messages.getString("conectar_jdbc"); |
496 |
String strPassword = Messages.getString("password"); |
497 |
dlg.setMessage(strMessage + " " + dbUrl + ". " + strPassword + "?"); |
498 |
dlg.show(); |
499 |
clave = dlg.getPassword(); |
500 |
if (clave == null) |
501 |
return;
|
502 |
poolPassw.put(keyPool, clave); |
503 |
} |
504 |
else
|
505 |
{ |
506 |
clave = (String) poolPassw.get(keyPool);
|
507 |
} |
508 |
newConn = DriverManager.getConnection(dbUrl, userName, clave);
|
509 |
newConn.setAutoCommit(false);
|
510 |
|
511 |
DBLayerDefinition lyrDef = new DBLayerDefinition();
|
512 |
if (getLyrDef() == null) { |
513 |
lyrDef.setCatalogName(catalogName); |
514 |
lyrDef.setTableName(tableName); |
515 |
lyrDef.setFieldNames(fields); |
516 |
lyrDef.setFieldID(FIDfield); |
517 |
lyrDef.setFieldGeometry(geometryField); |
518 |
lyrDef.setWhereClause(whereClause); |
519 |
// lyrDef.setClassToInstantiate(driverClass);
|
520 |
if (workingArea != null) |
521 |
lyrDef.setWorkingArea(workingArea); |
522 |
|
523 |
lyrDef.setSRID_EPSG(strSRID); |
524 |
} else {
|
525 |
lyrDef = getLyrDef(); |
526 |
} |
527 |
|
528 |
|
529 |
|
530 |
setData(newConn, lyrDef); |
531 |
} catch (ClassNotFoundException e) { |
532 |
logger.debug(e); |
533 |
throw new DriverException(e); |
534 |
} catch (SQLException e) { |
535 |
logger.debug(e); |
536 |
throw new DriverException(e); |
537 |
} |
538 |
} |
539 |
/* (non-Javadoc)
|
540 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver#getXMLEntity()
|
541 |
*/
|
542 |
public XMLEntity getXMLEntity()
|
543 |
{ |
544 |
XMLEntity xml = new XMLEntity();
|
545 |
xml.putProperty("className",this.getClass().getName()); |
546 |
try {
|
547 |
DatabaseMetaData metadata = getConnection().getMetaData();
|
548 |
xml.putProperty("dbURL", metadata.getURL());
|
549 |
xml.putProperty("catalog", getLyrDef().getCatalogName());
|
550 |
// TODO: NO DEBEMOS GUARDAR EL NOMBRE DE USUARIO Y CONTRASE?A
|
551 |
// AQUI. Hay que utilizar un pool de conexiones
|
552 |
// y pedir al usuario que conecte a la base de datos
|
553 |
// en la primera capa. En el resto, usar la conexi?n
|
554 |
// creada con anterioridad.
|
555 |
String userName = metadata.getUserName();
|
556 |
int aux = userName.indexOf("@"); |
557 |
if (aux != -1) |
558 |
userName = userName.substring(0,aux);
|
559 |
xml.putProperty("username", userName);
|
560 |
|
561 |
Driver drv = DriverManager.getDriver(metadata.getURL()); |
562 |
// System.out.println(drv.getClass().getName());
|
563 |
xml.putProperty("driverclass", drv.getClass().getName());
|
564 |
|
565 |
xml.putProperty("tablename", getTableName());
|
566 |
xml.putProperty("fields", lyrDef.getFieldNames());
|
567 |
xml.putProperty("FID", lyrDef.getFieldID());
|
568 |
xml.putProperty("THE_GEOM", lyrDef.getFieldGeometry());
|
569 |
xml.putProperty("whereclause", getWhereClause());
|
570 |
xml.putProperty("SRID", lyrDef.getSRID_EPSG());
|
571 |
if (getWorkingArea() != null) |
572 |
{ |
573 |
xml.putProperty("minXworkArea", getWorkingArea().getMinX());
|
574 |
xml.putProperty("minYworkArea", getWorkingArea().getMinY());
|
575 |
xml.putProperty("HworkArea", getWorkingArea().getHeight());
|
576 |
xml.putProperty("WworkArea", getWorkingArea().getWidth());
|
577 |
} |
578 |
|
579 |
} catch (SQLException e) { |
580 |
// TODO Auto-generated catch block
|
581 |
e.printStackTrace(); |
582 |
} |
583 |
|
584 |
|
585 |
return xml;
|
586 |
|
587 |
} |
588 |
|
589 |
/**
|
590 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver#setWorkingArea(java.awt.geom.Rectangle2D)
|
591 |
*/
|
592 |
public void setWorkingArea(Rectangle2D rect) { |
593 |
this.workingArea = rect;
|
594 |
} |
595 |
|
596 |
/**
|
597 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver#getWorkingArea()
|
598 |
*/
|
599 |
public Rectangle2D getWorkingArea() { |
600 |
return workingArea;
|
601 |
} |
602 |
|
603 |
/* (non-Javadoc)
|
604 |
* @see com.hardcode.gdbms.engine.data.driver.GDBMSDriver#setDataSourceFactory(com.hardcode.gdbms.engine.data.DataSourceFactory)
|
605 |
*/
|
606 |
public void setDataSourceFactory(DataSourceFactory arg0) { |
607 |
// TODO Auto-generated method stub
|
608 |
|
609 |
} |
610 |
|
611 |
/**
|
612 |
* @return Returns the lyrDef.
|
613 |
*/
|
614 |
public DBLayerDefinition getLyrDef() {
|
615 |
return lyrDef;
|
616 |
} |
617 |
|
618 |
/**
|
619 |
* @param lyrDef The lyrDef to set.
|
620 |
*/
|
621 |
public void setLyrDef(DBLayerDefinition lyrDef) { |
622 |
this.lyrDef = lyrDef;
|
623 |
} |
624 |
|
625 |
abstract public String getSqlTotal(); |
626 |
|
627 |
/**
|
628 |
* @return Returns the completeWhere. WITHOUT order by clause!!
|
629 |
*/
|
630 |
abstract public String getCompleteWhere(); |
631 |
|
632 |
/* (non-Javadoc)
|
633 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#reLoad()
|
634 |
*/
|
635 |
public void reload() throws IOException |
636 |
{ |
637 |
try {
|
638 |
if (conn == null) this.load(); |
639 |
|
640 |
conn.commit(); |
641 |
|
642 |
setData(conn, lyrDef); |
643 |
} catch (SQLException e) { |
644 |
throw new IOException(e.getMessage()); |
645 |
} catch (DriverException e) {
|
646 |
throw new IOException(e.getMessage()); |
647 |
} |
648 |
|
649 |
} |
650 |
|
651 |
public int getFieldWidth(int fieldId) |
652 |
{ |
653 |
int i = -1; |
654 |
try {
|
655 |
int aux = fieldId + 2; // idField viene basado en 1, y |
656 |
i = rs.getMetaData().getColumnDisplaySize(aux); |
657 |
} catch (SQLException e) { |
658 |
e.printStackTrace(); |
659 |
} |
660 |
// SUN define que getColumnDisplaySize devuelve numeros negativos cuando el campo es de tipo Text o Vartext
|
661 |
// sin ancho. Nosotros vamos a devolver 255 para que fucione, por lo menos al exportar a DBF.
|
662 |
// Nota: Si se truncan cadenas, este es el sitio que lo provoca.
|
663 |
if (i <0) i=255; |
664 |
return i;
|
665 |
} |
666 |
|
667 |
public void setFlatness(double flatness) { |
668 |
this.flatness = flatness;
|
669 |
} |
670 |
|
671 |
} |