Revision 1854 branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGisDriver.java
PostGisDriver.java | ||
---|---|---|
44 | 44 |
package com.iver.cit.gvsig.fmap.drivers.jdbc.postgis; |
45 | 45 |
|
46 | 46 |
import java.awt.geom.Rectangle2D; |
47 |
import java.nio.ByteBuffer; |
|
47 | 48 |
import java.sql.Connection; |
48 | 49 |
import java.sql.ResultSet; |
49 | 50 |
import java.sql.SQLException; |
50 | 51 |
import java.sql.Statement; |
52 |
import java.sql.Types; |
|
51 | 53 |
|
52 | 54 |
import org.postgis.PGbox3d; |
53 | 55 |
|
56 |
import com.hardcode.gdbms.engine.values.Value; |
|
57 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
|
54 | 58 |
import com.iver.cit.gvsig.fmap.DriverException; |
55 | 59 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
56 | 60 |
import com.iver.cit.gvsig.fmap.drivers.DefaultDBDriver; |
... | ... | |
106 | 110 |
// System.out.println("getShape " + index); |
107 | 111 |
if (index < fetch_min) |
108 | 112 |
{ |
109 |
rs.close();
|
|
113 |
rs.beforeFirst();
|
|
110 | 114 |
|
111 |
rs = st.executeQuery(sqlOrig); |
|
115 |
// rs = st.executeQuery(sqlOrig);
|
|
112 | 116 |
fetch_min = 0; |
113 | 117 |
fetch_max = rs.getFetchSize(); |
114 | 118 |
} |
... | ... | |
147 | 151 |
this.whereClause = whereClause; |
148 | 152 |
this.sqlOrig = "SELECT " + fields + " FROM " + tableName + " " + whereClause; |
149 | 153 |
try { |
150 |
st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
|
154 |
st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
|
151 | 155 |
st.setFetchSize(5000); |
152 | 156 |
st.execute("declare wkb_cursor binary cursor for " + sqlOrig); |
153 | 157 |
rs = st.executeQuery("fetch forward all in wkb_cursor"); |
154 |
st.execute("BEGIN"); |
|
155 |
bCursorActivo = true; |
|
158 |
// st.execute("BEGIN");
|
|
159 |
// bCursorActivo = true;
|
|
156 | 160 |
// rs = st.executeQuery(sqlOrig); |
157 | 161 |
fetch_min = 0; |
158 | 162 |
fetch_max = rs.getFetchSize(); |
... | ... | |
200 | 204 |
st = conn.createStatement(); |
201 | 205 |
st.setFetchSize(2000); |
202 | 206 |
if (bCursorActivo) |
203 |
close(); |
|
204 |
st.execute("declare wkb_cursor binary cursor for " + sql); |
|
205 |
ResultSet rs = st.executeQuery("fetch forward all in wkb_cursor"); |
|
207 |
{ |
|
208 |
st.execute("CLOSE wkb_cursor_prov"); |
|
209 |
bCursorActivo = false; |
|
210 |
} |
|
211 |
|
|
212 |
st.execute("declare wkb_cursor_prov binary cursor for " + sql); |
|
213 |
ResultSet rs = st.executeQuery("fetch forward all in wkb_cursor_prov"); |
|
206 | 214 |
// st.execute("BEGIN"); |
207 | 215 |
bCursorActivo = true; |
208 | 216 |
// ResultSet rs = st.executeQuery(sql); |
... | ... | |
235 | 243 |
|
236 | 244 |
return getFeatureIterator(sqlAux); |
237 | 245 |
} |
246 |
/* (non-Javadoc) |
|
247 |
* @see com.iver.cit.gvsig.fmap.drivers.DefaultDBDriver#getFieldValue(long, int) |
|
248 |
*/ |
|
249 |
public Value getFieldValue(long rowIndex, int idField) throws com.hardcode.gdbms.engine.data.driver.DriverException { |
|
250 |
boolean resul; |
|
251 |
// EL ABSOLUTE NO HACE QUE SE VUELVAN A LEER LAS |
|
252 |
// FILAS, ASI QUE MONTAMOS ESTA HISTORIA PARA QUE |
|
253 |
// LO HAGA |
|
254 |
// System.out.println("getShape " + index); |
|
255 |
int index = (int) (rowIndex + 1); |
|
256 |
try |
|
257 |
{ |
|
258 |
if (index < fetch_min) |
|
259 |
{ |
|
260 |
rs.close(); |
|
261 |
|
|
262 |
rs = st.executeQuery(sqlOrig); |
|
263 |
fetch_min = 0; |
|
264 |
fetch_max = rs.getFetchSize(); |
|
265 |
} |
|
266 |
while (index >= fetch_max) |
|
267 |
{ |
|
268 |
rs.last(); |
|
269 |
// forzamos una carga |
|
270 |
rs.next(); |
|
271 |
fetch_min = fetch_max; |
|
272 |
fetch_max = fetch_max + rs.getFetchSize(); |
|
273 |
// System.out.println("fetchSize = " + rs.getFetchSize() + " " + fetch_min + "-" + fetch_max); |
|
274 |
} |
|
275 |
rs.absolute(index+1 - fetch_min); |
|
276 |
int fieldId = idField+2; |
|
277 |
ByteBuffer buf = ByteBuffer.wrap(rs.getBytes(fieldId)); |
|
278 |
if (metaData.getColumnType(fieldId) == Types.VARCHAR) |
|
279 |
return ValueFactory.createValue(rs.getString(fieldId)); |
|
280 |
if (metaData.getColumnType(fieldId) == Types.FLOAT) |
|
281 |
return ValueFactory.createValue(buf.getFloat()); |
|
282 |
if (metaData.getColumnType(fieldId) == Types.DOUBLE) |
|
283 |
return ValueFactory.createValue(buf.getDouble()); |
|
284 |
if (metaData.getColumnType(fieldId) == Types.INTEGER) |
|
285 |
return ValueFactory.createValue(buf.getInt()); |
|
286 |
if (metaData.getColumnType(fieldId) == Types.BIGINT) |
|
287 |
return ValueFactory.createValue(buf.getLong()); |
|
288 |
if (metaData.getColumnType(fieldId) == Types.BIT) |
|
289 |
// TODO |
|
290 |
return ValueFactory.createValue(rs.getBoolean(fieldId)); |
|
291 |
if (metaData.getColumnType(fieldId) == Types.DATE) |
|
292 |
// TODO |
|
293 |
return ValueFactory.createValue(rs.getDate(fieldId)); |
|
294 |
} |
|
295 |
catch(SQLException e) |
|
296 |
{ |
|
297 |
throw new com.hardcode.gdbms.engine.data.driver.DriverException(e.getMessage()); |
|
298 |
} |
|
299 |
return ValueFactory.createNullValue(); |
|
300 |
|
|
301 |
} |
|
302 |
public void open() throws com.iver.cit.gvsig.fmap.DriverException { |
|
303 |
/* try { |
|
304 |
st = conn.createStatement(); |
|
305 |
st.setFetchSize(2000); |
|
306 |
if (bCursorActivo) |
|
307 |
close(); |
|
308 |
st.execute("declare wkb_cursor binary cursor for " + sqlOrig); |
|
309 |
rs = st.executeQuery("fetch forward all in wkb_cursor"); |
|
310 |
// st.execute("BEGIN"); |
|
311 |
bCursorActivo = true; |
|
312 |
} catch (SQLException e) { |
|
313 |
e.printStackTrace(); |
|
314 |
throw new com.iver.cit.gvsig.fmap.DriverException(e); |
|
315 |
} */ |
|
316 |
|
|
317 |
} |
|
238 | 318 |
|
239 | 319 |
|
240 | 320 |
} |
Also available in: Unified diff