Skip to content

Commit

Permalink
[GEOT-724] backport for 15.x
Browse files Browse the repository at this point in the history
fixes Oracle DataStore is unable to add empty geometries

Applies patches provided in geotools#1228 to 15.x branch
  • Loading branch information
mprins committed Sep 16, 2016
1 parent 0ffc6ad commit 5b1a386
Show file tree
Hide file tree
Showing 6 changed files with 3,906 additions and 3,841 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ public void setGeometryValue(Geometry g, int dimension, int srid, Class binding,

// Handle the null geometry case.
// Surprisingly, using setNull(column, Types.OTHER) does not work...
if (g == null) {
if (g == null||g.isEmpty()) {
ps.setNull(column, Types.STRUCT, "MDSYS.SDO_GEOMETRY");
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,105 +1,105 @@
/*
* GeoTools - The Open Source Java GIS Toolkit
* http://geotools.org
*
* (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
package org.geotools.data.oracle;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

import org.geotools.jdbc.JDBCDataStore;

import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;

/**
* This dialect uses the Oracle 11 specific sdoapi.jar API, which is touted to
* be faster than then standard JGeometry one. Benchmarking shows that it's no
* match for the standard GeometryConverter thought, and only adds a nasty
* dependency that cannot be redistributed, so it lays here inactive only
* for historical purposes. Uncomment here and in OracleDialect if you
* want to try it out.
* @author Andrea Aime
*/
class SDO11OracleDialect extends OracleDialect {

protected SDO11OracleDialect(JDBCDataStore dataStore) {
super(dataStore);
}

@Override
Geometry readGeometry(ResultSet rs, String column, GeometryFactory factory, Connection cx)
throws IOException, SQLException {
return readGeometry(rs.getBytes(column), factory, cx);
}

@Override
Geometry readGeometry(ResultSet rs, int column, GeometryFactory factory, Connection cx)
throws IOException, SQLException {
return readGeometry(rs.getBytes(column), factory, cx);
}

private Geometry readGeometry(byte[] rawGeometry, GeometryFactory factory, Connection cx) throws SQLException {
if(rawGeometry == null)
return null;

throw new UnsupportedOperationException("Due to licensing issues the code depending to " +
"JGeometry has been commented out");
// JGeometry geom = null;
// try {
// geom = JGeometry.load(rawGeometry);
// } catch(Exception e) {
// throw (SQLException) new SQLException("Could not parse the geometry struct").initCause(e);
// }
// return JGeometryConverter.toJTS(factory, geom);
}

@Override
public void setGeometryValue(Geometry g, int dimension, int srid, Class binding, PreparedStatement ps,
int column) throws SQLException {
// Handle the null geometry case.
// Surprisingly, using setNull(column, Types.OTHER) does not work...
if (g == null) {
ps.setNull(column, Types.STRUCT, "MDSYS.SDO_GEOMETRY");
return;
}

throw new UnsupportedOperationException("Due to licensing issues the code depending to " +
"JGeometry has been commented out");


// JGeometry geom = JGeometryConverter.toJGeometry(g, srid);
// try {
// OracleConnection ocx = unwrapConnection(ps.getConnection());
// // not to be mistaken for store(geom, connection), this is the faster 11G version
// // (no kidding, they created a new method by inverting the types in the signature... man!!!!)
// STRUCT obj = JGeometry.store(ocx, geom);
// ps.setObject(column, obj);
// } catch(Exception e) {
// throw (SQLException) new SQLException("Could not turn the JGeometry " +
// "into a raw byte[]").initCause(e);
// }
//
// if (LOGGER.isLoggable(Level.FINE)) {
// String sdo = SDOSqlDumper.toSDOGeom(g, srid);
// LOGGER.fine("Setting paramtetr " + column + " as " + sdo);
// }
}

}
/*
* GeoTools - The Open Source Java GIS Toolkit
* http://geotools.org
*
* (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
package org.geotools.data.oracle;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

import org.geotools.jdbc.JDBCDataStore;

import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;

/**
* This dialect uses the Oracle 11 specific sdoapi.jar API, which is touted to
* be faster than then standard JGeometry one. Benchmarking shows that it's no
* match for the standard GeometryConverter thought, and only adds a nasty
* dependency that cannot be redistributed, so it lays here inactive only
* for historical purposes. Uncomment here and in OracleDialect if you
* want to try it out.
* @author Andrea Aime
*/
class SDO11OracleDialect extends OracleDialect {

protected SDO11OracleDialect(JDBCDataStore dataStore) {
super(dataStore);
}

@Override
Geometry readGeometry(ResultSet rs, String column, GeometryFactory factory, Connection cx)
throws IOException, SQLException {
return readGeometry(rs.getBytes(column), factory, cx);
}

@Override
Geometry readGeometry(ResultSet rs, int column, GeometryFactory factory, Connection cx)
throws IOException, SQLException {
return readGeometry(rs.getBytes(column), factory, cx);
}

private Geometry readGeometry(byte[] rawGeometry, GeometryFactory factory, Connection cx) throws SQLException {
if(rawGeometry == null)
return null;

throw new UnsupportedOperationException("Due to licensing issues the code depending to " +
"JGeometry has been commented out");
// JGeometry geom = null;
// try {
// geom = JGeometry.load(rawGeometry);
// } catch(Exception e) {
// throw (SQLException) new SQLException("Could not parse the geometry struct").initCause(e);
// }
// return JGeometryConverter.toJTS(factory, geom);
}

@Override
public void setGeometryValue(Geometry g, int dimension, int srid, Class binding, PreparedStatement ps,
int column) throws SQLException {
// Handle the null geometry case.
// Surprisingly, using setNull(column, Types.OTHER) does not work...
if (g == null || g.isEmpty()) {
ps.setNull(column, Types.STRUCT, "MDSYS.SDO_GEOMETRY");
return;
}

throw new UnsupportedOperationException("Due to licensing issues the code depending to " +
"JGeometry has been commented out");


// JGeometry geom = JGeometryConverter.toJGeometry(g, srid);
// try {
// OracleConnection ocx = unwrapConnection(ps.getConnection());
// // not to be mistaken for store(geom, connection), this is the faster 11G version
// // (no kidding, they created a new method by inverting the types in the signature... man!!!!)
// STRUCT obj = JGeometry.store(ocx, geom);
// ps.setObject(column, obj);
// } catch(Exception e) {
// throw (SQLException) new SQLException("Could not turn the JGeometry " +
// "into a raw byte[]").initCause(e);
// }
//
// if (LOGGER.isLoggable(Level.FINE)) {
// String sdo = SDOSqlDumper.toSDOGeom(g, srid);
// LOGGER.fine("Setting paramtetr " + column + " as " + sdo);
// }
}

}

0 comments on commit 5b1a386

Please sign in to comment.