svn-gvsig-desktop / branches / v10 / extensions / extJDBC / src / com / iver / cit / gvsig / fmap / drivers / jdbc / postgis / PostGisDriver.java @ 20385
History | View | Annotate | Download (28 KB)
1 | 2269 | fjp | /*
|
---|---|---|---|
2 | * Created on 04-mar-2005
|
||
3 | *
|
||
4 | * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
5 | 5522 | caballero | *
|
6 | 2269 | fjp | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 | 5522 | caballero | *
|
8 | 2269 | fjp | * 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 | 5522 | caballero | *
|
13 | 2269 | fjp | * 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 | 5522 | caballero | *
|
18 | 2269 | fjp | * 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 | 5522 | caballero | *
|
22 | 2269 | fjp | * 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 | 5522 | caballero | *
|
34 | 2269 | fjp | * or
|
35 | 5522 | caballero | *
|
36 | 2269 | fjp | * IVER T.I. S.A
|
37 | * Salamanca 50
|
||
38 | * 46005 Valencia
|
||
39 | * Spain
|
||
40 | 5522 | caballero | *
|
41 | 2269 | fjp | * +34 963163400
|
42 | * dac@iver.es
|
||
43 | */
|
||
44 | package com.iver.cit.gvsig.fmap.drivers.jdbc.postgis; |
||
45 | |||
46 | import java.awt.geom.Rectangle2D; |
||
47 | 12351 | caballero | import java.io.IOException; |
48 | 3303 | fjp | import java.math.BigDecimal; |
49 | 2269 | fjp | import java.nio.ByteBuffer; |
50 | import java.sql.Connection; |
||
51 | 7095 | fjp | import java.sql.Date; |
52 | 2269 | fjp | import java.sql.ResultSet; |
53 | 11935 | caballero | import java.sql.ResultSetMetaData; |
54 | 2269 | fjp | import java.sql.SQLException; |
55 | import java.sql.Statement; |
||
56 | 7095 | fjp | import java.sql.Time; |
57 | import java.sql.Timestamp; |
||
58 | 2269 | fjp | import java.sql.Types; |
59 | 10408 | fjp | import java.util.ArrayList; |
60 | 3109 | fjp | import java.util.Hashtable; |
61 | 2269 | fjp | |
62 | import org.apache.log4j.Logger; |
||
63 | import org.postgis.PGbox2d; |
||
64 | import org.postgis.PGbox3d; |
||
65 | |||
66 | import com.hardcode.gdbms.engine.data.edition.DataWare; |
||
67 | import com.hardcode.gdbms.engine.values.Value; |
||
68 | import com.hardcode.gdbms.engine.values.ValueFactory; |
||
69 | 3095 | fjp | import com.iver.andami.messages.NotificationManager; |
70 | 2269 | fjp | import com.iver.cit.gvsig.fmap.DriverException; |
71 | 8765 | jjdelcerro | import com.iver.cit.gvsig.fmap.SqlDriveExceptionType; |
72 | 5901 | fjp | import com.iver.cit.gvsig.fmap.core.FShape; |
73 | 3095 | fjp | import com.iver.cit.gvsig.fmap.core.ICanReproject; |
74 | 2269 | fjp | import com.iver.cit.gvsig.fmap.core.IGeometry; |
75 | 11935 | caballero | import com.iver.cit.gvsig.fmap.drivers.ConnectionJDBC; |
76 | import com.iver.cit.gvsig.fmap.drivers.DBException; |
||
77 | 3251 | fjp | import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition; |
78 | 11935 | caballero | import com.iver.cit.gvsig.fmap.drivers.DefaultJDBCDriver; |
79 | 2269 | fjp | import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
80 | 11935 | caballero | import com.iver.cit.gvsig.fmap.drivers.IConnection; |
81 | 2269 | fjp | import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
82 | 12833 | caballero | import com.iver.cit.gvsig.fmap.drivers.TableDefinition; |
83 | 5714 | fjp | import com.iver.cit.gvsig.fmap.drivers.WKBParser2; |
84 | 7095 | fjp | import com.iver.cit.gvsig.fmap.drivers.XTypes; |
85 | 4740 | fjp | import com.iver.cit.gvsig.fmap.edition.EditionException; |
86 | 5595 | fjp | import com.iver.cit.gvsig.fmap.edition.IWriteable; |
87 | import com.iver.cit.gvsig.fmap.edition.IWriter; |
||
88 | 2269 | fjp | |
89 | /**
|
||
90 | * @author FJP
|
||
91 | 5522 | caballero | *
|
92 | 4171 | fjp | * TODO To change the template for this generated type comment go to Window -
|
93 | * Preferences - Java - Code Generation - Code and Comments
|
||
94 | 2269 | fjp | */
|
95 | 11935 | caballero | public class PostGisDriver extends DefaultJDBCDriver implements ICanReproject, IWriteable { |
96 | 4171 | fjp | private static Logger logger = Logger.getLogger(PostGisDriver.class |
97 | .getName()); |
||
98 | 5522 | caballero | |
99 | 4171 | fjp | private static int FETCH_SIZE = 5000; |
100 | 10726 | caballero | |
101 | 10408 | fjp | // To avoid problems when using wkb_cursor with same layer.
|
102 | // I mean, when you add twice or more the same layer using
|
||
103 | // the same connection
|
||
104 | 5522 | caballero | |
105 | 10408 | fjp | private static int CURSOR_ID = 0; |
106 | private int myCursorId; |
||
107 | 4748 | fjp | private PostGISWriter writer = new PostGISWriter(); |
108 | 5007 | fjp | private WKBParser2 parser = new WKBParser2(); |
109 | 4171 | fjp | private int fetch_min = -1; |
110 | private int fetch_max = -1; |
||
111 | private String sqlOrig; |
||
112 | |||
113 | /**
|
||
114 | * Used by setAbsolutePosition
|
||
115 | */
|
||
116 | private String sqlTotal; |
||
117 | |||
118 | private String strEPSG = null; |
||
119 | |||
120 | private String originalEPSG = null; |
||
121 | |||
122 | private Rectangle2D fullExtent = null; |
||
123 | |||
124 | private String strAux; |
||
125 | |||
126 | private String completeWhere; |
||
127 | |||
128 | private String provCursorName = null; |
||
129 | 5522 | caballero | |
130 | 4171 | fjp | int numProvCursors = 0; |
131 | 10726 | caballero | |
132 | 5901 | fjp | boolean bShapeTypeRevised = false; |
133 | 4171 | fjp | |
134 | 10457 | fjp | private int actual_position; |
135 | |||
136 | 4171 | fjp | static {
|
137 | try {
|
||
138 | 2269 | fjp | Class.forName("org.postgresql.Driver"); |
139 | } catch (ClassNotFoundException e) { |
||
140 | throw new RuntimeException(e); |
||
141 | } |
||
142 | 4171 | fjp | } |
143 | 2269 | fjp | |
144 | /**
|
||
145 | 5522 | caballero | *
|
146 | 4171 | fjp | */
|
147 | public PostGisDriver() {
|
||
148 | 10408 | fjp | // To avoid problems when using wkb_cursor with same layer.
|
149 | // I mean, when you add twice or more the same layer using
|
||
150 | // the same connection
|
||
151 | CURSOR_ID++; |
||
152 | myCursorId = CURSOR_ID; |
||
153 | 4171 | fjp | } |
154 | |||
155 | /*
|
||
156 | * (non-Javadoc)
|
||
157 | 5522 | caballero | *
|
158 | 4171 | fjp | * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
|
159 | */
|
||
160 | public DriverAttributes getDriverAttributes() {
|
||
161 | return null; |
||
162 | } |
||
163 | |||
164 | /*
|
||
165 | * (non-Javadoc)
|
||
166 | 5522 | caballero | *
|
167 | 4171 | fjp | * @see com.hardcode.driverManager.Driver#getName()
|
168 | */
|
||
169 | public String getName() { |
||
170 | return "PostGIS JDBC Driver"; |
||
171 | } |
||
172 | |||
173 | /**
|
||
174 | 12351 | caballero | * @throws IOException
|
175 | 2269 | fjp | * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShape(int)
|
176 | */
|
||
177 | 12351 | caballero | public IGeometry getShape(int index) throws IOException { |
178 | 4171 | fjp | IGeometry geom = null;
|
179 | boolean resul;
|
||
180 | try {
|
||
181 | setAbsolutePosition(index); |
||
182 | // strAux = rs.getString(1);
|
||
183 | // geom = parser.read(strAux);
|
||
184 | if (rs != null) { |
||
185 | byte[] data = rs.getBytes(1); |
||
186 | 10726 | caballero | if (data == null) // null geometry. |
187 | 6995 | fjp | return null; |
188 | 4171 | fjp | geom = parser.parse(data); |
189 | } |
||
190 | } catch (SQLException e) { |
||
191 | 12351 | caballero | throw new IOException(e.getMessage()); |
192 | 4171 | fjp | } |
193 | |||
194 | return geom;
|
||
195 | 2269 | fjp | } |
196 | 4171 | fjp | |
197 | 2269 | fjp | /**
|
198 | 4171 | fjp | * First, the geometry field. After, the rest of fields
|
199 | 5522 | caballero | *
|
200 | 4171 | fjp | * @return
|
201 | */
|
||
202 | /*
|
||
203 | * public String getTotalFields() { String strAux = "AsBinary(" +
|
||
204 | * getLyrDef().getFieldGeometry() + ")"; String[] fieldNames =
|
||
205 | * getLyrDef().getFieldNames(); for (int i=0; i< fieldNames.length; i++) {
|
||
206 | * strAux = strAux + ", " + fieldNames[i]; } return strAux; }
|
||
207 | */
|
||
208 | |||
209 | /**
|
||
210 | * Antes de llamar a esta funci?n hay que haber fijado el workingArea si se
|
||
211 | * quiere usar.
|
||
212 | 5522 | caballero | *
|
213 | 2269 | fjp | * @param conn
|
214 | 12351 | caballero | * @throws DBException
|
215 | 2269 | fjp | */
|
216 | 12351 | caballero | public void setData(IConnection conn, DBLayerDefinition lyrDef) throws DBException { |
217 | 4171 | fjp | this.conn = conn;
|
218 | 12833 | caballero | // TODO: Deber?amos poder quitar Connection de la llamada y meterlo
|
219 | 4740 | fjp | // en lyrDef desde el principio.
|
220 | 5522 | caballero | |
221 | 4740 | fjp | lyrDef.setConnection(conn); |
222 | 4171 | fjp | setLyrDef(lyrDef); |
223 | 3251 | fjp | |
224 | 12833 | caballero | getTableEPSG_and_shapeType(conn, lyrDef); |
225 | 10726 | caballero | |
226 | 6825 | fjp | getLyrDef().setSRID_EPSG(originalEPSG); |
227 | 4171 | fjp | |
228 | try {
|
||
229 | 11935 | caballero | ((ConnectionJDBC)conn).getConnection().setAutoCommit(false);
|
230 | 4171 | fjp | sqlOrig = "SELECT " + getTotalFields() + " FROM " |
231 | 11867 | jmvivo | + getLyrDef().getComposedTableName() + " ";
|
232 | 6788 | fjp | // + getLyrDef().getWhereClause();
|
233 | 4171 | fjp | if (canReproject(strEPSG)) {
|
234 | completeWhere = getCompoundWhere(sqlOrig, workingArea, strEPSG); |
||
235 | } else {
|
||
236 | completeWhere = getCompoundWhere(sqlOrig, workingArea, |
||
237 | originalEPSG); |
||
238 | } |
||
239 | 6788 | fjp | // completeWhere = getLyrDef().getWhereClause() + completeWhere;
|
240 | |||
241 | 4171 | fjp | String sqlAux = sqlOrig + completeWhere + " ORDER BY " |
242 | 6788 | fjp | + getLyrDef().getFieldID(); |
243 | 4171 | fjp | |
244 | sqlTotal = sqlAux; |
||
245 | 12140 | jaume | logger.info("SQL> " + sqlAux);
|
246 | 11935 | caballero | st = ((ConnectionJDBC)conn).getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
|
247 | 4171 | fjp | ResultSet.CONCUR_READ_ONLY);
|
248 | 12140 | jaume | st.setFetchSize(FETCH_SIZE); |
249 | 10457 | fjp | myCursorId++; |
250 | st.execute("declare " + getTableName() + myCursorId + "_wkb_cursor binary scroll cursor with hold for " + sqlAux); |
||
251 | 4171 | fjp | rs = st.executeQuery("fetch forward " + FETCH_SIZE
|
252 | 10408 | fjp | + " in " + getTableName() + myCursorId + "_wkb_cursor"); |
253 | 4171 | fjp | fetch_min = 0;
|
254 | fetch_max = FETCH_SIZE - 1;
|
||
255 | 10457 | fjp | actual_position = 0;
|
256 | 4171 | fjp | metaData = rs.getMetaData(); |
257 | doRelateID_FID(); |
||
258 | 10726 | caballero | |
259 | 5595 | fjp | writer.setCreateTable(false);
|
260 | writer.setWriteAll(false);
|
||
261 | writer.initialize(lyrDef); |
||
262 | 4171 | fjp | |
263 | 5595 | fjp | |
264 | 4171 | fjp | } catch (SQLException e) { |
265 | 12351 | caballero | throw new DBException(e); |
266 | 5595 | fjp | } catch (EditionException e) {
|
267 | 12351 | caballero | throw new DBException(e); |
268 | 12833 | caballero | } catch (Exception e) { |
269 | throw new DBException(e); |
||
270 | 4171 | fjp | } |
271 | 2269 | fjp | } |
272 | 4171 | fjp | |
273 | 2269 | fjp | /**
|
274 | 12351 | caballero | * @throws IOException
|
275 | 2269 | fjp | * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getFullExtent()
|
276 | */
|
||
277 | 12351 | caballero | public Rectangle2D getFullExtent() throws IOException { |
278 | 4171 | fjp | if (fullExtent == null) { |
279 | try {
|
||
280 | 11935 | caballero | Statement s = ((ConnectionJDBC)conn).getConnection().createStatement();
|
281 | 4171 | fjp | ResultSet r = s.executeQuery("SELECT extent(" |
282 | + getLyrDef().getFieldGeometry() |
||
283 | 11867 | jmvivo | + ") AS FullExtent FROM " + getLyrDef().getComposedTableName()
|
284 | 4171 | fjp | + " " + getCompleteWhere());
|
285 | r.next(); |
||
286 | String strAux = r.getString(1); |
||
287 | System.out.println("fullExtent = " + strAux); |
||
288 | 10726 | caballero | if (strAux == null) |
289 | 6621 | fjp | { |
290 | logger.debug("La capa " + getLyrDef().getName() + " no tiene FULLEXTENT"); |
||
291 | return null; |
||
292 | } |
||
293 | 4171 | fjp | if (strAux.startsWith("BOX3D")) { |
294 | 2269 | fjp | PGbox3d regeom = new PGbox3d(strAux);
|
295 | 4171 | fjp | double x = regeom.getLLB().x;
|
296 | double y = regeom.getLLB().y;
|
||
297 | double w = regeom.getURT().x - x;
|
||
298 | double h = regeom.getURT().y - y;
|
||
299 | fullExtent = new Rectangle2D.Double(x, y, w, h); |
||
300 | } else {
|
||
301 | 2269 | fjp | PGbox2d regeom = new PGbox2d(strAux);
|
302 | 4171 | fjp | double x = regeom.getLLB().x;
|
303 | double y = regeom.getLLB().y;
|
||
304 | double w = regeom.getURT().x - x;
|
||
305 | double h = regeom.getURT().y - y;
|
||
306 | fullExtent = new Rectangle2D.Double(x, y, w, h); |
||
307 | 2269 | fjp | } |
308 | 4171 | fjp | } catch (SQLException e) { |
309 | 12351 | caballero | throw new IOException(e.getMessage()); |
310 | 4171 | fjp | } |
311 | |||
312 | } |
||
313 | return fullExtent;
|
||
314 | 2269 | fjp | } |
315 | 3095 | fjp | |
316 | 4171 | fjp | /*
|
317 | * (non-Javadoc)
|
||
318 | 5522 | caballero | *
|
319 | 4171 | fjp | * @see com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver#getGeometryIterator(java.lang.String)
|
320 | */
|
||
321 | public IFeatureIterator getFeatureIterator(String sql) |
||
322 | throws com.iver.cit.gvsig.fmap.DriverException {
|
||
323 | PostGisFeatureIterator geomIterator = null;
|
||
324 | try {
|
||
325 | // st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
|
||
326 | // ResultSet.CONCUR_READ_ONLY);
|
||
327 | |||
328 | 5522 | caballero | |
329 | 4171 | fjp | if (provCursorName != null) { |
330 | /* st.execute("BEGIN");
|
||
331 | st.execute("CLOSE " + provCursorName);
|
||
332 | bCursorActivo = false;
|
||
333 | st.execute("COMMIT"); */
|
||
334 | numProvCursors++; |
||
335 | } |
||
336 | // st.execute("BEGIN");
|
||
337 | 10408 | fjp | provCursorName = getTableName() + myCursorId + "wkb_cursor_prov_" + System.currentTimeMillis() + "" + numProvCursors; |
338 | 4171 | fjp | |
339 | // st.execute("BEGIN");
|
||
340 | bCursorActivo = true;
|
||
341 | // ResultSet rs = st.executeQuery(sql);
|
||
342 | 11935 | caballero | geomIterator = new PostGisFeatureIterator(((ConnectionJDBC)conn).getConnection(), provCursorName, sql);
|
343 | 4171 | fjp | geomIterator.setLyrDef(getLyrDef()); |
344 | } catch (SQLException e) { |
||
345 | e.printStackTrace(); |
||
346 | 8765 | jjdelcerro | SqlDriveExceptionType type = new SqlDriveExceptionType();
|
347 | type.setDriverName("PostGIS Driver");
|
||
348 | type.setSql(sql); |
||
349 | type.setLayerName(getTableName()); |
||
350 | type.setSchema(null);
|
||
351 | throw new com.iver.cit.gvsig.fmap.DriverException(e, type); |
||
352 | // throw new DriverException(e);
|
||
353 | 4171 | fjp | // return null;
|
354 | } |
||
355 | |||
356 | return geomIterator;
|
||
357 | } |
||
358 | |||
359 | public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG) |
||
360 | throws DriverException {
|
||
361 | if (workingArea != null) |
||
362 | r = r.createIntersection(workingArea); |
||
363 | |||
364 | String sqlAux;
|
||
365 | if (canReproject(strEPSG)) {
|
||
366 | sqlAux = sqlOrig + getCompoundWhere(sqlOrig, r, strEPSG); |
||
367 | } else {
|
||
368 | sqlAux = sqlOrig + getCompoundWhere(sqlOrig, r, originalEPSG); |
||
369 | } |
||
370 | |||
371 | System.out.println("SqlAux getFeatureIterator = " + sqlAux); |
||
372 | |||
373 | return getFeatureIterator(sqlAux);
|
||
374 | } |
||
375 | |||
376 | 2269 | fjp | /**
|
377 | 4171 | fjp | * Le pasas el rect?ngulo que quieres pedir. La primera vez es el
|
378 | * workingArea, y las siguientes una interseccion de este rectangulo con el
|
||
379 | * workingArea
|
||
380 | 5522 | caballero | *
|
381 | 4171 | fjp | * @param r
|
382 | * @param strEPSG
|
||
383 | * @return
|
||
384 | */
|
||
385 | private String getCompoundWhere(String sql, Rectangle2D r, String strEPSG) { |
||
386 | if (r == null) |
||
387 | 6788 | fjp | return getWhereClause();
|
388 | 4171 | fjp | |
389 | double xMin = r.getMinX();
|
||
390 | double yMin = r.getMinY();
|
||
391 | double xMax = r.getMaxX();
|
||
392 | double yMax = r.getMaxY();
|
||
393 | String wktBox = "GeometryFromText('LINESTRING(" + xMin + " " + yMin |
||
394 | + ", " + xMax + " " + yMin + ", " + xMax + " " + yMax + ", " |
||
395 | + xMin + " " + yMax + ")', " + strEPSG + ")"; |
||
396 | String sqlAux;
|
||
397 | if (getWhereClause().indexOf("WHERE") != -1) |
||
398 | 6788 | fjp | sqlAux = getWhereClause() + " AND " + getLyrDef().getFieldGeometry() + " && " + wktBox; |
399 | 4171 | fjp | else
|
400 | sqlAux = "WHERE " + getLyrDef().getFieldGeometry() + " && " |
||
401 | + wktBox; |
||
402 | return sqlAux;
|
||
403 | } |
||
404 | |||
405 | /**
|
||
406 | 11935 | caballero | * @see com.iver.cit.gvsig.fmap.drivers.IVectorialDatabaseDriver#getConnectionStringBeginning()
|
407 | 2269 | fjp | */
|
408 | public String getConnectionStringBeginning() { |
||
409 | return "jdbc:postgresql:"; |
||
410 | } |
||
411 | 3303 | fjp | |
412 | 4171 | fjp | /*
|
413 | * (non-Javadoc)
|
||
414 | 5522 | caballero | *
|
415 | 4171 | fjp | * @see com.iver.cit.gvsig.fmap.drivers.DefaultDBDriver#getFieldValue(long,
|
416 | * int)
|
||
417 | */
|
||
418 | public Value getFieldValue(long rowIndex, int idField) |
||
419 | throws com.hardcode.gdbms.engine.data.driver.DriverException {
|
||
420 | boolean resul;
|
||
421 | // EL ABSOLUTE NO HACE QUE SE VUELVAN A LEER LAS
|
||
422 | // FILAS, ASI QUE MONTAMOS ESTA HISTORIA PARA QUE
|
||
423 | // LO HAGA
|
||
424 | // System.out.println("getShape " + index);
|
||
425 | int index = (int) (rowIndex); |
||
426 | try {
|
||
427 | setAbsolutePosition(index); |
||
428 | int fieldId = idField + 2; |
||
429 | 12559 | jmvivo | return getFieldValue(rs, fieldId);
|
430 | |||
431 | } catch (SQLException e) { |
||
432 | // TODO Auto-generated catch block
|
||
433 | throw new com.hardcode.gdbms.engine.data.driver.DriverException(e |
||
434 | .getMessage()); |
||
435 | } |
||
436 | } |
||
437 | |||
438 | static Value getFieldValue(ResultSet aRs, int fieldId) |
||
439 | throws SQLException { |
||
440 | ResultSetMetaData metaData = aRs.getMetaData();
|
||
441 | byte[] byteBuf = aRs.getBytes(fieldId); |
||
442 | if (byteBuf == null) |
||
443 | return ValueFactory.createNullValue();
|
||
444 | else {
|
||
445 | ByteBuffer buf = ByteBuffer.wrap(byteBuf); |
||
446 | if (metaData.getColumnType(fieldId) == Types.VARCHAR) |
||
447 | return ValueFactory.createValue(aRs.getString(fieldId));
|
||
448 | if (metaData.getColumnType(fieldId) == Types.FLOAT) |
||
449 | return ValueFactory.createValue(buf.getFloat());
|
||
450 | if (metaData.getColumnType(fieldId) == Types.DOUBLE) |
||
451 | return ValueFactory.createValue(buf.getDouble());
|
||
452 | if (metaData.getColumnType(fieldId) == Types.REAL) |
||
453 | return ValueFactory.createValue(buf.getFloat());
|
||
454 | if (metaData.getColumnType(fieldId) == Types.INTEGER) |
||
455 | return ValueFactory.createValue(buf.getInt());
|
||
456 | if (metaData.getColumnType(fieldId) == Types.BIGINT) |
||
457 | return ValueFactory.createValue(buf.getLong());
|
||
458 | if (metaData.getColumnType(fieldId) == Types.BIT) |
||
459 | return ValueFactory.createValue((byteBuf[0] == 1)); |
||
460 | if (metaData.getColumnType(fieldId) == Types.BOOLEAN) |
||
461 | return ValueFactory.createValue(aRs.getBoolean(fieldId));
|
||
462 | if (metaData.getColumnType(fieldId) == Types.DATE) |
||
463 | { |
||
464 | long daysAfter2000 = buf.getInt() + 1; |
||
465 | long msecs = daysAfter2000*24*60*60*1000; |
||
466 | long real_msecs_date1 = (long) (XTypes.NUM_msSecs2000 + msecs); |
||
467 | Date realDate1 = new Date(real_msecs_date1); |
||
468 | return ValueFactory.createValue(realDate1);
|
||
469 | } |
||
470 | if (metaData.getColumnType(fieldId) == Types.TIME) |
||
471 | { |
||
472 | // TODO:
|
||
473 | 7095 | fjp | // throw new RuntimeException("TIME type not implemented yet");
|
474 | 12559 | jmvivo | return ValueFactory.createValue("NOT IMPLEMENTED YET"); |
475 | } |
||
476 | if (metaData.getColumnType(fieldId) == Types.TIMESTAMP) |
||
477 | { |
||
478 | double segsReferredTo2000 = buf.getDouble();
|
||
479 | long real_msecs = (long) (XTypes.NUM_msSecs2000 + segsReferredTo2000*1000); |
||
480 | Timestamp valTimeStamp = new Timestamp(real_msecs); |
||
481 | return ValueFactory.createValue(valTimeStamp);
|
||
482 | } |
||
483 | 7095 | fjp | |
484 | 12559 | jmvivo | if (metaData.getColumnType(fieldId) == Types.NUMERIC) { |
485 | // System.out.println(metaData.getColumnName(fieldId) + " "
|
||
486 | // + metaData.getColumnClassName(fieldId));
|
||
487 | short ndigits = buf.getShort();
|
||
488 | short weight = buf.getShort();
|
||
489 | short sign = buf.getShort();
|
||
490 | short dscale = buf.getShort();
|
||
491 | String strAux;
|
||
492 | if (sign == 0) |
||
493 | strAux = "+";
|
||
494 | else
|
||
495 | strAux = "-";
|
||
496 | 4171 | fjp | |
497 | 12559 | jmvivo | for (int iDigit = 0; iDigit < ndigits; iDigit++) { |
498 | short digit = buf.getShort();
|
||
499 | strAux = strAux + digit; |
||
500 | if (iDigit == weight)
|
||
501 | strAux = strAux + ".";
|
||
502 | 4171 | fjp | |
503 | } |
||
504 | 12559 | jmvivo | strAux = strAux + "0";
|
505 | BigDecimal dec;
|
||
506 | dec = new BigDecimal(strAux); |
||
507 | // System.out.println(ndigits + "_" + weight + "_" + dscale
|
||
508 | // + "_" + strAux);
|
||
509 | // System.out.println(strAux + " Big= " + dec);
|
||
510 | return ValueFactory.createValue(dec.doubleValue());
|
||
511 | } |
||
512 | 4171 | fjp | |
513 | } |
||
514 | return ValueFactory.createNullValue();
|
||
515 | |||
516 | } |
||
517 | |||
518 | public void open() throws com.iver.cit.gvsig.fmap.DriverException { |
||
519 | /*
|
||
520 | * try { st = conn.createStatement(); st.setFetchSize(2000); if
|
||
521 | * (bCursorActivo) close(); st.execute("declare wkb_cursor binary cursor
|
||
522 | * for " + sqlOrig); rs = st.executeQuery("fetch forward all in
|
||
523 | * wkb_cursor"); // st.execute("BEGIN"); bCursorActivo = true; } catch
|
||
524 | * (SQLException e) { e.printStackTrace(); throw new
|
||
525 | * com.iver.cit.gvsig.fmap.DriverException(e); }
|
||
526 | */
|
||
527 | |||
528 | } |
||
529 | |||
530 | private void setAbsolutePosition(int index) throws SQLException { |
||
531 | // TODO: USAR LIMIT Y ORDER BY, Y HACERLO TAMBI?N PARA
|
||
532 | // MYSQL
|
||
533 | |||
534 | // EL ABSOLUTE NO HACE QUE SE VUELVAN A LEER LAS
|
||
535 | // FILAS, ASI QUE MONTAMOS ESTA HISTORIA PARA QUE
|
||
536 | // LO HAGA
|
||
537 | // System.out.println("getShape " + index + " fetchMin=" + fetch_min + "
|
||
538 | // fetchMax=" + fetch_max);
|
||
539 | 10726 | caballero | |
540 | 10457 | fjp | if ((index >= fetch_min) && (index <= fetch_max))
|
541 | { |
||
542 | // Est? en el intervalo, as? que lo podemos posicionar
|
||
543 | 10726 | caballero | |
544 | 10457 | fjp | } |
545 | else
|
||
546 | { |
||
547 | // calculamos el intervalo correcto
|
||
548 | fetch_min = (index / FETCH_SIZE) * FETCH_SIZE; |
||
549 | 17397 | vcaballero | fetch_max = fetch_min + FETCH_SIZE - 1;
|
550 | 10457 | fjp | // y cogemos ese cacho
|
551 | rs.close(); |
||
552 | 18448 | vcaballero | myCursorId++; |
553 | 20385 | vcaballero | st.execute("declare " + getTableName() + myCursorId + "_wkb_cursorAbsolutePosition binary scroll cursor with hold for " + sqlTotal); |
554 | 10457 | fjp | st.executeQuery("fetch absolute " + fetch_min
|
555 | 20385 | vcaballero | + " in " + getTableName() + myCursorId + "_wkb_cursorAbsolutePosition"); |
556 | 4171 | fjp | |
557 | 10457 | fjp | rs = st.executeQuery("fetch forward " + FETCH_SIZE
|
558 | 20385 | vcaballero | + " in " + getTableName() + myCursorId + "_wkb_cursorAbsolutePosition"); |
559 | 10726 | caballero | |
560 | 4171 | fjp | } |
561 | 10457 | fjp | rs.absolute(index - fetch_min + 1);
|
562 | actual_position = index; |
||
563 | 4171 | fjp | |
564 | } |
||
565 | |||
566 | 2269 | fjp | /**
|
567 | 11935 | caballero | * @see com.iver.cit.gvsig.fmap.drivers.IVectorialDatabaseDriver#getGeometryField(java.lang.String)
|
568 | 2269 | fjp | */
|
569 | public String getGeometryField(String fieldName) { |
||
570 | return "ASBINARY(" + fieldName + ", 'XDR')"; |
||
571 | } |
||
572 | 3095 | fjp | |
573 | 4171 | fjp | /**
|
574 | * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
|
||
575 | */
|
||
576 | public int[] getPrimaryKeys() |
||
577 | throws com.hardcode.gdbms.engine.data.driver.DriverException {
|
||
578 | // TODO Auto-generated method stub
|
||
579 | return null; |
||
580 | } |
||
581 | 3268 | fjp | |
582 | 4171 | fjp | /**
|
583 | 11935 | caballero | * @see com.iver.cit.gvsig.fmap.drivers.IVectorialJDBCDriver#getDefaultPort()
|
584 | 4171 | fjp | */
|
585 | public int getDefaultPort() { |
||
586 | return 5432; |
||
587 | } |
||
588 | 3268 | fjp | |
589 | 4171 | fjp | /**
|
590 | * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
|
||
591 | */
|
||
592 | public void write(DataWare arg0) |
||
593 | throws com.hardcode.gdbms.engine.data.driver.DriverException {
|
||
594 | // TODO Auto-generated method stub
|
||
595 | |||
596 | } |
||
597 | |||
598 | /*
|
||
599 | * (non-Javadoc)
|
||
600 | 5522 | caballero | *
|
601 | 4171 | fjp | * @see com.iver.cit.gvsig.fmap.core.ICanReproject#getSourceProjection()
|
602 | */
|
||
603 | 12833 | caballero | public String getSourceProjection(IConnection conn,DBLayerDefinition dbld) { |
604 | 4171 | fjp | if (originalEPSG == null) |
605 | 12833 | caballero | getTableEPSG_and_shapeType(conn,dbld); |
606 | 4171 | fjp | return originalEPSG;
|
607 | } |
||
608 | |||
609 | 4335 | fjp | /**
|
610 | 5522 | caballero | * Las tablas con geometr?as est?n en la tabla GEOMETRY_COLUMNS y de
|
611 | 4335 | fjp | * ah? sacamos en qu? proyecci?n est?n.
|
612 | * El problema es que si el usuario hace una vista de esa
|
||
613 | * tabla, no estar? dada de alta aqu? y entonces gvSIG
|
||
614 | * no se entera en qu? proyecci?n est? trabajando (y le
|
||
615 | * ponemos un -1 como mal menor). El -1 implica que luego
|
||
616 | * no podremos reproyectar al vuelo desde la base de datos.
|
||
617 | 10457 | fjp | * OJO: ES SENSIBLE A MAYUSCULAS / MINUSCULAS!!!
|
618 | 12833 | caballero | * @param dbld
|
619 | 4335 | fjp | */
|
620 | 12833 | caballero | private void getTableEPSG_and_shapeType(IConnection conn, DBLayerDefinition dbld) { |
621 | 4171 | fjp | try {
|
622 | 11935 | caballero | Statement stAux = ((ConnectionJDBC)conn).getConnection().createStatement();
|
623 | 4171 | fjp | |
624 | 11953 | jmvivo | // String sql = "SELECT * FROM GEOMETRY_COLUMNS WHERE F_TABLE_NAME = '"
|
625 | // + getTableName() + "' AND F_GEOMETRY_COLUMN = '" + getLyrDef().getFieldGeometry() + "'";
|
||
626 | 11959 | jmvivo | String sql;
|
627 | 12833 | caballero | if (dbld.getSchema() == null || dbld.getSchema().equals("")){ |
628 | 12513 | jmvivo | sql = "SELECT * FROM GEOMETRY_COLUMNS WHERE F_TABLE_SCHEMA = current_schema() AND F_TABLE_NAME = '"
|
629 | 12833 | caballero | + dbld.getTableName() + "' AND F_GEOMETRY_COLUMN = '" + dbld.getFieldGeometry() + "'"; |
630 | 11959 | jmvivo | }else{
|
631 | 12833 | caballero | sql = "SELECT * FROM GEOMETRY_COLUMNS WHERE F_TABLE_SCHEMA = '"+ dbld.getSchema() + "' AND F_TABLE_NAME = '" |
632 | + dbld.getTableName() + "' AND F_GEOMETRY_COLUMN = '" + dbld.getFieldGeometry() + "'"; |
||
633 | 11959 | jmvivo | } |
634 | 11953 | jmvivo | |
635 | 4171 | fjp | ResultSet rs = stAux.executeQuery(sql);
|
636 | rs.next(); |
||
637 | originalEPSG = "" + rs.getInt("SRID"); |
||
638 | 5901 | fjp | String geometryType = rs.getString("TYPE"); |
639 | int shapeType = FShape.MULTI;
|
||
640 | if (geometryType.compareToIgnoreCase("POINT") == 0) |
||
641 | shapeType = FShape.POINT; |
||
642 | 12833 | caballero | else if (geometryType.compareToIgnoreCase("LINESTRING") == 0) |
643 | 5901 | fjp | shapeType = FShape.LINE; |
644 | 12833 | caballero | else if (geometryType.compareToIgnoreCase("POLYGON") == 0) |
645 | 5901 | fjp | shapeType = FShape.POLYGON; |
646 | 12833 | caballero | else if (geometryType.compareToIgnoreCase("MULTIPOINT") == 0) |
647 | 5901 | fjp | shapeType = FShape.POINT; |
648 | 12833 | caballero | else if (geometryType.compareToIgnoreCase("MULTILINESTRING") == 0) |
649 | 5901 | fjp | shapeType = FShape.LINE; |
650 | 12833 | caballero | else if (geometryType.compareToIgnoreCase("MULTIPOLYGON") == 0) |
651 | 10726 | caballero | shapeType = FShape.POLYGON; |
652 | |||
653 | 12833 | caballero | dbld.setShapeType(shapeType); |
654 | 4171 | fjp | rs.close(); |
655 | } catch (SQLException e) { |
||
656 | // TODO Auto-generated catch block
|
||
657 | 4335 | fjp | originalEPSG = "-1";
|
658 | logger.error(e); |
||
659 | 4171 | fjp | e.printStackTrace(); |
660 | } |
||
661 | |||
662 | } |
||
663 | |||
664 | /*
|
||
665 | * (non-Javadoc)
|
||
666 | 5522 | caballero | *
|
667 | 4171 | fjp | * @see com.iver.cit.gvsig.fmap.core.ICanReproject#getDestProjection()
|
668 | */
|
||
669 | public String getDestProjection() { |
||
670 | return strEPSG;
|
||
671 | } |
||
672 | |||
673 | /*
|
||
674 | * (non-Javadoc)
|
||
675 | 5522 | caballero | *
|
676 | 4171 | fjp | * @see com.iver.cit.gvsig.fmap.core.ICanReproject#setDestProjection(java.lang.String)
|
677 | */
|
||
678 | public void setDestProjection(String toEPSG) { |
||
679 | this.strEPSG = toEPSG;
|
||
680 | } |
||
681 | |||
682 | /*
|
||
683 | * (non-Javadoc)
|
||
684 | 5522 | caballero | *
|
685 | 4171 | fjp | * @see com.iver.cit.gvsig.fmap.core.ICanReproject#canReproject(java.lang.String)
|
686 | */
|
||
687 | public boolean canReproject(String toEPSGdestinyProjection) { |
||
688 | // TODO POR AHORA, REPROYECTA SIEMPRE gvSIG.
|
||
689 | return false; |
||
690 | } |
||
691 | |||
692 | /*
|
||
693 | * (non-Javadoc)
|
||
694 | 5522 | caballero | *
|
695 | 4171 | fjp | * @see com.iver.cit.gvsig.fmap.drivers.DefaultDBDriver#doRelateID_FID()
|
696 | */
|
||
697 | 12351 | caballero | protected void doRelateID_FID() throws DBException { |
698 | 4171 | fjp | hashRelate = new Hashtable(); |
699 | try {
|
||
700 | String strSQL = "SELECT " + getLyrDef().getFieldID() + " FROM " |
||
701 | 11867 | jmvivo | + getLyrDef().getComposedTableName() + " ";
|
702 | 6788 | fjp | // + getLyrDef().getWhereClause();
|
703 | 4171 | fjp | if (canReproject(strEPSG)) {
|
704 | strSQL = strSQL |
||
705 | + getCompoundWhere(strSQL, workingArea, strEPSG); |
||
706 | } else {
|
||
707 | strSQL = strSQL |
||
708 | + getCompoundWhere(strSQL, workingArea, originalEPSG); |
||
709 | } |
||
710 | 5570 | fjp | strSQL = strSQL + " ORDER BY " + getLyrDef().getFieldID();
|
711 | 11935 | caballero | Statement s = ((ConnectionJDBC)getConnection()).getConnection().createStatement(
|
712 | 4171 | fjp | ResultSet.TYPE_SCROLL_INSENSITIVE,
|
713 | ResultSet.CONCUR_READ_ONLY);
|
||
714 | 12140 | jaume | s.setFetchSize(FETCH_SIZE); |
715 | 4171 | fjp | ResultSet r = s.executeQuery(strSQL);
|
716 | int id = 0; |
||
717 | String gid;
|
||
718 | while (r.next()) {
|
||
719 | gid = r.getString(1);
|
||
720 | Value aux = ValueFactory.createValue(gid); |
||
721 | hashRelate.put(aux, new Integer(id)); |
||
722 | 12140 | jaume | // System.out.println("ASOCIANDO CLAVE " + aux + " CON VALOR " + id);
|
723 | 4171 | fjp | id++; |
724 | 12140 | jaume | // System.out.println("Row " + id + ":" + strAux);
|
725 | 4171 | fjp | } |
726 | s.close(); |
||
727 | numReg = id; |
||
728 | |||
729 | /*
|
||
730 | * for (int index = 0; index < getShapeCount(); index++) { Value aux =
|
||
731 | * getFieldValue(index, idFID_FieldName-2); hashRelate.put(aux, new
|
||
732 | * Integer(index)); // System.out.println("Row " + index + " clave=" +
|
||
733 | * aux); }
|
||
734 | */
|
||
735 | /*
|
||
736 | * int index = 0;
|
||
737 | 5522 | caballero | *
|
738 | 4171 | fjp | * while (rs.next()) { Value aux = getFieldValue(index,
|
739 | * idFID_FieldName-2); hashRelate.put(aux, new Integer(index));
|
||
740 | * index++; System.out.println("Row " + index + " clave=" + aux); }
|
||
741 | * numReg = index;
|
||
742 | */
|
||
743 | // rs.beforeFirst();
|
||
744 | /*
|
||
745 | * } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) { //
|
||
746 | * TODO Auto-generated catch block e.printStackTrace();
|
||
747 | */
|
||
748 | } catch (SQLException e) { |
||
749 | 12351 | caballero | throw new DBException(e); |
750 | 4171 | fjp | } |
751 | } |
||
752 | |||
753 | public String getSqlTotal() { |
||
754 | return sqlTotal;
|
||
755 | } |
||
756 | |||
757 | /**
|
||
758 | * @return Returns the completeWhere.
|
||
759 | */
|
||
760 | public String getCompleteWhere() { |
||
761 | return completeWhere;
|
||
762 | } |
||
763 | |||
764 | /*
|
||
765 | * (non-Javadoc)
|
||
766 | 5522 | caballero | *
|
767 | 4171 | fjp | * @see com.iver.cit.gvsig.fmap.drivers.DefaultDBDriver#close()
|
768 | */
|
||
769 | public void close() { |
||
770 | super.close();
|
||
771 | /*
|
||
772 | * if (bCursorActivo) { try { // st =
|
||
773 | * conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
|
||
774 | * ResultSet.CONCUR_READ_ONLY); st.execute("CLOSE wkb_cursor_prov"); //
|
||
775 | * st.close(); } catch (SQLException e) { // TODO Auto-generated catch
|
||
776 | * block e.printStackTrace(); } bCursorActivo = false; }
|
||
777 | */
|
||
778 | |||
779 | } |
||
780 | |||
781 | /*
|
||
782 | * (non-Javadoc)
|
||
783 | 5522 | caballero | *
|
784 | 4171 | fjp | * @see com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver#getFeatureIterator(java.awt.geom.Rectangle2D,
|
785 | * java.lang.String, java.lang.String[])
|
||
786 | */
|
||
787 | public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG, |
||
788 | String[] alphaNumericFieldsNeeded) throws DriverException { |
||
789 | 8765 | jjdelcerro | String sqlAux = null; |
790 | 4171 | fjp | try {
|
791 | if (workingArea != null) |
||
792 | r = r.createIntersection(workingArea); |
||
793 | // if (getLyrDef()==null){
|
||
794 | // load();
|
||
795 | // throw new DriverException("Fallo de la conexi?n");
|
||
796 | // }
|
||
797 | String strAux = getGeometryField(getLyrDef().getFieldGeometry());
|
||
798 | |||
799 | boolean found = false; |
||
800 | if (alphaNumericFieldsNeeded != null) { |
||
801 | for (int i = 0; i < alphaNumericFieldsNeeded.length; i++) { |
||
802 | strAux = strAux + ", " + alphaNumericFieldsNeeded[i];
|
||
803 | if (alphaNumericFieldsNeeded[i].equals(getLyrDef()
|
||
804 | .getFieldID())) |
||
805 | found = true;
|
||
806 | } |
||
807 | } |
||
808 | // Nos aseguramos de pedir siempre el campo ID
|
||
809 | if (found == false) |
||
810 | strAux = strAux + ", " + getLyrDef().getFieldID();
|
||
811 | |||
812 | String sqlProv = "SELECT " + strAux + " FROM " |
||
813 | 11867 | jmvivo | + getLyrDef().getComposedTableName() + " ";
|
814 | 6788 | fjp | // + getLyrDef().getWhereClause();
|
815 | 4171 | fjp | |
816 | 10726 | caballero | |
817 | 4171 | fjp | if (canReproject(strEPSG)) {
|
818 | sqlAux = sqlProv + getCompoundWhere(sqlProv, r, strEPSG); |
||
819 | } else {
|
||
820 | sqlAux = sqlProv + getCompoundWhere(sqlProv, r, originalEPSG); |
||
821 | } |
||
822 | |||
823 | System.out.println("SqlAux getFeatureIterator = " + sqlAux); |
||
824 | |||
825 | return getFeatureIterator(sqlAux);
|
||
826 | } catch (Exception e) { |
||
827 | 8765 | jjdelcerro | e.printStackTrace(); |
828 | SqlDriveExceptionType type = new SqlDriveExceptionType();
|
||
829 | type.setDriverName("PostGIS Driver");
|
||
830 | type.setSql(sqlAux); |
||
831 | type.setLayerName(getTableName()); |
||
832 | type.setSchema(null);
|
||
833 | throw new com.iver.cit.gvsig.fmap.DriverException(e, type); |
||
834 | 10726 | caballero | |
835 | 8765 | jjdelcerro | // throw new DriverException(e);
|
836 | 3462 | caballero | } |
837 | 4171 | fjp | } |
838 | |||
839 | 5595 | fjp | /* public void preProcess() throws EditionException {
|
840 | 4740 | fjp | writer.preProcess();
|
841 | }
|
||
842 | |||
843 | public void process(IRowEdited row) throws EditionException {
|
||
844 | writer.process(row);
|
||
845 | }
|
||
846 | |||
847 | public void postProcess() throws EditionException {
|
||
848 | writer.postProcess();
|
||
849 | }
|
||
850 | |||
851 | public String getCapability(String capability) {
|
||
852 | return writer.getCapability(capability);
|
||
853 | }
|
||
854 | |||
855 | public void setCapabilities(Properties capabilities) {
|
||
856 | writer.setCapabilities(capabilities);
|
||
857 | }
|
||
858 | |||
859 | public boolean canWriteAttribute(int sqlType) {
|
||
860 | return writer.canWriteAttribute(sqlType);
|
||
861 | }
|
||
862 | |||
863 | public boolean canWriteGeometry(int gvSIGgeometryType) {
|
||
864 | return writer.canWriteGeometry(gvSIGgeometryType);
|
||
865 | }
|
||
866 | |||
867 | 5558 | fjp | public void initialize(ITableDefinition layerDef) throws EditionException {
|
868 | 4740 | fjp | writer.setCreateTable(false);
|
869 | writer.setWriteAll(false);
|
||
870 | // Obtenemos el DBLayerDefinition a partir del driver
|
||
871 | 5522 | caballero | |
872 | DBLayerDefinition dbLyrDef = getLyrDef();
|
||
873 | |||
874 | |||
875 | 4740 | fjp | writer.initialize(dbLyrDef);
|
876 | }
|
||
877 | 5595 | fjp | */
|
878 | 5522 | caballero | public boolean isWritable() { |
879 | return true; |
||
880 | 10726 | caballero | } |
881 | 5595 | fjp | |
882 | public IWriter getWriter() {
|
||
883 | return writer;
|
||
884 | 5522 | caballero | } |
885 | 5402 | fjp | |
886 | 11935 | caballero | public String[] getGeometryFieldsCandidates(IConnection conn, String table_name) throws DBException { |
887 | ArrayList list = new ArrayList(); |
||
888 | try{
|
||
889 | Statement stAux = ((ConnectionJDBC)conn).getConnection().createStatement();
|
||
890 | String[] tokens = table_name.split("\\u002E", 2); |
||
891 | 11867 | jmvivo | String sql;
|
892 | if (tokens.length > 1) |
||
893 | { |
||
894 | sql = "select * from GEOMETRY_COLUMNS WHERE F_TABLE_SCHEMA = '"
|
||
895 | 11935 | caballero | + tokens[0] + "' AND F_TABLE_NAME = '" + |
896 | 11867 | jmvivo | tokens[1] + "'"; |
897 | } |
||
898 | else
|
||
899 | { |
||
900 | sql = "select * from GEOMETRY_COLUMNS" +
|
||
901 | 14554 | jmvivo | " where F_TABLE_SCHEMA = current_schema() AND F_TABLE_NAME = " + "'" + table_name + "'"; |
902 | 5522 | caballero | |
903 | 11867 | jmvivo | } |
904 | |||
905 | // String sql = "SELECT * FROM GEOMETRY_COLUMNS WHERE F_TABLE_NAME = '"
|
||
906 | // + table_name + "'";
|
||
907 | 11935 | caballero | |
908 | 10408 | fjp | ResultSet rs = stAux.executeQuery(sql);
|
909 | while (rs.next())
|
||
910 | { |
||
911 | String geomCol = rs.getString("F_GEOMETRY_COLUMN"); |
||
912 | list.add(geomCol); |
||
913 | } |
||
914 | rs.close(); stAux.close(); |
||
915 | 11935 | caballero | } catch (SQLException e) { |
916 | throw new DBException(e); |
||
917 | } |
||
918 | return (String[]) list.toArray(new String[0]); |
||
919 | 10408 | fjp | } |
920 | 12351 | caballero | // public String[] getTableFields(IConnection conex, String table) throws DBException {
|
921 | // try{
|
||
922 | // Statement st = ((ConnectionJDBC)conex).getConnection().createStatement();
|
||
923 | // // ResultSet rs = dbmd.getTables(catalog, null, dbLayerDefinition.getTable(), null);
|
||
924 | // ResultSet rs = st.executeQuery("select * from " + table + " LIMIT 1");
|
||
925 | // ResultSetMetaData rsmd = rs.getMetaData();
|
||
926 | //
|
||
927 | // String[] ret = new String[rsmd.getColumnCount()];
|
||
928 | //
|
||
929 | // for (int i = 0; i < ret.length; i++) {
|
||
930 | // ret[i] = rsmd.getColumnName(i+1);
|
||
931 | // }
|
||
932 | //
|
||
933 | // return ret;
|
||
934 | // }catch (SQLException e) {
|
||
935 | // throw new DBException(e);
|
||
936 | // }
|
||
937 | // }
|
||
938 | // public String[] getTableNames(IConnection conn, String catalog) throws DBException {
|
||
939 | // // TODO Auto-generated method stub
|
||
940 | // return super.getTableNames(conn, catalog);
|
||
941 | // }
|
||
942 | 10408 | fjp | |
943 | 2269 | fjp | } |