Revision 3236
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/DefaultDBDriver.java | ||
---|---|---|
80 | 80 |
private static Hashtable poolPassw = new Hashtable(); |
81 | 81 |
|
82 | 82 |
protected Connection conn; |
83 |
protected String tableName; |
|
84 |
protected String whereClause; |
|
85 |
protected String fields; |
|
86 |
protected String sqlOrig; |
|
83 |
// protected String tableName; |
|
84 |
// protected String whereClause; |
|
85 |
// protected String fields; |
|
86 |
// protected String sqlOrig; |
|
87 |
private DBLayerDefinition lyrDef = null; |
|
87 | 88 |
protected ResultSet rs; |
88 | 89 |
protected boolean bCursorActivo = false; |
89 | 90 |
protected Statement st; |
90 | 91 |
protected int numReg=-1; |
91 | 92 |
|
92 |
protected String strFID_FieldName; |
|
93 |
protected int idFID_FieldName;
|
|
93 |
// protected String strFID_FieldName;
|
|
94 |
// protected String idFID_FieldName;
|
|
94 | 95 |
|
95 | 96 |
protected Hashtable hashRelate; |
96 | 97 |
|
... | ... | |
98 | 99 |
protected ResultSetMetaData metaData = null; |
99 | 100 |
protected Rectangle2D workingArea; |
100 | 101 |
|
101 |
abstract public void setData(Connection conn, String tableName, String fields, String whereClause, int fidField);
|
|
102 |
abstract public void setData(Connection conn, DBLayerDefinition lyrDef);
|
|
102 | 103 |
|
103 | 104 |
/** |
104 | 105 |
* @return devuelve la Conexi?n a la base de datos, para que |
... | ... | |
114 | 115 |
} |
115 | 116 |
public String[] getFields() |
116 | 117 |
{ |
117 |
StringTokenizer tokenizer = new StringTokenizer(fields, ","); |
|
118 |
/* StringTokenizer tokenizer = new StringTokenizer(fields, ",");
|
|
118 | 119 |
String[] arrayFields = new String[tokenizer.countTokens()]; |
119 | 120 |
int i=0; |
120 | 121 |
while (tokenizer.hasMoreTokens()) |
... | ... | |
122 | 123 |
arrayFields[i] = tokenizer.nextToken(); |
123 | 124 |
i++; |
124 | 125 |
} |
125 |
return arrayFields; |
|
126 |
return arrayFields; */ |
|
127 |
return lyrDef.getFieldNames(); |
|
128 |
|
|
126 | 129 |
} |
130 |
/** |
|
131 |
* First, the geometry field. After, the rest of fields |
|
132 |
* @return |
|
133 |
*/ |
|
134 |
public String getTotalFields() |
|
135 |
{ |
|
136 |
String strAux = getGeometryField(getLyrDef().getFieldGeometry()); |
|
137 |
String[] fieldNames = getLyrDef().getFieldNames(); |
|
138 |
for (int i=0; i< fieldNames.length; i++) |
|
139 |
{ |
|
140 |
strAux = strAux + ", " + fieldNames[i]; |
|
141 |
} |
|
142 |
return strAux; |
|
143 |
} |
|
144 |
|
|
127 | 145 |
public String getWhereClause() |
128 | 146 |
{ |
129 |
return whereClause;
|
|
147 |
return lyrDef.getWhereClause();
|
|
130 | 148 |
} |
131 | 149 |
public String getTableName() |
132 | 150 |
{ |
133 |
return tableName;
|
|
151 |
return lyrDef.getTableName();
|
|
134 | 152 |
} |
135 | 153 |
|
136 | 154 |
|
... | ... | |
145 | 163 |
try |
146 | 164 |
{ |
147 | 165 |
Statement s = conn.createStatement(); |
148 |
ResultSet r = s.executeQuery("SELECT COUNT(*) AS NUMREG FROM " + tableName + " " + whereClause);
|
|
166 |
ResultSet r = s.executeQuery("SELECT COUNT(*) AS NUMREG FROM " + lyrDef.getTableName() + " " + lyrDef.getWhereClause());
|
|
149 | 167 |
r.next(); |
150 | 168 |
numReg = r.getInt(1); |
151 | 169 |
System.err.println("numReg = " + numReg); |
... | ... | |
322 | 340 |
|
323 | 341 |
while (rs.next()) |
324 | 342 |
{ |
325 |
Value aux = getFieldValue(index, idFID_FieldName-2);
|
|
343 |
Value aux = getFieldValue(index, lyrDef.getIdFieldID()-2);
|
|
326 | 344 |
hashRelate.put(aux, new Integer(index)); |
327 | 345 |
index++; |
328 | 346 |
} |
... | ... | |
344 | 362 |
public int getRowIndexByFID(IFeature FID) |
345 | 363 |
{ |
346 | 364 |
int resul; |
347 |
Object obj = FID.getAttribute(idFID_FieldName -2);
|
|
365 |
Object obj = FID.getAttribute(lyrDef.getIdFieldID() -2);
|
|
348 | 366 |
// System.err.println("Mirando si existe " + obj.toString()); |
349 | 367 |
Integer rowIndex = (Integer) hashRelate.get(obj); |
350 | 368 |
resul = rowIndex.intValue(); |
... | ... | |
358 | 376 |
{ |
359 | 377 |
String className = xml.getStringProperty("className"); |
360 | 378 |
String dbUrl = xml.getStringProperty("dbURL"); |
379 |
String catalogName = xml.getStringProperty("catalog"); |
|
361 | 380 |
String userName =xml.getStringProperty("username"); |
362 | 381 |
String driverClass =xml.getStringProperty("driverclass"); |
363 | 382 |
String tableName = xml.getStringProperty("tablename"); |
364 |
String fields = xml.getStringProperty("fields");
|
|
383 |
String[] fields = xml.getStringArrayProperty("fields");
|
|
365 | 384 |
int idFIDfield = xml.getIntProperty("FID"); |
385 |
String geometryField = xml.getStringProperty("THE_GEOM"); |
|
366 | 386 |
String whereClause = xml.getStringProperty("whereclause"); |
387 |
String strSRID = xml.getStringProperty("SRID"); |
|
367 | 388 |
|
368 | 389 |
try { |
369 | 390 |
Class.forName(driverClass); |
... | ... | |
390 | 411 |
newConn = DriverManager.getConnection(dbUrl, userName, clave); |
391 | 412 |
newConn.setAutoCommit(false); |
392 | 413 |
|
393 |
setData(newConn, tableName, fields, whereClause, idFIDfield); |
|
414 |
DBLayerDefinition lyrDef = new DBLayerDefinition(); |
|
415 |
lyrDef.setCatalogName(catalogName); |
|
416 |
lyrDef.setTableName(tableName); |
|
417 |
lyrDef.setFieldNames(fields); |
|
418 |
lyrDef.setFieldID(fields[idFIDfield]); |
|
419 |
lyrDef.setFieldGeometry(geometryField); |
|
420 |
lyrDef.setWhereClause(whereClause); |
|
421 |
// lyrDef.setClassToInstantiate(driverClass); |
|
422 |
if (workingArea != null) |
|
423 |
lyrDef.setWorkingArea(workingArea); |
|
424 |
|
|
425 |
lyrDef.setSRID_EPSG(strSRID); |
|
426 |
|
|
427 |
|
|
428 |
setData(newConn, lyrDef); |
|
394 | 429 |
} catch (ClassNotFoundException e) { |
395 | 430 |
logger.debug(e); |
396 | 431 |
throw new XMLException(e); |
... | ... | |
410 | 445 |
try { |
411 | 446 |
DatabaseMetaData metadata = getConnection().getMetaData(); |
412 | 447 |
xml.putProperty("dbURL", metadata.getURL()); |
448 |
xml.putProperty("catalog", getLyrDef().getCatalogName()); |
|
413 | 449 |
// TODO: NO DEBEMOS GUARDAR EL NOMBRE DE USUARIO Y CONTRASE?A |
414 | 450 |
// AQUI. Hay que utilizar un pool de conexiones |
415 | 451 |
// y pedir al usuario que conecte a la base de datos |
... | ... | |
426 | 462 |
xml.putProperty("driverclass", drv.getClass().getName()); |
427 | 463 |
|
428 | 464 |
xml.putProperty("tablename", getTableName()); |
429 |
xml.putProperty("fields", getFields()); |
|
430 |
xml.putProperty("FID", idFID_FieldName); |
|
431 |
|
|
432 |
// NOTA: El campo de geometr?a se supone que es |
|
433 |
// el ?ltimo de la lista de campos. |
|
434 |
|
|
465 |
xml.putProperty("fields", lyrDef.getFieldNames()); |
|
466 |
xml.putProperty("FID", lyrDef.getFieldID()); |
|
467 |
xml.putProperty("THE_GEOM", lyrDef.getFieldGeometry()); |
|
435 | 468 |
xml.putProperty("whereclause", getWhereClause()); |
469 |
xml.putProperty("SRID", lyrDef.getSRID_EPSG()); |
|
436 | 470 |
|
437 | 471 |
} catch (SQLException e) { |
438 | 472 |
// TODO Auto-generated catch block |
... | ... | |
465 | 499 |
// TODO Auto-generated method stub |
466 | 500 |
|
467 | 501 |
} |
502 |
|
|
503 |
/** |
|
504 |
* @return Returns the lyrDef. |
|
505 |
*/ |
|
506 |
public DBLayerDefinition getLyrDef() { |
|
507 |
return lyrDef; |
|
508 |
} |
|
509 |
|
|
510 |
/** |
|
511 |
* @param lyrDef The lyrDef to set. |
|
512 |
*/ |
|
513 |
public void setLyrDef(DBLayerDefinition lyrDef) { |
|
514 |
this.lyrDef = lyrDef; |
|
515 |
} |
|
468 | 516 |
|
469 | 517 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/VectorialJDBCDriver.java | ||
---|---|---|
48 | 48 |
public interface VectorialJDBCDriver extends VectorialDatabaseDriver { |
49 | 49 |
/** |
50 | 50 |
* @param conn |
51 |
* @param tableName |
|
52 |
* @param fields (Todos los campos, el primero ha de ser el de las geometr?as |
|
53 |
* @param whereClause |
|
51 |
* @param lyrDef TODO |
|
54 | 52 |
* @param id_FID_field El identificador del campo que contiene una clave ?nica. 1=> primer campo, 2 => segundo campo, etc |
55 | 53 |
* |
56 | 54 |
*/ |
57 |
public void setData(Connection conn, String tableName, String fields, String whereClause, int id_FID_field);
|
|
55 |
public void setData(Connection conn, DBLayerDefinition lyrDef);
|
|
58 | 56 |
public Connection getConnection(); |
59 | 57 |
public IFeatureIterator getFeatureIterator(String sql) throws DriverException; |
60 | 58 |
public String getConnectionStringBeginning(); |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/DBLayerDefinition.java | ||
---|---|---|
54 | 54 |
private String whereClause; |
55 | 55 |
private Rectangle2D workingArea; |
56 | 56 |
private String SRID_EPSG; |
57 |
private String classToInstantiate; |
|
58 |
|
|
57 | 59 |
// private int idFieldGeometry = -1; |
58 | 60 |
private int idFieldID = -1; |
59 | 61 |
|
... | ... | |
96 | 98 |
public void setTableName(String tableName) { |
97 | 99 |
this.tableName = tableName; |
98 | 100 |
} |
101 |
/** |
|
102 |
* The returned string must contain " WHERE " clause |
|
103 |
* @return |
|
104 |
*/ |
|
99 | 105 |
public String getWhereClause() { |
100 | 106 |
return whereClause; |
101 | 107 |
} |
... | ... | |
155 | 161 |
public void setSRID_EPSG(String srid_epsg) { |
156 | 162 |
SRID_EPSG = srid_epsg; |
157 | 163 |
} |
164 |
/** |
|
165 |
* @return Returns the classToInstantiate. |
|
166 |
*/ |
|
167 |
public String getClassToInstantiate() { |
|
168 |
return classToInstantiate; |
|
169 |
} |
|
170 |
/** |
|
171 |
* @param classToInstantiate The classToInstantiate to set. |
|
172 |
*/ |
|
173 |
public void setClassToInstantiate(String classToInstantiate) { |
|
174 |
this.classToInstantiate = classToInstantiate; |
|
175 |
} |
|
158 | 176 |
} |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/operations/strategies/DBStrategy.java | ||
---|---|---|
61 | 61 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
62 | 62 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
63 | 63 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
64 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
64 | 65 |
import com.iver.cit.gvsig.fmap.layers.VectorialDBAdapter; |
65 | 66 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
66 | 67 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
... | ... | |
87 | 88 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel) throws DriverException { |
88 | 89 |
// Nos aprovechamos del SQL para lanzar la consulta |
89 | 90 |
// teniendo en cuenta el boundingbox que toca. |
90 |
FLayer capa = getCapa();
|
|
91 |
FLyrVect lyr = (FLyrVect) getCapa();
|
|
91 | 92 |
VectorialDBAdapter dbAdapter = (VectorialDBAdapter) ((SingleLayer) capa).getSource(); |
92 | 93 |
VectorialDatabaseDriver dbDriver = (VectorialDatabaseDriver) dbAdapter.getDriver(); |
93 | 94 |
dbAdapter.start(); |
94 |
Selectable selection = (Selectable) getCapa();
|
|
95 |
ICoordTrans ct = getCapa().getCoordTrans();
|
|
95 |
Selectable selection = (Selectable) lyr;
|
|
96 |
ICoordTrans ct = lyr.getCoordTrans();
|
|
96 | 97 |
FBitSet bitSet = selection.getSelection(); |
97 | 98 |
|
98 | 99 |
String strEPSG = viewPort.getProjection().getAbrev().substring(5); |
... | ... | |
105 | 106 |
// con todos los campos de Vias: 11 segundos. |
106 | 107 |
// => MODIFICAR EL getFeatureIterator para que admita los nombres |
107 | 108 |
// de los campos adem?s del rect?ngulo que pides. |
109 |
String[] usedFields = null; |
|
110 |
if (lyr.getLegend() instanceof VectorialLegend) |
|
111 |
{ |
|
112 |
VectorialLegend legend = (VectorialLegend) lyr.getLegend(); |
|
113 |
// TODO: Meter en el interaz Legend un m?todo String[] getUsedFields() |
|
114 |
} |
|
115 |
|
|
108 | 116 |
Rectangle2D rectAux = viewPort.getAdjustedExtent(); |
109 | 117 |
if (ct != null) { |
110 | 118 |
ICoordTrans invertedCT = ct.getInverted(); |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/LayerFactory.java | ||
---|---|---|
65 | 65 |
import com.iver.cit.gvsig.fmap.DriverException; |
66 | 66 |
import com.iver.cit.gvsig.fmap.ProgressListener; |
67 | 67 |
import com.iver.cit.gvsig.fmap.ViewPort; |
68 |
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition; |
|
68 | 69 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
69 | 70 |
import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
70 | 71 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
... | ... | |
75 | 76 |
import com.iver.cit.gvsig.fmap.operations.arcview.ArcJoin; |
76 | 77 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
77 | 78 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
78 |
import com.iver.utiles.StringUtilities; |
|
79 | 79 |
|
80 | 80 |
|
81 | 81 |
/** |
... | ... | |
453 | 453 |
} |
454 | 454 |
String dsName = dataSourceFactory.createTable(database, ds.getPKNames(), fieldNames, types); |
455 | 455 |
|
456 |
DBLayerDefinition lyrDef = new DBLayerDefinition(); |
|
457 |
lyrDef.setTableName(dsName); |
|
458 |
lyrDef.setLayerName(layerName); |
|
459 |
lyrDef.setFieldNames(ds.getFieldNames()); |
|
460 |
lyrDef.setFieldGeometry("the_geom"); |
|
461 |
lyrDef.setFieldID(ds.getPKNames()[0]); |
|
462 |
lyrDef.setClassToInstantiate("org.hsqldb.jdbcDriver"); |
|
463 |
|
|
456 | 464 |
dataSourceFactory.addDBDataSourceByTable(dsName, null, 0, "sa", "", database, dsName, "GDBMS HSQLDB Transactional driver"); |
457 | 465 |
DataSource local = dataSourceFactory.createRandomDataSource(dsName, DataSourceFactory.MANUAL_OPENING); |
458 | 466 |
local.start(); |
... | ... | |
496 | 504 |
VectorialJDBCDriver cacheDriver = (VectorialJDBCDriver) LayerFactory.getDM().getDriver("HSQLDB Driver"); |
497 | 505 |
Class.forName("org.hsqldb.jdbcDriver"); |
498 | 506 |
|
499 |
cacheDriver.setData(java.sql.DriverManager.getConnection("jdbc:hsqldb:file:" + database, "sa", ""), dsName, StringUtilities.getComaSeparated(local.getFieldNames()), "", local.getPrimaryKeys()[0]+1);
|
|
507 |
cacheDriver.setData(java.sql.DriverManager.getConnection("jdbc:hsqldb:file:" + database, "sa", ""), lyrDef);
|
|
500 | 508 |
cacheDriver.setWorkingArea(driver.getWorkingArea()); |
501 | 509 |
return createDBLayer(cacheDriver, layerName, proj); |
502 | 510 |
} |
Also available in: Unified diff