|
From: Logs S. c. messages. <gvs...@li...> - 2013-11-23 15:29:01
|
Revision: 1067
http://sourceforge.net/p/gvsigce/code/1067
Author: vicgonco
Date: 2013-11-23 15:28:58 +0000 (Sat, 23 Nov 2013)
Log Message:
-----------
Applying https://devel.gvsig.org/redmine/projects/gvsig-desktop/repository/revisions/38035 and https://devel.gvsig.org/redmine/projects/gvsig-desktop/repository/revisions/38057
Modified Paths:
--------------
trunk/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGisDriver.java
trunk/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGisFeatureIterator.java
Modified: trunk/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGisDriver.java
===================================================================
--- trunk/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGisDriver.java 2013-11-23 15:27:37 UTC (rev 1066)
+++ trunk/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGisDriver.java 2013-11-23 15:28:58 UTC (rev 1067)
@@ -1,7 +1,7 @@
/*
* Created on 04-mar-2005
*
- * gvSIG. Sistema de Informaci\xF3n Geogr\xE1fica de la Generalitat Valenciana
+ * gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
*
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
*
@@ -23,7 +23,7 @@
*
* Generalitat Valenciana
* Conselleria d'Infraestructures i Transport
- * Av. Blasco Ib\xE1\xF1ez, 50
+ * Av. Blasco Ib��ez, 50
* 46010 VALENCIA
* SPAIN
*
@@ -61,6 +61,7 @@
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
+import java.util.Random;
import org.apache.log4j.Logger;
import org.joda.time.DateTime;
@@ -140,10 +141,6 @@
private String completeWhere;
- private String provCursorName = null;
-
- int numProvCursors = 0;
-
boolean bShapeTypeRevised = false;
private int actual_position;
@@ -203,7 +200,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see
* com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
*/
@@ -213,7 +210,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see com.hardcode.driverManager.Driver#getName()
*/
public String getName() {
@@ -233,8 +230,9 @@
// geom = parser.read(strAux);
if (rs != null) {
byte[] data = rs.getBytes(1);
- if (data == null) // null geometry.
- return null;
+ if (data == null) {
+ return null;
+ }
geom = parser.parse(data);
}
} catch (SQLException e) {
@@ -246,7 +244,7 @@
/**
* First, the geometry field. After, the rest of fields
- *
+ *
* @return
*/
/*
@@ -257,16 +255,16 @@
*/
/**
- * Antes de llamar a esta funci\xF3n hay que haber fijado el workingArea si se
+ * Antes de llamar a esta funci�n hay que haber fijado el workingArea si se
* quiere usar.
- *
+ *
* @param conn
* @throws DBException
*/
public void setData(IConnection conn, DBLayerDefinition lyrDef)
throws DBException {
this.conn = conn;
- // TODO: Deber\xEDamos poder quitar Conneciton de la llamada y meterlo
+ // TODO: Deber�amos poder quitar Conneciton de la llamada y meterlo
// en lyrDef desde el principio.
lyrDef.setConnection(conn);
@@ -315,13 +313,13 @@
writer.initialize(lyrDef);
} catch (SQLException e) {
-
+
try {
((ConnectionJDBC) conn).getConnection().rollback();
} catch (SQLException e1) {
logger.warn("Unable to rollback connection after problem (" + e.getMessage() + ") in setData()");
}
-
+
try {
if (rs != null) { rs.close(); }
} catch (SQLException e1) {
@@ -380,7 +378,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see
* com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver#getGeometryIterator
* (java.lang.String)
@@ -398,47 +396,31 @@
throws ReadDriverException {
PostGisFeatureIterator geomIterator = null;
try {
- // st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
- // ResultSet.CONCUR_READ_ONLY);
-
- // st = conn.createStatement
- if (provCursorName != null) {
- /*
- * st.execute("BEGIN"); st.execute("CLOSE " + provCursorName);
- * bCursorActivo = false; st.execute("COMMIT");
- */
- numProvCursors++;
+ String provCursorName = "wkb_cursor_prov_"
+ + Long.toString(Math.abs(new Random().nextLong()))
+ + getTableName();
+ // jlopez: if the cursor is longer than 64 chars, we strip it to
+ // that length. We should use a different name convention which
+ // avoids this kind of problems.
+ if (provCursorName.length() > 64) {
+ provCursorName = provCursorName.substring(0, 63);
}
- // st.execute("BEGIN");
- provCursorName = getTableName() + myCursorId + "wkb_cursor_prov_"
- + System.currentTimeMillis() + "" + numProvCursors;
- // st.execute("BEGIN");
bCursorActivo = true;
- // ResultSet rs = st.executeQuery(sql);
geomIterator = new PostGisFeatureIterator(
((ConnectionJDBC) conn).getConnection(), provCursorName,
sql);
} catch (SQLException e) {
- // e.printStackTrace();
- // e.printStackTrace();
- // SqlDriveExceptionType type = new SqlDriveExceptionType();
- // type.setDriverName("PostGIS Driver");
- // type.setSql(sql);
- // type.setLayerName(getTableName());
- // type.setSchema(null);
throw new ReadDriverException("PostGIS Driver", e);
- // throw new DriverException(e);
- // return null;
}
-
return geomIterator;
}
public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG)
throws ReadDriverException {
- if (workingArea != null)
- r = r.createIntersection(workingArea);
+ if (workingArea != null) {
+ r = r.createIntersection(workingArea);
+ }
String sqlAux;
if (canReproject(strEPSG)) {
@@ -453,17 +435,18 @@
}
/**
- * Le pasas el rect\xE1ngulo que quieres pedir. La primera vez es el
+ * Le pasas el rect�ngulo que quieres pedir. La primera vez es el
* workingArea, y las siguientes una interseccion de este rectangulo con el
* workingArea
- *
+ *
* @param r
* @param strEPSG
* @return
*/
private String getCompoundWhere(String sql, Rectangle2D r, String strEPSG) {
- if (r == null)
- return getWhereClause();
+ if (r == null) {
+ return getWhereClause();
+ }
double xMin = r.getMinX();
double yMin = r.getMinY();
@@ -473,11 +456,12 @@
+ ", " + xMax + " " + yMin + ", " + xMax + " " + yMax + ", "
+ xMin + " " + yMax + ")', " + strEPSG + ")";
String sqlAux;
- if (getWhereClause().toUpperCase().indexOf("WHERE") != -1)
+ if (getWhereClause().toUpperCase().indexOf("WHERE") != -1) {
sqlAux = getWhereClause() + " AND \"" + getLyrDef().getFieldGeometry() + "\" && " + wktBox;
- else
+ } else {
sqlAux = "WHERE \"" + getLyrDef().getFieldGeometry() + "\" && "
+ wktBox;
+ }
return sqlAux;
}
@@ -490,7 +474,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see com.iver.cit.gvsig.fmap.drivers.DefaultDBDriver#getFieldValue(long,
* int)
*/
@@ -515,12 +499,13 @@
static Value getFieldValue(ResultSet aRs, int fieldId) throws SQLException {
ResultSetMetaData metaData = aRs.getMetaData();
byte[] byteBuf = aRs.getBytes(fieldId);
- if (byteBuf == null)
- return ValueFactory.createNullValue();
- else {
+ if (byteBuf == null) {
+ return ValueFactory.createNullValue();
+ } else {
ByteBuffer buf = ByteBuffer.wrap(byteBuf);
- if (metaData.getColumnType(fieldId) == Types.VARCHAR)
- return ValueFactory.createValue(aRs.getString(fieldId));
+ if (metaData.getColumnType(fieldId) == Types.VARCHAR) {
+ return ValueFactory.createValue(aRs.getString(fieldId));
+ }
if (metaData.getColumnType(fieldId) == Types.CHAR){
String character = aRs.getString(fieldId);
if (character != null){
@@ -529,22 +514,30 @@
return ValueFactory.createValue(character);
}
}
- if (metaData.getColumnType(fieldId) == Types.FLOAT)
- return ValueFactory.createValue(buf.getFloat());
- if (metaData.getColumnType(fieldId) == Types.DOUBLE)
- return ValueFactory.createValue(buf.getDouble());
- if (metaData.getColumnType(fieldId) == Types.REAL)
- return ValueFactory.createValue(buf.getFloat());
- if (metaData.getColumnType(fieldId) == Types.INTEGER)
- return ValueFactory.createValue(buf.getInt());
- if (metaData.getColumnType(fieldId) == Types.SMALLINT)
- return ValueFactory.createValue(buf.getShort());
- if (metaData.getColumnType(fieldId) == Types.BIGINT)
- return ValueFactory.createValue(buf.getLong());
- if (metaData.getColumnType(fieldId) == Types.BIT)
- return ValueFactory.createValue((byteBuf[0] == 1));
- if (metaData.getColumnType(fieldId) == Types.BOOLEAN)
- return ValueFactory.createValue(aRs.getBoolean(fieldId));
+ if (metaData.getColumnType(fieldId) == Types.FLOAT) {
+ return ValueFactory.createValue(buf.getFloat());
+ }
+ if (metaData.getColumnType(fieldId) == Types.DOUBLE) {
+ return ValueFactory.createValue(buf.getDouble());
+ }
+ if (metaData.getColumnType(fieldId) == Types.REAL) {
+ return ValueFactory.createValue(buf.getFloat());
+ }
+ if (metaData.getColumnType(fieldId) == Types.INTEGER) {
+ return ValueFactory.createValue(buf.getInt());
+ }
+ if (metaData.getColumnType(fieldId) == Types.SMALLINT) {
+ return ValueFactory.createValue(buf.getShort());
+ }
+ if (metaData.getColumnType(fieldId) == Types.BIGINT) {
+ return ValueFactory.createValue(buf.getLong());
+ }
+ if (metaData.getColumnType(fieldId) == Types.BIT) {
+ return ValueFactory.createValue((byteBuf[0] == 1));
+ }
+ if (metaData.getColumnType(fieldId) == Types.BOOLEAN) {
+ return ValueFactory.createValue(aRs.getBoolean(fieldId));
+ }
if (metaData.getColumnType(fieldId) == Types.DATE) {
long daysAfter2000 = buf.getInt();
DateTime year2000 = new DateTime(2000, 1,1,0,0,0);
@@ -721,7 +714,7 @@
}
private void setAbsolutePosition(int index) throws SQLException {
- // TODO: USAR LIMIT Y ORDER BY, Y HACERLO TAMBI\xC9N PARA
+ // TODO: USAR LIMIT Y ORDER BY, Y HACERLO TAMBI�N PARA
// MYSQL
if (rs == null) {
@@ -742,7 +735,7 @@
// fetchMax=" + fetch_max);
if ((index >= fetch_min) && (index <= fetch_max)) {
- // Est\xE1 en el intervalo, as\xED que lo podemos posicionar
+ // Est� en el intervalo, as� que lo podemos posicionar
//
//
@@ -813,20 +806,21 @@
/*
* (non-Javadoc)
- *
+ *
* @see com.iver.cit.gvsig.fmap.core.ICanReproject#getSourceProjection()
*/
public String getSourceProjection(IConnection conn, DBLayerDefinition dbld) {
- if (originalEPSG == null)
- getTableEPSG_and_shapeType(conn, dbld);
+ if (originalEPSG == null) {
+ getTableEPSG_and_shapeType(conn, dbld);
+ }
return originalEPSG;
}
/**
- * Las tablas con geometr\xEDas est\xE1n en la tabla GEOMETRY_COLUMNS y de ah\xED
- * sacamos en qu\xE9 proyecci\xF3n est\xE1n. El problema es que si el usuario hace
- * una vista de esa tabla, no estar\xE1 dada de alta aqu\xED y entonces gvSIG no
- * se entera en qu\xE9 proyecci\xF3n est\xE1 trabajando (y le ponemos un -1 como mal
+ * Las tablas con geometr�as est�n en la tabla GEOMETRY_COLUMNS y de ah�
+ * sacamos en qu� proyecci�n est�n. El problema es que si el usuario hace
+ * una vista de esa tabla, no estar� dada de alta aqu� y entonces gvSIG no
+ * se entera en qu� proyecci�n est� trabajando (y le ponemos un -1 como mal
* menor). El -1 implica que luego no podremos reproyectar al vuelo desde la
* base de datos. OJO: ES SENSIBLE A MAYUSCULAS / MINUSCULAS!!!
*/
@@ -858,22 +852,23 @@
originalEPSG = "" + rs.getInt("SRID");
String geometryType = rs.getString("TYPE");
int shapeType = FShape.MULTI;
- if (geometryType.compareToIgnoreCase("POINT") == 0)
- shapeType = FShape.POINT;
- else if (geometryType.compareToIgnoreCase("LINESTRING") == 0)
- shapeType = FShape.LINE;
- else if (geometryType.compareToIgnoreCase("POLYGON") == 0)
- shapeType = FShape.POLYGON;
- else if (geometryType.compareToIgnoreCase("MULTIPOINT") == 0)
- shapeType = FShape.MULTIPOINT;
- else if (geometryType.compareToIgnoreCase("MULTILINESTRING") == 0)
- shapeType = FShape.LINE;
- else if (geometryType.compareToIgnoreCase("MULTILINESTRINGM") == 0) // MCoord
- shapeType = FShape.LINE | FShape.M;
- else if (geometryType.compareToIgnoreCase("MULTIPOLYGON") == 0)
- shapeType = FShape.POLYGON;
+ if (geometryType.compareToIgnoreCase("POINT") == 0) {
+ shapeType = FShape.POINT;
+ } else if (geometryType.compareToIgnoreCase("LINESTRING") == 0) {
+ shapeType = FShape.LINE;
+ } else if (geometryType.compareToIgnoreCase("POLYGON") == 0) {
+ shapeType = FShape.POLYGON;
+ } else if (geometryType.compareToIgnoreCase("MULTIPOINT") == 0) {
+ shapeType = FShape.MULTIPOINT;
+ } else if (geometryType.compareToIgnoreCase("MULTILINESTRING") == 0) {
+ shapeType = FShape.LINE;
+ } else if (geometryType.compareToIgnoreCase("MULTILINESTRINGM") == 0) {
+ shapeType = FShape.LINE | FShape.M;
+ } else if (geometryType.compareToIgnoreCase("MULTIPOLYGON") == 0) {
+ shapeType = FShape.POLYGON;
+ }
dbld.setShapeType(shapeType);
-
+
//jomarlla
int dimension = rs.getInt("COORD_DIMENSION");
dbld.setDimension(dimension);
@@ -894,7 +889,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see com.iver.cit.gvsig.fmap.core.ICanReproject#getDestProjection()
*/
public String getDestProjection() {
@@ -903,7 +898,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see
* com.iver.cit.gvsig.fmap.core.ICanReproject#setDestProjection(java.lang
* .String)
@@ -914,7 +909,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see
* com.iver.cit.gvsig.fmap.core.ICanReproject#canReproject(java.lang.String)
*/
@@ -925,7 +920,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see com.iver.cit.gvsig.fmap.drivers.DefaultDBDriver#doRelateID_FID()
*/
protected void doRelateID_FID() throws DBException {
@@ -951,13 +946,13 @@
String gid;
while (r.next()) {
gid = r.getString(1);
-
+
if (gid == null) {
throw new SQLException(
PluginServices.getText(null, "Found_null_id_in_table") + ": " +
getLyrDef().getComposedTableName());
}
-
+
Value aux = ValueFactory.createValue(gid);
hashRelate.put(aux, new Integer(id));
// System.out.println("ASOCIANDO CLAVE " + aux + " CON VALOR " +
@@ -976,7 +971,7 @@
*/
/*
* int index = 0;
- *
+ *
* while (rs.next()) { Value aux = getFieldValue(index,
* idFID_FieldName-2); hashRelate.put(aux, new Integer(index));
* index++; System.out.println("Row " + index + " clave=" + aux); }
@@ -1005,7 +1000,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see com.iver.cit.gvsig.fmap.drivers.DefaultDBDriver#close()
*/
public void close() {
@@ -1022,7 +1017,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see
* com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver#getFeatureIterator
* (java.awt.geom.Rectangle2D, java.lang.String, java.lang.String[])
@@ -1036,11 +1031,12 @@
// new
// FieldDescription[alphaNumericFieldsNeeded.length+1];
try {
- if (workingArea != null)
- r = r.createIntersection(workingArea);
+ if (workingArea != null) {
+ r = r.createIntersection(workingArea);
+ }
// if (getLyrDef()==null){
// load();
- // throw new DriverException("Fallo de la conexi\xF3n");
+ // throw new DriverException("Fallo de la conexi�n");
// }
String strAux = getGeometryField(lyrDef.getFieldGeometry());
@@ -1110,32 +1106,32 @@
/*
* public void preProcess() throws EditionException { writer.preProcess(); }
- *
+ *
* public void process(IRowEdited row) throws EditionException {
* writer.process(row); }
- *
+ *
* public void postProcess() throws EditionException { writer.postProcess();
* }
- *
+ *
* public String getCapability(String capability) { return
* writer.getCapability(capability); }
- *
+ *
* public void setCapabilities(Properties capabilities) {
* writer.setCapabilities(capabilities); }
- *
+ *
* public boolean canWriteAttribute(int sqlType) { return
* writer.canWriteAttribute(sqlType); }
- *
+ *
* public boolean canWriteGeometry(int gvSIGgeometryType) { return
* writer.canWriteGeometry(gvSIGgeometryType); }
- *
+ *
* public void initialize(ITableDefinition layerDef) throws EditionException
* { writer.setCreateTable(false); writer.setWriteAll(false); // Obtenemos
* el DBLayerDefinition a partir del driver
- *
+ *
* DBLayerDefinition dbLyrDef = getLyrDef();
- *
- *
+ *
+ *
* writer.initialize(dbLyrDef); }
*/
public boolean isWritable() {
@@ -1252,12 +1248,12 @@
/**
* Gets all field names of a given table.
- *
+ *
* This method comes from DefaultJDBC.java class. Postgis driver has no method to check
- * the status of the connection -if it is valid or not. So, as it's not possible to assure
- * its status, close the connection when an exception happens and re-open it on demand
+ * the status of the connection -if it is valid or not. So, as it's not possible to assure
+ * its status, close the connection when an exception happens and re-open it on demand
* on the proper method will solve the problems related to an invalid status.
- *
+ *
* @param conn connection object
* @param table_name table name
* @return all field names of the given table
@@ -1294,12 +1290,12 @@
/**
* Gets all field type names of a given table.
- *
+ *
* This method comes from DefaultJDBC.java class. Postgis driver has no method to check
- * the status of the connection -if it is valid or not. So, as it's not possible to assure
- * its status, close the connection when an exception happens and re-open it on demand
+ * the status of the connection -if it is valid or not. So, as it's not possible to assure
+ * its status, close the connection when an exception happens and re-open it on demand
* on the proper method will solve the problems related to an invalid status.
- *
+ *
* @param conn connection object
* @param table_name table name
* @return all field type names of the given table
@@ -1416,7 +1412,7 @@
/**
* Tells if user can read contents of the table.
- *
+ *
* @param iconn connection with the database where the user is connected
* @param tablename to get the permissions over
* @return true if can read, either false
@@ -1456,19 +1452,21 @@
} else {
return false;
}
- } else return false;
+ } else {
+ return false;
+ }
}
-
+
private Integer getGidFieldIndex(String ret[]){
for (int i=0; i<ret.length; i++) {
if (ret[i].equalsIgnoreCase("gid")) {
return new Integer(i);
- }
+ }
}
return null;
}
-
+
private void swapIndexes(String[] ret, int i, int j){
if(i!=j && i>=0 && i<ret.length && j>=0 && j<ret.length){
String aux = ret[i];
@@ -1487,7 +1485,7 @@
for (int i = 0; i < ret.length; i++) {
if (pk.equals(ret[i])) {
//swap possible gid col with the first element
- //in order to make it the default selection on
+ //in order to make it the default selection on
//combobox
swapIndexes(ret, i, 0);
break;
@@ -1497,7 +1495,7 @@
Integer gidFieldIndex = getGidFieldIndex(ret);
if (gidFieldIndex!=null){
//swap possible gid col with the first element
- //in order to make it the default selection on
+ //in order to make it the default selection on
//combobox
int index = gidFieldIndex.intValue();
swapIndexes(ret, index, 0);
@@ -1505,7 +1503,7 @@
for (int i = 0; i < ret.length; i++) {
if (isAutoIncrement(conn, table_name, ret[i])) {
//swap possible gid col with the first element
- //in order to make it the default selection on
+ //in order to make it the default selection on
//combobox
swapIndexes(ret, i, 0);
break;
@@ -1517,12 +1515,12 @@
}
private boolean isAutoIncrement(IConnection con, String table_name, String colName) {
-
+
String query = "SELECT column_default SIMILAR TO 'nextval%regclass%' AS isautoincremental "
- + "FROM information_schema.columns "
- + "WHERE table_name = ? AND table_schema=? "
+ + "FROM information_schema.columns "
+ + "WHERE table_name = ? AND table_schema=? "
+ "AND column_name=?";
-
+
try {
// get schema and table from the composed tablename
String[] tokens = table_name.split("\\u002E", 2);
@@ -1534,23 +1532,23 @@
schema = tokens[0];
tableName = tokens[1];
}
-
-
+
+
Connection c = ((ConnectionJDBC)con).getConnection();
PreparedStatement st = c.prepareStatement(query);
st.setString(1, tableName);
st.setString(2, schema);
st.setString(3, colName);
-
+
ResultSet rs = st.executeQuery();
boolean isAutoincrement = false;
if (rs.next()) {
isAutoincrement = rs.getBoolean("isautoincremental");
}
-
+
rs.close();
st.close();
-
+
return isAutoincrement;
} catch (SQLException e) {
try {
@@ -1558,12 +1556,12 @@
} catch (DBException e2) {
// TODO Auto-generated catch block
e.printStackTrace();
- }
+ }
return false;
}
-
-
+
+
}
private String getPrimaryKey(IConnection con, String table_name) {
@@ -1582,24 +1580,24 @@
schema = tokens[0];
tableName = tokens[1];
}
-
-
+
+
Connection c = ((ConnectionJDBC)con).getConnection();
PreparedStatement st = c.prepareStatement(query);
st.setString(1, tableName);
st.setString(2, schema);
st.setString(3, tableName+"_pkey");
-
+
ResultSet rs = st.executeQuery();
-
+
String primaryKey = "";
if (rs.next()) {
primaryKey = rs.getString("column_name");
}
-
+
rs.close();
st.close();
-
+
return primaryKey;
} catch (SQLException e) {
try {
@@ -1607,14 +1605,14 @@
} catch (DBException e2) {
// TODO Auto-generated catch block
e.printStackTrace();
- }
+ }
return "";
}
}
-
+
public void validateData(IConnection _conn, DBLayerDefinition lyrDef) throws DBException {
-
+
this.conn = _conn;
lyrDef.setConnection(conn);
setLyrDef(lyrDef);
@@ -1646,7 +1644,7 @@
ResultSet.CONCUR_READ_ONLY);
// st.setFetchSize(FETCH_SIZE);
// myCursorId++;
- String temp_index_name = getTableName() + "_temp_wkb_cursor";
+ String temp_index_name = getTableName() + "_temp_wkb_cursor";
st.execute("declare " + temp_index_name + " binary scroll cursor with hold for "
+ sqlAux);
rs = st.executeQuery("fetch forward 50 in " + temp_index_name);
@@ -1655,13 +1653,13 @@
st.close();
} catch (SQLException e) {
-
+
try {
((ConnectionJDBC) conn).getConnection().rollback();
} catch (SQLException e1) {
logger.warn("Unable to rollback connection after problem (" + e.getMessage() + ") in setData()");
}
-
+
try {
if (rs != null) { rs.close(); }
} catch (SQLException e1) {
Modified: trunk/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGisFeatureIterator.java
===================================================================
--- trunk/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGisFeatureIterator.java 2013-11-23 15:27:37 UTC (rev 1066)
+++ trunk/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGisFeatureIterator.java 2013-11-23 15:28:58 UTC (rev 1067)
@@ -56,9 +56,7 @@
import com.iver.cit.gvsig.fmap.core.IGeometry;
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition;
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
-import com.iver.cit.gvsig.fmap.drivers.WKBParser2;
import com.iver.cit.gvsig.fmap.drivers.WKBParser3;
-import com.iver.cit.gvsig.fmap.drivers.XTypes;
/**
* @author FJP
@@ -99,6 +97,8 @@
String cursorName;
+ boolean closed = false;
+
/**
* @throws SQLException
* @throws SQLException
@@ -111,17 +111,18 @@
// de geometria
// Debe ser forward only
st = conn.createStatement();
-
+
// CodeSprint 2010 (Manuel L\xF3pez S\xE1nchez)
try{
- st.execute("BEGIN");
+ st.execute("BEGIN");
}catch(SQLException e){
st.execute("END"); // Cerramos la transacci\xF3n para anular los cursores binarios
- // que pueden quedar colgados (from CodeSprint 2010)
+ // que pueden quedar colgados (from CodeSprint 2010)
st.execute("BEGIN"); // Si salta otra excepci\xF3n, no la capturamos
}
// End CodeSprint 2010
- st.execute("declare " + cursorName + " binary cursor for " + sql);
+ st.execute("declare " + cursorName + " binary cursor with hold for "
+ + sql);
this.rs = st.executeQuery("fetch forward " + FETCH_SIZE + " in "
+ cursorName);
@@ -140,16 +141,17 @@
*/
public boolean hasNext() throws ReadDriverException {
try {
- if (numReg > 0)
- if ((numReg % FETCH_SIZE) == 0) {
- rs = st.executeQuery("fetch forward " + FETCH_SIZE + " in "
- + cursorName);
- // System.out.println("ejecutando la query otra vez");
- }
+ if (numReg > 0) {
+ if ((numReg % FETCH_SIZE) == 0) {
+ rs = st.executeQuery("fetch forward " + FETCH_SIZE + " in "
+ + cursorName);
+ // System.out.println("ejecutando la query otra vez");
+ }
+ }
// System.out.println("hasNext con numReg=" + numReg);
- if (rs.next())
- return true;
- else {
+ if (rs.next()) {
+ return true;
+ } else {
closeIterator();
return false;
}
@@ -217,29 +219,23 @@
*
* @see com.iver.cit.gvsig.fmap.drivers.IFeatureIterator#closeIterator()
*/
- public void closeIterator() throws ReadDriverException {
- try {
- numReg = 0;
+ public void closeIterator() throws ReadDriverException {
+ try {
+ if (!closed) {
+ numReg = 0;
+ st.execute("CLOSE " + cursorName);
+ st.execute("END");
+ rs.close();
+ st.close();
+ closed = true;
+ }
- // st.execute("CLOSE " + cursorName);
- // st.execute("COMMIT");
- rs.close();
- } catch (SQLException e) {
-// SqlDriveExceptionType type = new SqlDriveExceptionType();
-// type.setDriverName("PostGIS Driver");
-// try {
-// type.setSql(rs.getStatement().toString());
-// } catch (SQLException e1) {
-// e1.printStackTrace();
-// }
- throw new ReadDriverException("PostGIS Driver",e);
-// throw new DriverException(e);
- }
- // st.execute("COMMIT");
- // st.close();
-
+ } catch (SQLException e) {
+ throw new ReadDriverException("PostGIS Driver", e);
}
+ }
+
public void setLyrDef(DBLayerDefinition lyrDef) {
this.lyrDef = lyrDef;
// Aunque no nos hayan pedido todos los campos, devolveremos
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|