Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an extension to the oracle dialect that works analog to the FeatureInspector #1288

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/*----------------------------------------------------------------------------
This file is part of deegree, http://deegree.org/
Copyright (C) 2001-2014 by:
Copyright (C) 2001-2022 by:
- Department of Geography, University of Bonn -
and
- lat/lon GmbH -
and
- grit graphische Informationstechnik Beratungsgesellschaft mbH -

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
Expand All @@ -30,6 +32,11 @@
Germany
http://www.geographie.uni-bonn.de/deegree/

grit graphische Informationstechnik Beratungsgesellschaft mbH
Landwehrstr. 143, 59368 Werne
Germany
http://www.grit.de/

e-mail: info@deegree.org
----------------------------------------------------------------------------*/
package org.deegree.sqldialect.oracle;
Expand All @@ -40,17 +47,18 @@
import java.sql.SQLException;
import java.sql.Types;

import oracle.jdbc.OracleConnection;
import oracle.sql.STRUCT;

import org.deegree.cs.coordinatesystems.ICRS;
import org.deegree.geometry.Geometry;
import org.deegree.geometry.GeometryTransformer;
import org.deegree.geometry.utils.GeometryParticleConverter;
import org.deegree.sqldialect.oracle.sdo.SDOGeometryConverter;
import org.deegree.sqldialect.oracle.sdo.SDOInspector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import oracle.jdbc.OracleConnection;
import oracle.sql.STRUCT;

/**
* {@link GeometryParticleConverter} for Oracle Spatial.
*
Expand All @@ -71,6 +79,8 @@ public class OracleGeometryConverter implements GeometryParticleConverter {

private int isrid;

private SDOInspector sdoInspector;

/**
* Creates a new {@link OracleGeometryConverter} instance.
*
Expand Down Expand Up @@ -115,7 +125,7 @@ public Geometry toParticle( ResultSet rs, int colIndex )
return null;
}
try {
return new SDOGeometryConverter().toGeometry( (STRUCT) sqlValue, crs );
return new SDOGeometryConverter( sdoInspector ).toGeometry( (STRUCT) sqlValue, crs );
} catch ( Throwable t ) {
throw new IllegalArgumentException(t);
}
Expand All @@ -137,7 +147,7 @@ public void setParticle( PreparedStatement stmt, Geometry particle, int paramInd
// compatible = compatible.getConvexHull();
// }
OracleConnection ocon = getOracleConnection( stmt.getConnection() );
Object struct = new SDOGeometryConverter().fromGeometry( ocon, isrid, compatible, true );
Object struct = new SDOGeometryConverter(sdoInspector).fromGeometry( ocon, isrid, compatible, true );
stmt.setObject( paramIndex, struct );
}
} catch ( Throwable t ) {
Expand Down Expand Up @@ -188,4 +198,8 @@ public String getSrid() {
public ICRS getCrs() {
return crs;
}

public void setSdoInsepctor( SDOInspector sdoInspector ) {
this.sdoInspector = sdoInspector;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ protected static double[] fromDoubleArray( STRUCT struct, final double defaultVa
return fromDoubleArray( struct.getOracleAttributes(), defaultValue );
}

protected static STRUCT toSDOGeometry( GeomHolder h, OracleConnection conn )
protected static STRUCT toSDOGeometry( SDOGeometry h, OracleConnection conn )
throws SQLException {
return toSDOGeometry( h.gtype, h.srid, h.elem_info, h.ordinates, conn);
}

/**
* Convert SDO_Geometry informations into Oracle JDBC STRUCT element
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*----------------------------------------------------------------------------
This file is part of deegree, http://deegree.org/
Copyright (C) 2022 by:
- grit graphische Informationstechnik Beratungsgesellschaft mbH -

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; either version 2.1 of the License, or (at your option)
any later version.
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.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Contact information:

grit graphische Informationstechnik Beratungsgesellschaft mbH
Landwehrstr. 143, 59368 Werne
Germany
http://www.grit.de/

lat/lon GmbH
Aennchenstr. 19, 53177 Bonn
Germany
http://lat-lon.de/

Department of Geography, University of Bonn
Prof. Dr. Klaus Greve
Postfach 1147, 53001 Bonn
Germany
http://www.geographie.uni-bonn.de/deegree/

e-mail: info@deegree.org
----------------------------------------------------------------------------*/
package org.deegree.sqldialect.oracle.sdo;

/**
* Holder for a native representation of Oracle Geometries in plain Java types
*
* @author <a href="mailto:reichhelm@grit.de">Stephan Reichhelm</a>
*/
public class SDOGeometry {
public int gtype;

public int srid;

public double point[];

public int[] elem_info;

public double[] ordinates;

public SDOGeometry( int gtype, int srid, double point[], int[] elem_info, double[] ordinates ) {
this.gtype = gtype;
this.srid = srid;
this.point = point;
this.elem_info = elem_info;
this.ordinates = ordinates;
}

public SDOGeometry() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,15 @@
public class SDOGeometryConverter {
static final Logger LOG = LoggerFactory.getLogger( SDOGeometryConverter.class );

private final SDOInspector inspector;

public SDOGeometryConverter() {
this.inspector = null;
}

public SDOGeometryConverter(SDOInspector inspector)
{
this.inspector = inspector;
}

private GeometryFactory _gf = new GeometryFactory();
Expand Down Expand Up @@ -133,6 +140,10 @@ protected static class GeomHolder {

public GeomHolderTyp last;

public GeomHolder( SDOGeometry sdo, ICRS crs ) {
this( sdo.gtype, sdo.srid, sdo.point, sdo.elem_info, sdo.ordinates, crs );
}

public GeomHolder( final int gtype, final int srid, final double point[], final int[] elem_info,
final double[] ordinates, ICRS crs ) {
this.gtype = gtype;
Expand Down Expand Up @@ -271,61 +282,70 @@ public Geometry toGeometry( STRUCT sdoStruct, ICRS crs )
if ( sdoStruct == null ) {
return null;
}

Datum data[] = sdoStruct.getOracleAttributes();
SDOGeometry sdo = new SDOGeometry();

sdo.gtype = OracleObjectTools.fromInteger( data[0], 0 );
sdo.srid = OracleObjectTools.fromInteger( data[1], -1 );
sdo.point = OracleObjectTools.fromDoubleArray( (STRUCT) data[2], Double.NaN );
sdo.elem_info = OracleObjectTools.fromIntegerArray( (ARRAY) data[3] );
sdo.ordinates = OracleObjectTools.fromDoubleArray( (ARRAY) data[4], Double.NaN );

removeLinearReferencingSystem(sdo);

if ( inspector != null ) {
inspector.toGeometry(sdo);
}

int gtype = OracleObjectTools.fromInteger( data[0], 0 );
int srid = OracleObjectTools.fromInteger( data[1], -1 );
double[] point = OracleObjectTools.fromDoubleArray( (STRUCT) data[2], Double.NaN );
int[] elemInfo = OracleObjectTools.fromIntegerArray( (ARRAY) data[3] );
double[] ordinates = OracleObjectTools.fromDoubleArray( (ARRAY) data[4], Double.NaN );
return toGeometry( sdo, crs );
}

int gtype_d, tdims = gtype / 1000;
protected void removeLinearReferencingSystem( SDOGeometry sdo ) {
int gtype_d, tdims = sdo.gtype / 1000;
if ( tdims < 2 || tdims > 4 ) {
gtype_d = 2;
} else {
gtype_d = tdims;
}

int gtype_l = ( gtype % 1000 ) / 100;
int gtype_l = ( sdo.gtype % 1000 ) / 100;
if ( gtype_l > 0 ) { // contains LRS?
// create ordinates array without LRS dimension
double[] newOrdinates = new double[( ordinates.length / gtype_d ) * ( gtype_d - 1 )];
double[] newOrdinates = new double[( sdo.ordinates.length / gtype_d ) * ( gtype_d - 1 )];

int j = 0;
for ( int i = 0; i < ordinates.length; i++ ) {
for ( int i = 0; i < sdo.ordinates.length; i++ ) {
if ( i % gtype_d != ( gtype_l - 1 ) ) { // ordinate not in LRS dimension?
newOrdinates[j++] = ordinates[i];
newOrdinates[j++] = sdo.ordinates[i];
}
}

ordinates = newOrdinates;
sdo.ordinates = newOrdinates;

// create elemInfo array without LRS dimension
int[] newElemInfo = new int[elemInfo.length];
int[] newElemInfo = new int[sdo.elem_info.length];
for ( int i = 0; i < newElemInfo.length; i++ ) {
if ( i % 3 == 0 ) {
// compute new offset in ordinates array
newElemInfo[i] = ( ( elemInfo[i] - 1 ) / gtype_d ) * ( gtype_d - 1 ) + 1;
newElemInfo[i] = ( ( sdo.elem_info[i] - 1 ) / gtype_d ) * ( gtype_d - 1 ) + 1;
} else {
newElemInfo[i] = elemInfo[i];
newElemInfo[i] = sdo.elem_info[i];
}
}

elemInfo = newElemInfo;
sdo.elem_info = newElemInfo;

// compute new gtype
gtype = gtype - 1000 - gtype_l * 100;
sdo.gtype = sdo.gtype - 1000 - gtype_l * 100;
}

GeomHolder sdo = new GeomHolder( gtype, srid, point, elemInfo, ordinates, crs );

return toGeometry( sdo, crs );
}

@SuppressWarnings("unchecked")
protected Geometry toGeometry( GeomHolder sdo, ICRS crs )
protected Geometry toGeometry( SDOGeometry geom, ICRS crs )
throws SQLException {
GeomHolder sdo = new GeomHolder( geom, crs );

if ( sdo.cnt_o < sdo.gtype_d || sdo.cnt_e < 3 || sdo.cnt_o % sdo.gtype_d > 0 || sdo.cnt_e % 3 > 0 )
throw new SQLException( "Illegal Geometry" );
else if ( sdo.gtype_tt == SDOGTypeTT.UNKNOWN )
Expand Down Expand Up @@ -730,7 +750,7 @@ public Object fromGeometry( OracleConnection conn, int srid, Geometry geometry )
}

@SuppressWarnings("unchecked")
protected GeomHolder fromGeometry( int srid, Geometry geometry, boolean allowJTSfallback ) {
protected SDOGeometry fromGeometry( int srid, Geometry geometry, boolean allowJTSfallback ) {
List<Triplet> info = new LinkedList<Triplet>();
List<Point> pnts = new LinkedList<Point>();
int gtypett = SDOGTypeTT.UNKNOWN;
Expand Down Expand Up @@ -781,21 +801,22 @@ protected GeomHolder fromGeometry( int srid, Geometry geometry, boolean allowJTS
int gtyp = ( 1000 * dim ) + gtypett;
LOG.trace( "fromGeometry: MDSYS.SDO_GEOMETRY( {}, {}, NULL, MDSYS.SDO_ELEM_INFO_ARRAY{}, MDSYS.SDO_ORDINATE_ARRAY{} )",
gtyp, srid, elemInfo, ordinates );

return new GeomHolder( gtyp, srid, null, elemInfo, ordinates, null );
return new SDOGeometry( gtyp, srid, null, elemInfo, ordinates );
}

// no parse able geometry found
return null;
}


public Object fromGeometry( OracleConnection conn, int srid, Geometry geometry, boolean allowJTSfallback )
throws SQLException {

GeomHolder holder = fromGeometry( srid, geometry, allowJTSfallback );
if ( holder != null ) {
return OracleObjectTools.toSDOGeometry( holder, conn );
SDOGeometry geom = fromGeometry( srid, geometry, allowJTSfallback );
if ( inspector != null ) {
inspector.fromGeometry(geom);
}
if ( geom != null ) {
return OracleObjectTools.toSDOGeometry( geom, conn );
} else {
// create error message
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*----------------------------------------------------------------------------
This file is part of deegree, http://deegree.org/
Copyright (C) 2022 by:
- grit graphische Informationstechnik Beratungsgesellschaft mbH -

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; either version 2.1 of the License, or (at your option)
any later version.
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.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Contact information:

grit graphische Informationstechnik Beratungsgesellschaft mbH
Landwehrstr. 143, 59368 Werne
Germany
http://www.grit.de/

lat/lon GmbH
Aennchenstr. 19, 53177 Bonn
Germany
http://lat-lon.de/

Department of Geography, University of Bonn
Prof. Dr. Klaus Greve
Postfach 1147, 53001 Bonn
Germany
http://www.geographie.uni-bonn.de/deegree/

e-mail: info@deegree.org
----------------------------------------------------------------------------*/
package org.deegree.sqldialect.oracle.sdo;

/**
* Inspector interface to allow inspection of Geometries
*
* @author <a href="mailto:reichhelm@grit.de">Stephan Reichhelm</a>
*/
public interface SDOInspector {

/**
* Inspect SDO before conversion to oracle object
*
* @param holder
*/
default void fromGeometry( SDOGeometry geom ) {
// do nothing by default
}

/**
* Inspect SDO before conversion to geometry object
*
* @param holder
*/
default void toGeometry( SDOGeometry geom ) {
// do nothing by default
}
}
Loading