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