diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/hana/HANASpatialDialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/hana/HANASpatialDialect.java index 29adbc4e45..7b0cd66539 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/hana/HANASpatialDialect.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/hana/HANASpatialDialect.java @@ -6,6 +6,8 @@ */ package org.hibernate.spatial.dialect.hana; +import java.sql.Types; + import org.hibernate.boot.model.TypeContributions; import org.hibernate.dialect.HANAColumnStoreDialect; import org.hibernate.engine.config.spi.ConfigurationService; @@ -29,88 +31,226 @@ public class HANASpatialDialect extends HANAColumnStoreDialect implements Spatia registerColumnType( HANAGeometryTypeDescriptor.INSTANCE.getSqlType(), "ST_GEOMETRY" ); registerColumnType( HANAPointTypeDescriptor.INSTANCE.getSqlType(), "ST_POINT" ); + registerHibernateType( Types.OTHER, new GeolatteGeometryType( HANAGeometryTypeDescriptor.INSTANCE ).getName() ); + + /* + * Hibernate Spatial functions + */ registerFunction( SpatialFunction.asbinary.name(), - new HANASpatialFunction( "ST_AsBinary", StandardBasicTypes.MATERIALIZED_BLOB, false ) - ); + new HANASpatialFunction( "ST_AsBinary", StandardBasicTypes.MATERIALIZED_BLOB, false ) ); registerFunction( SpatialFunction.astext.name(), - new HANASpatialFunction( "ST_AsText", StandardBasicTypes.MATERIALIZED_CLOB, false ) - ); + new HANASpatialFunction( "ST_AsText", StandardBasicTypes.MATERIALIZED_CLOB, false ) ); registerFunction( SpatialFunction.boundary.name(), new HANASpatialFunction( "ST_Boundary", false ) ); registerFunction( SpatialFunction.buffer.name(), new HANASpatialFunction( "ST_Buffer", false ) ); registerFunction( SpatialFunction.contains.name(), - new HANASpatialFunction( "ST_Contains", StandardBasicTypes.NUMERIC_BOOLEAN, true ) - ); + new HANASpatialFunction( "ST_Contains", StandardBasicTypes.NUMERIC_BOOLEAN, true ) ); registerFunction( SpatialFunction.convexhull.name(), new HANASpatialFunction( "ST_ConvexHull", false ) ); registerFunction( SpatialFunction.crosses.name(), - new HANASpatialFunction( "ST_Crosses", StandardBasicTypes.NUMERIC_BOOLEAN, true ) - ); + new HANASpatialFunction( "ST_Crosses", StandardBasicTypes.NUMERIC_BOOLEAN, true ) ); registerFunction( SpatialFunction.difference.name(), new HANASpatialFunction( "ST_Difference", true ) ); registerFunction( SpatialFunction.dimension.name(), - new HANASpatialFunction( "ST_Dimension ", StandardBasicTypes.INTEGER, false ) - ); + new HANASpatialFunction( "ST_Dimension", StandardBasicTypes.INTEGER, false ) ); registerFunction( SpatialFunction.disjoint.name(), - new HANASpatialFunction( "ST_Disjoint", StandardBasicTypes.NUMERIC_BOOLEAN, true ) - ); + new HANASpatialFunction( "ST_Disjoint", StandardBasicTypes.NUMERIC_BOOLEAN, true ) ); registerFunction( SpatialFunction.distance.name(), - new HANASpatialFunction( "ST_Distance", StandardBasicTypes.DOUBLE, true ) - ); + new HANASpatialFunction( "ST_Distance", StandardBasicTypes.DOUBLE, true ) ); registerFunction( SpatialFunction.dwithin.name(), - new HANASpatialFunction( "ST_WithinDistance", StandardBasicTypes.NUMERIC_BOOLEAN, true ) - ); + new HANASpatialFunction( "ST_WithinDistance", StandardBasicTypes.NUMERIC_BOOLEAN, true ) ); registerFunction( SpatialFunction.envelope.name(), new HANASpatialFunction( "ST_Envelope", true ) ); registerFunction( SpatialFunction.equals.name(), - new HANASpatialFunction( "ST_Equals", StandardBasicTypes.NUMERIC_BOOLEAN, true ) - ); + new HANASpatialFunction( "ST_Equals", StandardBasicTypes.NUMERIC_BOOLEAN, true ) ); registerFunction( SpatialFunction.extent.name(), new HANASpatialAggregate( "ST_EnvelopeAggr" ) ); registerFunction( SpatialFunction.geometrytype.name(), - new HANASpatialFunction( "ST_GeometryType", StandardBasicTypes.STRING, false ) - ); + new HANASpatialFunction( "ST_GeometryType", StandardBasicTypes.STRING, false ) ); registerFunction( SpatialFunction.geomunion.name(), new HANASpatialFunction( "ST_Union", true ) ); registerFunction( SpatialFunction.intersection.name(), new HANASpatialFunction( "ST_Intersection", true ) ); registerFunction( SpatialFunction.intersects.name(), - new HANASpatialFunction( "ST_Intersects", StandardBasicTypes.NUMERIC_BOOLEAN, true ) - ); + new HANASpatialFunction( "ST_Intersects", StandardBasicTypes.NUMERIC_BOOLEAN, true ) ); registerFunction( SpatialFunction.isempty.name(), - new HANASpatialFunction( "ST_IsEmpty", StandardBasicTypes.NUMERIC_BOOLEAN, false ) - ); + new HANASpatialFunction( "ST_IsEmpty", StandardBasicTypes.NUMERIC_BOOLEAN, false ) ); registerFunction( SpatialFunction.issimple.name(), - new HANASpatialFunction( "ST_IsSimple", StandardBasicTypes.NUMERIC_BOOLEAN, false ) - ); + new HANASpatialFunction( "ST_IsSimple", StandardBasicTypes.NUMERIC_BOOLEAN, false ) ); registerFunction( SpatialFunction.overlaps.name(), - new HANASpatialFunction( "ST_Overlaps", StandardBasicTypes.NUMERIC_BOOLEAN, true ) - ); + new HANASpatialFunction( "ST_Overlaps", StandardBasicTypes.NUMERIC_BOOLEAN, true ) ); registerFunction( SpatialFunction.relate.name(), - new HANASpatialFunction( "ST_Relate", StandardBasicTypes.NUMERIC_BOOLEAN, true ) - ); + new HANASpatialFunction( "ST_Relate", StandardBasicTypes.NUMERIC_BOOLEAN, true ) ); registerFunction( SpatialFunction.srid.name(), - new HANASpatialFunction( "ST_SRID", StandardBasicTypes.INTEGER, false ) - ); + new HANASpatialFunction( "ST_SRID", StandardBasicTypes.INTEGER, false ) ); registerFunction( SpatialFunction.symdifference.name(), new HANASpatialFunction( "ST_SymDifference", true ) ); registerFunction( SpatialFunction.touches.name(), - new HANASpatialFunction( "ST_Touches", StandardBasicTypes.NUMERIC_BOOLEAN, true ) - ); + new HANASpatialFunction( "ST_Touches", StandardBasicTypes.NUMERIC_BOOLEAN, true ) ); registerFunction( SpatialFunction.transform.name(), new HANASpatialFunction( "ST_Transform", false ) ); registerFunction( SpatialFunction.within.name(), - new HANASpatialFunction( "ST_Within", StandardBasicTypes.NUMERIC_BOOLEAN, true ) - ); + new HANASpatialFunction( "ST_Within", StandardBasicTypes.NUMERIC_BOOLEAN, true ) ); + + /* + * Additional HANA functions + */ + registerFunction( HANASpatialFunctions.alphashape.name(), + new HANASpatialFunction( HANASpatialFunctions.alphashape.getFunctionName(), false ) ); + registerFunction( HANASpatialFunctions.area.name(), + new HANASpatialFunction( HANASpatialFunctions.area.getFunctionName(), StandardBasicTypes.DOUBLE, false ) ); + registerFunction( HANASpatialFunctions.asewkb.name(), + new HANASpatialFunction( HANASpatialFunctions.asewkb.getFunctionName(), StandardBasicTypes.MATERIALIZED_BLOB, false ) ); + registerFunction( HANASpatialFunctions.asewkt.name(), + new HANASpatialFunction( HANASpatialFunctions.asewkt.getFunctionName(), StandardBasicTypes.MATERIALIZED_CLOB, false ) ); + registerFunction( HANASpatialFunctions.asgeojson.name(), + new HANASpatialFunction( HANASpatialFunctions.asgeojson.getFunctionName(), StandardBasicTypes.MATERIALIZED_CLOB, false ) ); + registerFunction( HANASpatialFunctions.assvg.name(), + new HANASpatialFunction( HANASpatialFunctions.assvg.getFunctionName(), StandardBasicTypes.MATERIALIZED_CLOB, false ) ); + registerFunction( HANASpatialFunctions.assvgaggr.name(), + new HANASpatialFunction( HANASpatialFunctions.assvgaggr.getFunctionName(), StandardBasicTypes.MATERIALIZED_CLOB, false, true ) ); + registerFunction( HANASpatialFunctions.aswkb.name(), + new HANASpatialFunction( HANASpatialFunctions.aswkb.getFunctionName(), StandardBasicTypes.MATERIALIZED_BLOB, false ) ); + registerFunction( HANASpatialFunctions.aswkt.name(), + new HANASpatialFunction( HANASpatialFunctions.aswkt.getFunctionName(), StandardBasicTypes.MATERIALIZED_CLOB, false ) ); + registerFunction( HANASpatialFunctions.centroid.name(), + new HANASpatialFunction( HANASpatialFunctions.centroid.getFunctionName(), false ) ); + registerFunction( HANASpatialFunctions.convexhullaggr.name(), + new HANASpatialFunction( HANASpatialFunctions.convexhullaggr.getFunctionName(), true, true ) ); + registerFunction( + HANASpatialFunctions.coorddim.name(), + new HANASpatialFunction( HANASpatialFunctions.coorddim.getFunctionName(), StandardBasicTypes.INTEGER, false ) ); + registerFunction( + HANASpatialFunctions.coveredby.name(), + new HANASpatialFunction( HANASpatialFunctions.coveredby.getFunctionName(), StandardBasicTypes.NUMERIC_BOOLEAN, true ) ); + registerFunction( + HANASpatialFunctions.covers.name(), + new HANASpatialFunction( HANASpatialFunctions.covers.getFunctionName(), StandardBasicTypes.NUMERIC_BOOLEAN, true ) ); + registerFunction( + HANASpatialFunctions.endpoint.name(), + new HANASpatialFunction( HANASpatialFunctions.endpoint.getFunctionName(), false ) ); + registerFunction( HANASpatialFunctions.envelopeaggr.name(), + new HANASpatialFunction( HANASpatialFunctions.envelopeaggr.getFunctionName(), true, true ) ); + registerFunction( + HANASpatialFunctions.exteriorring.name(), + new HANASpatialFunction( HANASpatialFunctions.exteriorring.getFunctionName(), false ) ); + registerFunction( HANASpatialFunctions.geomfromewkb.name(), + new HANASpatialFunction( HANASpatialFunctions.geomfromewkb.getFunctionName(), false, true ) ); + registerFunction( HANASpatialFunctions.geomfromewkt.name(), + new HANASpatialFunction( HANASpatialFunctions.geomfromewkt.getFunctionName(), false, true ) ); + registerFunction( HANASpatialFunctions.geomfromtext.name(), + new HANASpatialFunction( HANASpatialFunctions.geomfromtext.getFunctionName(), false, true ) ); + registerFunction( HANASpatialFunctions.geomfromwkb.name(), + new HANASpatialFunction( HANASpatialFunctions.geomfromwkb.getFunctionName(), false, true ) ); + registerFunction( HANASpatialFunctions.geomfromwkt.name(), + new HANASpatialFunction( HANASpatialFunctions.geomfromwkt.getFunctionName(), false, true ) ); + registerFunction( + HANASpatialFunctions.geometryn.name(), + new HANASpatialFunction( HANASpatialFunctions.geometryn.getFunctionName(), false ) ); + registerFunction( + HANASpatialFunctions.interiorringn.name(), + new HANASpatialFunction( HANASpatialFunctions.interiorringn.getFunctionName(), false ) ); + registerFunction( HANASpatialFunctions.intersectionaggr.name(), + new HANASpatialFunction( HANASpatialFunctions.intersectionaggr.getFunctionName(), true, true ) ); + registerFunction( + HANASpatialFunctions.intersectsrect.name(), + new HANASpatialFunction( HANASpatialFunctions.intersectsrect.getFunctionName(), StandardBasicTypes.NUMERIC_BOOLEAN, + new boolean[]{ true, true } ) ); + registerFunction( + HANASpatialFunctions.is3d.name(), + new HANASpatialFunction( HANASpatialFunctions.is3d.getFunctionName(), StandardBasicTypes.NUMERIC_BOOLEAN, false ) ); + registerFunction( + HANASpatialFunctions.isclosed.name(), + new HANASpatialFunction( HANASpatialFunctions.isclosed.getFunctionName(), StandardBasicTypes.NUMERIC_BOOLEAN, false ) ); + registerFunction( + HANASpatialFunctions.ismeasured.name(), + new HANASpatialFunction( HANASpatialFunctions.ismeasured.getFunctionName(), StandardBasicTypes.NUMERIC_BOOLEAN, false ) ); + registerFunction( + HANASpatialFunctions.isring.name(), + new HANASpatialFunction( HANASpatialFunctions.isring.getFunctionName(), StandardBasicTypes.NUMERIC_BOOLEAN, false ) ); + registerFunction( + HANASpatialFunctions.isvalid.name(), + new HANASpatialFunction( HANASpatialFunctions.isvalid.getFunctionName(), StandardBasicTypes.NUMERIC_BOOLEAN, false ) ); + registerFunction( + HANASpatialFunctions.length.name(), + new HANASpatialFunction( HANASpatialFunctions.length.getFunctionName(), StandardBasicTypes.DOUBLE, false ) ); + registerFunction( + HANASpatialFunctions.m.name(), + new HANASpatialFunction( HANASpatialFunctions.m.getFunctionName(), StandardBasicTypes.DOUBLE, false ) ); + registerFunction( + HANASpatialFunctions.mmax.name(), + new HANASpatialFunction( HANASpatialFunctions.mmax.getFunctionName(), StandardBasicTypes.DOUBLE, false ) ); + registerFunction( + HANASpatialFunctions.mmin.name(), + new HANASpatialFunction( HANASpatialFunctions.mmin.getFunctionName(), StandardBasicTypes.DOUBLE, false ) ); + registerFunction( + HANASpatialFunctions.numgeometries.name(), + new HANASpatialFunction( HANASpatialFunctions.numgeometries.getFunctionName(), StandardBasicTypes.INTEGER, false ) ); + registerFunction( + HANASpatialFunctions.numinteriorring.name(), + new HANASpatialFunction( HANASpatialFunctions.numinteriorring.getFunctionName(), StandardBasicTypes.INTEGER, false ) ); + registerFunction( + HANASpatialFunctions.numinteriorrings.name(), + new HANASpatialFunction( HANASpatialFunctions.numinteriorrings.getFunctionName(), StandardBasicTypes.INTEGER, false ) ); + registerFunction( + HANASpatialFunctions.numpoints.name(), + new HANASpatialFunction( HANASpatialFunctions.numpoints.getFunctionName(), StandardBasicTypes.INTEGER, false ) ); + registerFunction( + HANASpatialFunctions.orderingequals.name(), + new HANASpatialFunction( HANASpatialFunctions.orderingequals.getFunctionName(), StandardBasicTypes.NUMERIC_BOOLEAN, true ) ); + registerFunction( + HANASpatialFunctions.perimeter.name(), + new HANASpatialFunction( HANASpatialFunctions.perimeter.getFunctionName(), StandardBasicTypes.DOUBLE, false ) ); + registerFunction( + HANASpatialFunctions.pointonsurface.name(), + new HANASpatialFunction( HANASpatialFunctions.pointonsurface.getFunctionName(), false ) ); + registerFunction( + HANASpatialFunctions.pointn.name(), + new HANASpatialFunction( HANASpatialFunctions.pointn.getFunctionName(), false ) ); + registerFunction( + HANASpatialFunctions.snaptogrid.name(), + new HANASpatialFunction( HANASpatialFunctions.snaptogrid.getFunctionName(), false ) ); + registerFunction( + HANASpatialFunctions.startpoint.name(), + new HANASpatialFunction( HANASpatialFunctions.startpoint.getFunctionName(), false ) ); + registerFunction( HANASpatialFunctions.unionaggr.name(), + new HANASpatialFunction( HANASpatialFunctions.unionaggr.getFunctionName(), true, true ) ); + registerFunction( + HANASpatialFunctions.x.name(), + new HANASpatialFunction( HANASpatialFunctions.x.getFunctionName(), StandardBasicTypes.DOUBLE, false ) ); + registerFunction( + HANASpatialFunctions.xmax.name(), + new HANASpatialFunction( HANASpatialFunctions.xmax.getFunctionName(), StandardBasicTypes.DOUBLE, false ) ); + registerFunction( + HANASpatialFunctions.xmin.name(), + new HANASpatialFunction( HANASpatialFunctions.xmin.getFunctionName(), StandardBasicTypes.DOUBLE, false ) ); + registerFunction( + HANASpatialFunctions.y.name(), + new HANASpatialFunction( HANASpatialFunctions.y.getFunctionName(), StandardBasicTypes.DOUBLE, false ) ); + registerFunction( + HANASpatialFunctions.ymax.name(), + new HANASpatialFunction( HANASpatialFunctions.ymax.getFunctionName(), StandardBasicTypes.DOUBLE, false ) ); + registerFunction( + HANASpatialFunctions.ymin.name(), + new HANASpatialFunction( HANASpatialFunctions.ymin.getFunctionName(), StandardBasicTypes.DOUBLE, false ) ); + registerFunction( + HANASpatialFunctions.z.name(), + new HANASpatialFunction( HANASpatialFunctions.z.getFunctionName(), StandardBasicTypes.DOUBLE, false ) ); + registerFunction( + HANASpatialFunctions.zmax.name(), + new HANASpatialFunction( HANASpatialFunctions.zmax.getFunctionName(), StandardBasicTypes.DOUBLE, false ) ); + registerFunction( + HANASpatialFunctions.zmin.name(), + new HANASpatialFunction( HANASpatialFunctions.zmin.getFunctionName(), StandardBasicTypes.DOUBLE, false ) ); } @Override @@ -154,8 +294,7 @@ public class HANASpatialDialect extends HANAColumnStoreDialect implements Spatia } }, - Boolean.FALSE - ).booleanValue(); + Boolean.FALSE ).booleanValue(); if ( determineCrsIdFromDatabase ) { typeContributions.contributeType( new GeolatteGeometryType( HANAGeometryTypeDescriptor.CRS_LOADING_INSTANCE ) ); diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/hana/HANASpatialFunction.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/hana/HANASpatialFunction.java index f1eeae3dd0..5fbab410fb 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/hana/HANASpatialFunction.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/hana/HANASpatialFunction.java @@ -6,6 +6,7 @@ */ package org.hibernate.spatial.dialect.hana; +import java.util.BitSet; import java.util.List; import org.hibernate.dialect.function.StandardSQLFunction; @@ -16,16 +17,39 @@ public class HANASpatialFunction extends StandardSQLFunction { private static final String AS_EWKB_SUFFIX = ".ST_AsEWKB()"; - private final boolean firstArgumentIsGeometryType; + private final BitSet argumentIsGeometryTypeMask = new BitSet(); + private final boolean staticFunction; public HANASpatialFunction(String name, boolean firstArgumentIsGeometryType) { super( name ); - this.firstArgumentIsGeometryType = firstArgumentIsGeometryType; + this.argumentIsGeometryTypeMask.set( 1, firstArgumentIsGeometryType ); + this.staticFunction = false; + } + + public HANASpatialFunction(String name, boolean firstArgumentIsGeometryType, boolean staticFunction) { + super( name ); + this.argumentIsGeometryTypeMask.set( staticFunction ? 0 : 1, firstArgumentIsGeometryType ); + this.staticFunction = staticFunction; } public HANASpatialFunction(String name, Type registeredType, boolean firstArgumentIsGeometryType) { super( name, registeredType ); - this.firstArgumentIsGeometryType = firstArgumentIsGeometryType; + this.argumentIsGeometryTypeMask.set( 1, firstArgumentIsGeometryType ); + this.staticFunction = false; + } + + public HANASpatialFunction(String name, Type registeredType, boolean[] argumentIsGeometryTypeMask) { + super( name, registeredType ); + for ( int i = 0; i < argumentIsGeometryTypeMask.length; i++ ) { + this.argumentIsGeometryTypeMask.set( i + 1, argumentIsGeometryTypeMask[i] ); + } + this.staticFunction = false; + } + + public HANASpatialFunction(String name, Type registeredType, boolean firstArgumentIsGeometryType, boolean staticFunction) { + super( name, registeredType ); + this.argumentIsGeometryTypeMask.set( staticFunction ? 0 : 1, firstArgumentIsGeometryType ); + this.staticFunction = staticFunction; } @Override @@ -35,18 +59,30 @@ public class HANASpatialFunction extends StandardSQLFunction { } else { final StringBuilder buf = new StringBuilder(); - // If the first argument is an expression, e.g. a nested function, strip the .ST_AsEWKB() suffix - buf.append( stripEWKBSuffix( arguments.get( 0 ) ) ); + int firstArgumentIndex; + if ( staticFunction ) { + // Add function call + buf.append( getName() ); + firstArgumentIndex = 0; + } + else { + // If the first argument is an expression, e.g. a nested function, strip the .ST_AsEWKB() suffix + buf.append( stripEWKBSuffix( arguments.get( 0 ) ) ); - // Add function call - buf.append( "." ).append( getName() ).append( '(' ); + // Add function call + buf.append( "." ).append( getName() ); + + firstArgumentIndex = 1; + } + + buf.append( '(' ); // Add function arguments - for ( int i = 1; i < arguments.size(); i++ ) { + for ( int i = firstArgumentIndex; i < arguments.size(); i++ ) { final Object argument = arguments.get( i ); // Check if first argument needs to be parsed from EWKB. This is the case if the first argument is a // parameter that is set as EWKB or if it's a nested function call. - final boolean parseFromWKB = ( this.firstArgumentIsGeometryType && i == 1 && "?".equals( argument ) ); + final boolean parseFromWKB = ( isGeometryArgument( i ) && "?".equals( argument ) ); if ( parseFromWKB ) { buf.append( "ST_GeomFromEWKB(" ); } @@ -75,4 +111,8 @@ public class HANASpatialFunction extends StandardSQLFunction { return argument; } + + private boolean isGeometryArgument(int idx) { + return this.argumentIsGeometryTypeMask.size() > idx && this.argumentIsGeometryTypeMask.get( idx ); + } } diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/hana/HANASpatialFunctions.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/hana/HANASpatialFunctions.java new file mode 100644 index 0000000000..4504554155 --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/hana/HANASpatialFunctions.java @@ -0,0 +1,129 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.spatial.dialect.hana; + +public enum HANASpatialFunctions { + alphashape("ST_AlphaShape"), + + area("ST_Area"), + + asewkb("ST_AsEWKB"), + + asewkt("ST_AsEWKT"), + + asgeojson("ST_AsGeoJSON"), + + assvg("ST_AsSVG"), + + assvgaggr("ST_AsSVGAggr"), + + aswkb("ST_AsWKB"), + + aswkt("ST_AsWKT"), + + centroid("ST_Centroid"), + + convexhullaggr("ST_ConvexHullAggr"), + + coorddim("ST_CoordDim"), + + coveredby("ST_CoveredBy"), + + covers("ST_Covers"), + + endpoint("ST_EndPoint"), + + envelopeaggr("ST_EnvelopeAggr"), + + exteriorring("ST_ExteriorRing"), + + geomfromewkb("ST_GeomFromEWKB"), + + geomfromewkt("ST_GeomFromEWKT"), + + geomfromtext("ST_GeomFromText"), + + geomfromwkb("ST_GeomFromWKB"), + + geomfromwkt("ST_GeomFromWKT"), + + geometryn("ST_GeometryN"), + + interiorringn("ST_InteriorRingN"), + + intersectionaggr("ST_IntersectionAggr"), + + intersectsrect("ST_IntersectsRect"), + + is3d("ST_Is3D"), + + isclosed("ST_IsClosed"), + + ismeasured("ST_IsMeasured"), + + isring("ST_IsRing"), + + isvalid("ST_IsValid"), + + length("ST_Length"), + + m("ST_M"), + + mmax("ST_MMax"), + + mmin("ST_MMin"), + + numgeometries("ST_NumGeometries"), + + numinteriorring("ST_NumInteriorRing"), + + numinteriorrings("ST_NumInteriorRings"), + + numpoints("ST_NumPoints"), + + orderingequals("ST_OrderingEquals"), + + perimeter("ST_Perimeter"), + + pointonsurface("ST_PointOnSurface"), + + pointn("ST_PointN"), + + snaptogrid("ST_SnapToGrid"), + + startpoint("ST_StartPoint"), + + unionaggr("ST_UnionAggr"), + + x("ST_X"), + + xmax("ST_XMax"), + + xmin("ST_XMin"), + + y("ST_Y"), + + ymax("ST_YMax"), + + ymin("ST_YMin"), + + z("ST_Z"), + + zmax("ST_ZMax"), + + zmin("ST_ZMin"); + + private final String functionName; + + private HANASpatialFunctions(String functionName) { + this.functionName = functionName; + } + + public String getFunctionName() { + return functionName; + } +} diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/dialect/hana/TestHANASpatialFunctions.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/dialect/hana/TestHANASpatialFunctions.java new file mode 100644 index 0000000000..5d1e8befde --- /dev/null +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/dialect/hana/TestHANASpatialFunctions.java @@ -0,0 +1,1037 @@ +package org.hibernate.spatial.dialect.hana; + +import static java.lang.String.format; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +import org.hibernate.cfg.Configuration; +import org.hibernate.spatial.HSMessageLogger; +import org.hibernate.spatial.integration.TestSpatialFunctions; +import org.hibernate.spatial.testing.dialects.hana.HANAExpectationsFactory; +import org.hibernate.testing.RequiresDialect; +import org.jboss.logging.Logger; +import org.junit.Test; + +import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.geom.Point; +import com.vividsolutions.jts.io.WKBWriter; +import com.vividsolutions.jts.io.WKTWriter; + +@RequiresDialect(value = HANASpatialDialect.class, comment = "This test tests the HANA spatial functions not covered by Hibernate Spatial", jiraKey = "HHH-12426") +public class TestHANASpatialFunctions extends TestSpatialFunctions { + + private static final HSMessageLogger LOG = Logger.getMessageLogger( + HSMessageLogger.class, + TestHANASpatialFunctions.class.getName() ); + + protected HANAExpectationsFactory hanaExpectationsFactory; + + @Override + protected void afterConfigurationBuilt(Configuration cfg) { + super.afterConfigurationBuilt( cfg ); + this.hanaExpectationsFactory = (HANAExpectationsFactory) this.expectationsFactory; + } + + @Override + protected HSMessageLogger getLogger() { + return LOG; + } + + @Test + public void test_alphashape_on_jts() throws SQLException { + alphashape( JTS ); + } + + @Test + public void test_alphashape_on_geolatte() throws SQLException { + alphashape( GEOLATTE ); + } + + public void alphashape(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getAlphaShape( 1 ); + String hql = format( + "SELECT id, alphashape(geom, 1) FROM org.hibernate.spatial.integration.%s.GeomEntity where geometrytype(geom) in ('ST_Point', 'ST_MultiPoint')", + pckg ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_area_on_jts() throws SQLException { + area( JTS ); + } + + @Test + public void test_area_on_geolatte() throws SQLException { + area( GEOLATTE ); + } + + public void area(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getArea(); + String hql = format( + "SELECT id, area(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where geometrytype(geom) in ('ST_Polygon', 'ST_MultiPolygon')", + pckg ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_asewkb_on_jts() throws SQLException { + asewkb( JTS ); + } + + @Test + public void test_asewkb_on_geolatte() throws SQLException { + asewkb( GEOLATTE ); + } + + public void asewkb(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getAsEWKB(); + String hql = format( "SELECT id, asewkb(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity", pckg ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_asewkt_on_jts() throws SQLException { + asewkt( JTS ); + } + + @Test + public void test_asewkt_on_geolatte() throws SQLException { + asewkt( GEOLATTE ); + } + + public void asewkt(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getAsEWKT(); + String hql = format( "SELECT id, asewkt(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity", pckg ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_asgeojson_on_jts() throws SQLException { + asgeojson( JTS ); + } + + @Test + public void test_asgeojson_on_geolatte() throws SQLException { + asgeojson( GEOLATTE ); + } + + public void asgeojson(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getAsGeoJSON(); + String hql = format( "SELECT id, asgeojson(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity", pckg ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_assvg_on_jts() throws SQLException { + assvg( JTS ); + } + + @Test + public void test_assvg_on_geolatte() throws SQLException { + assvg( GEOLATTE ); + } + + public void assvg(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getAsSVG(); + String hql = format( "SELECT id, assvg(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity", pckg ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_assvgaggr_on_jts() throws SQLException { + assvgaggr( JTS ); + } + + @Test + public void test_assvgaggr_on_geolatte() throws SQLException { + assvgaggr( GEOLATTE ); + } + + public void assvgaggr(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getAsSVGAggr(); + String hql = format( "SELECT cast(count(g) as int), assvgaggr(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity g", pckg ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_aswkb_on_jts() throws SQLException { + aswkb( JTS ); + } + + @Test + public void test_aswkb_on_geolatte() throws SQLException { + aswkb( GEOLATTE ); + } + + public void aswkb(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getAsWKB(); + String hql = format( "SELECT id, aswkb(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity", pckg ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_aswkt_on_jts() throws SQLException { + aswkt( JTS ); + } + + @Test + public void test_aswkt_on_geolatte() throws SQLException { + aswkt( GEOLATTE ); + } + + public void aswkt(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getAsWKT(); + String hql = format( "SELECT id, aswkt(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity", pckg ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_convexhullaggr_on_jts() throws SQLException { + convexhullaggr( JTS ); + } + + @Test + public void test_convexhullaggr_on_geolatte() throws SQLException { + convexhullaggr( GEOLATTE ); + } + + public void convexhullaggr(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getConvexHullAggr(); + String hql = format( "SELECT cast(count(g) as int), convexhullaggr(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity g", pckg ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_centroid_on_jts() throws SQLException { + centroid( JTS ); + } + + @Test + public void test_centroid_on_geolatte() throws SQLException { + centroid( GEOLATTE ); + } + + public void centroid(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getCentroid(); + String hql = format( "SELECT id, centroid(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity g where geometrytype(geom) = 'ST_Polygon'", pckg ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_coorddim_on_jts() throws SQLException { + coorddim( JTS ); + } + + @Test + public void test_coorddim_on_geolatte() throws SQLException { + coorddim( GEOLATTE ); + } + + public void coorddim(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getCoordDim(); + String hql = format( "SELECT id, coorddim(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity", pckg ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_coveredby_on_jts() throws SQLException { + coveredby( JTS ); + } + + @Test + public void test_coveredby_on_geolatte() throws SQLException { + coveredby( GEOLATTE ); + } + + public void coveredby(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getCoveredBy( expectationsFactory.getTestPolygon() ); + String hql = format( + "SELECT id, coveredby(geom, :filter) FROM org.hibernate.spatial.integration.%s.GeomEntity where coveredby(geom, :filter) = true and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + Map params = createQueryParams( "filter", expectationsFactory.getTestPolygon() ); + retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg ); + } + + @Test + public void test_covers_on_jts() throws SQLException { + covers( JTS ); + } + + @Test + public void test_covers_on_geolatte() throws SQLException { + covers( GEOLATTE ); + } + + public void covers(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getCovers( expectationsFactory.getTestPolygon() ); + String hql = format( + "SELECT id, covers(geom, :filter) FROM org.hibernate.spatial.integration.%s.GeomEntity where covers(geom, :filter) = true and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + Map params = createQueryParams( "filter", expectationsFactory.getTestPolygon() ); + retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg ); + } + + @Test + public void test_endpoint_on_jts() throws SQLException { + endpoint( JTS ); + } + + @Test + public void test_endpoint_on_geolatte() throws SQLException { + endpoint( GEOLATTE ); + } + + public void endpoint(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getEndPoint(); + String hql = format( "SELECT id, endpoint(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity g where geometrytype(geom) = 'ST_LineString'", + pckg ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_envelopeaggr_on_jts() throws SQLException { + envelopeaggr( JTS ); + } + + @Test + public void test_envelopeaggr_on_geolatte() throws SQLException { + envelopeaggr( GEOLATTE ); + } + + public void envelopeaggr(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getEnvelopeAggr(); + String hql = format( "SELECT cast(count(g) as int), envelopeaggr(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity g", pckg ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_exteriorring_on_jts() throws SQLException { + exteriorring( JTS ); + } + + @Test + public void test_exteriorring_on_geolatte() throws SQLException { + exteriorring( GEOLATTE ); + } + + public void exteriorring(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getExteriorRing(); + String hql = format( "SELECT id, exteriorring(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity g where geometrytype(geom) = 'ST_Polygon'", + pckg ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_geomfromewkb_on_jts() throws SQLException { + geomfromewkb( JTS ); + } + + @Test + public void test_geomfromewkb_on_geolatte() throws SQLException { + geomfromewkb( GEOLATTE ); + } + + public void geomfromewkb(String pckg) throws SQLException { + WKBWriter writer = new WKBWriter( 2, true ); + byte[] ewkb = writer.write( expectationsFactory.getTestPolygon() ); + Map dbexpected = hanaExpectationsFactory.getGeomFromEWKB( ewkb ); + String hql = format( "SELECT 1, cast(geomfromewkb(:param) as %s) FROM org.hibernate.spatial.integration.%s.GeomEntity g", + getGeometryTypeFromPackage( pckg ), pckg ); + Map params = createQueryParams( "param", ewkb ); + retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg ); + } + + @Test + public void test_geomfromewkt_on_jts() throws SQLException { + geomfromewkt( JTS ); + } + + @Test + public void test_geomfromewkt_on_geolatte() throws SQLException { + geomfromewkt( GEOLATTE ); + } + + public void geomfromewkt(String pckg) throws SQLException { + WKTWriter writer = new WKTWriter(); + String ewkt = "SRID=" + expectationsFactory.getTestSrid() + ";" + writer.write( expectationsFactory.getTestPolygon() ); + Map dbexpected = hanaExpectationsFactory.getGeomFromEWKT( ewkt ); + String hql = format( "SELECT 1, cast(geomfromewkt(:param) as %s) FROM org.hibernate.spatial.integration.%s.GeomEntity g", + getGeometryTypeFromPackage( pckg ), pckg ); + Map params = createQueryParams( "param", ewkt ); + retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg ); + } + + @Test + public void test_geomfromtext_on_jts() throws SQLException { + geomfromtext( JTS ); + } + + @Test + public void test_geomfromtext_on_geolatte() throws SQLException { + geomfromtext( GEOLATTE ); + } + + public void geomfromtext(String pckg) throws SQLException { + String text = expectationsFactory.getTestPolygon().toText(); + Map dbexpected = hanaExpectationsFactory.getGeomFromText( text ); + String hql = format( "SELECT 1, cast(geomfromtext(:param) as %s) FROM org.hibernate.spatial.integration.%s.GeomEntity g", + getGeometryTypeFromPackage( pckg ), pckg ); + Map params = createQueryParams( "param", text ); + retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg ); + } + + @Test + public void test_geomfromwkb_on_jts() throws SQLException { + geomfromwkb( JTS ); + } + + @Test + public void test_geomfromwkb_on_geolatte() throws SQLException { + geomfromwkb( GEOLATTE ); + } + + public void geomfromwkb(String pckg) throws SQLException { + WKBWriter writer = new WKBWriter( 2, false ); + byte[] wkb = writer.write( expectationsFactory.getTestPolygon() ); + Map dbexpected = hanaExpectationsFactory.getGeomFromWKB( wkb ); + String hql = format( "SELECT 1, cast(geomfromwkb(:param) as %s) FROM org.hibernate.spatial.integration.%s.GeomEntity g", + getGeometryTypeFromPackage( pckg ), pckg ); + Map params = createQueryParams( "param", wkb ); + retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg ); + } + + @Test + public void test_geomfromwkt_on_jts() throws SQLException { + geomfromwkt( JTS ); + } + + @Test + public void test_geomfromwkt_on_geolatte() throws SQLException { + geomfromwkt( GEOLATTE ); + } + + public void geomfromwkt(String pckg) throws SQLException { + WKTWriter writer = new WKTWriter(); + String wkt = writer.write( expectationsFactory.getTestPolygon() ); + Map dbexpected = hanaExpectationsFactory.getGeomFromWKT( wkt ); + String hql = format( "SELECT 1, cast(geomfromwkt(:param) as %s) FROM org.hibernate.spatial.integration.%s.GeomEntity g", + getGeometryTypeFromPackage( pckg ), pckg ); + Map params = createQueryParams( "param", wkt ); + retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg ); + } + + @Test + public void test_geometryn_on_jts() throws SQLException { + geometryn( JTS ); + } + + @Test + public void test_geometryn_on_geolatte() throws SQLException { + geometryn( GEOLATTE ); + } + + public void geometryn(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getGeometryN( 1 ); + String hql = format( + "SELECT id, cast(geometryn(geom, :n) as %s) FROM org.hibernate.spatial.integration.%s.GeomEntity g where geometrytype(geom) = 'ST_GeometryCollection'", + getGeometryTypeFromPackage( pckg ), pckg ); + Map params = createQueryParams( "n", 1 ); + retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg ); + } + + @Test + public void test_interiorringn_on_jts() throws SQLException { + interiorringn( JTS ); + } + + @Test + public void test_interiorringn_on_geolatte() throws SQLException { + interiorringn( GEOLATTE ); + } + + public void interiorringn(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getInteriorRingN( 1 ); + String hql = format( + "SELECT id, cast(interiorringn(geom, :n) as %s) FROM org.hibernate.spatial.integration.%s.GeomEntity g where geometrytype(geom) = 'ST_Polygon'", + getGeometryTypeFromPackage( pckg ), pckg ); + Map params = createQueryParams( "n", 1 ); + retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg ); + } + + @Test + public void test_intersectionaggr_on_jts() throws SQLException { + intersectionaggr( JTS ); + } + + @Test + public void test_intersectionaggr_on_geolatte() throws SQLException { + intersectionaggr( GEOLATTE ); + } + + public void intersectionaggr(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getIntersectionAggr(); + String hql = format( "SELECT cast(count(g) as int), intersectionaggr(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity g", pckg ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_intersectsrect_on_jts() throws SQLException { + intersectsrect( JTS ); + } + + @Test + public void test_intersectsrect_on_geolatte() throws SQLException { + intersectsrect( GEOLATTE ); + } + + public void intersectsrect(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getIntersectsRect( (Point) expectationsFactory.getTestPoint().reverse(), + expectationsFactory.getTestPoint() ); + String hql = format( + "SELECT id, intersectsrect(geom, :pmin, :pmax) FROM org.hibernate.spatial.integration.%s.GeomEntity where intersectsrect(geom, :pmin, :pmax) = true and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + Map params = createQueryParams( "pmin", expectationsFactory.getTestPoint().reverse() ); + params.put( "pmax", expectationsFactory.getTestPoint() ); + retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg ); + } + + @Test + public void test_is3d_on_jts() throws SQLException { + is3d( JTS ); + } + + @Test + public void test_is3d_on_geolatte() throws SQLException { + is3d( GEOLATTE ); + } + + public void is3d(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getIs3D(); + String hql = format( + "SELECT id, is3d(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where is3d(geom) = true and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_isclosed_on_jts() throws SQLException { + isclosed( JTS ); + } + + @Test + public void test_isclosed_on_geolatte() throws SQLException { + isclosed( GEOLATTE ); + } + + public void isclosed(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getIsClosed(); + String hql = format( + "SELECT id, isclosed(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where geometrytype(geom) in ('ST_LineString', 'ST_MultiLineString') and isclosed(geom) = true and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_ismeasured_on_jts() throws SQLException { + ismeasured( JTS ); + } + + @Test + public void test_ismeasured_on_geolatte() throws SQLException { + ismeasured( GEOLATTE ); + } + + public void ismeasured(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getIsMeasured(); + String hql = format( + "SELECT id, ismeasured(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where ismeasured(geom) = true and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_isring_on_jts() throws SQLException { + isring( JTS ); + } + + @Test + public void test_isring_on_geolatte() throws SQLException { + isring( GEOLATTE ); + } + + public void isring(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getIsRing(); + String hql = format( + "SELECT id, isring(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where geometrytype(geom) in ('ST_LineString') and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_isvalid_on_jts() throws SQLException { + isvalid( JTS ); + } + + @Test + public void test_isvalid_on_geolatte() throws SQLException { + isvalid( GEOLATTE ); + } + + public void isvalid(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getIsValid(); + String hql = format( + "SELECT id, isvalid(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where isvalid(geom) = true and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_length_on_jts() throws SQLException { + length( JTS ); + } + + @Test + public void test_length_on_geolatte() throws SQLException { + length( GEOLATTE ); + } + + public void length(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getLength(); + String hql = format( + "SELECT id, length(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where geometrytype(geom) in ('ST_LineString', 'ST_MultiLineString') and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_m_on_jts() throws SQLException { + m( JTS ); + } + + @Test + public void test_m_on_geolatte() throws SQLException { + m( GEOLATTE ); + } + + public void m(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getM(); + String hql = format( + "SELECT id, m(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where geometrytype(geom) in ('ST_Point') and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_mmax_on_jts() throws SQLException { + mmax( JTS ); + } + + @Test + public void test_mmax_on_geolatte() throws SQLException { + mmax( GEOLATTE ); + } + + public void mmax(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getMMax(); + String hql = format( + "SELECT id, mmax(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_mmin_on_jts() throws SQLException { + mmin( JTS ); + } + + @Test + public void test_mmin_on_geolatte() throws SQLException { + mmin( GEOLATTE ); + } + + public void mmin(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getMMin(); + String hql = format( + "SELECT id, mmin(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_numgeometries_on_jts() throws SQLException { + numgeometries( JTS ); + } + + @Test + public void test_numgeometries_on_geolatte() throws SQLException { + numgeometries( GEOLATTE ); + } + + public void numgeometries(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getNumGeometries(); + String hql = format( + "SELECT id, numgeometries(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where geometrytype(geom) in ('ST_GeometryCollection') and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_numinteriorring_on_jts() throws SQLException { + numinteriorring( JTS ); + } + + @Test + public void test_numnuminteriorring_on_geolatte() throws SQLException { + numinteriorring( GEOLATTE ); + } + + public void numinteriorring(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getNumInteriorRing(); + String hql = format( + "SELECT id, numinteriorring(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where geometrytype(geom) in ('ST_Polygon') and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_numinteriorrings_on_jts() throws SQLException { + numinteriorrings( JTS ); + } + + @Test + public void test_numnuminteriorrings_on_geolatte() throws SQLException { + numinteriorrings( GEOLATTE ); + } + + public void numinteriorrings(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getNumInteriorRings(); + String hql = format( + "SELECT id, numinteriorrings(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where geometrytype(geom) in ('ST_Polygon') and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_numpoints_on_jts() throws SQLException { + numpoints( JTS ); + } + + @Test + public void test_numpoints_on_geolatte() throws SQLException { + numpoints( GEOLATTE ); + } + + public void numpoints(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getNumPoints(); + String hql = format( + "SELECT id, numpoints(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where geometrytype(geom) in ('ST_LineString') and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_orderingequals_on_jts() throws SQLException { + orderingequals( JTS ); + } + + @Test + public void test_orderingequals_on_geolatte() throws SQLException { + orderingequals( GEOLATTE ); + } + + public void orderingequals(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getOrderingEquals( expectationsFactory.getTestPolygon() ); + String hql = format( + "SELECT id, orderingequals(geom, :filter) FROM org.hibernate.spatial.integration.%s.GeomEntity where orderingequals(geom, :filter) = true and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + Map params = createQueryParams( "filter", expectationsFactory.getTestPolygon() ); + retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg ); + } + + @Test + public void test_perimeter_on_jts() throws SQLException { + perimeter( JTS ); + } + + @Test + public void test_perimeter_on_geolatte() throws SQLException { + perimeter( GEOLATTE ); + } + + public void perimeter(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getPerimeter(); + String hql = format( + "SELECT id, perimeter(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where geometrytype(geom) in ('ST_Polygon', 'ST_MultiPolygon') and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_pointonsurface_on_jts() throws SQLException { + pointonsurface( JTS ); + } + + @Test + public void test_pointonsurface_on_geolatte() throws SQLException { + pointonsurface( GEOLATTE ); + } + + public void pointonsurface(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getPointOnSurface(); + String hql = format( + "SELECT id, pointonsurface(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where geometrytype(geom) in ('ST_Polygon', 'ST_MultiPolygon') and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_pointn_on_jts() throws SQLException { + pointn( JTS ); + } + + @Test + public void test_pointn_on_geolatte() throws SQLException { + pointn( GEOLATTE ); + } + + public void pointn(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getPointN( 1 ); + String hql = format( + "SELECT id, pointn(geom, :n) FROM org.hibernate.spatial.integration.%s.GeomEntity where geometrytype(geom) in ('ST_LineString') and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + Map params = createQueryParams( "n", 1 ); + retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg ); + } + + @Test(expected = SQLException.class) // ST_GEOMETRY columns are not supported + public void test_snaptogrid_on_jts() throws SQLException { + snaptogrid( JTS ); + } + + @Test(expected = SQLException.class) // ST_GEOMETRY columns are not supported + public void test_snaptogrid_on_geolatte() throws SQLException { + snaptogrid( GEOLATTE ); + } + + public void snaptogrid(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getSnapToGrid(); + String hql = format( + "SELECT id, snaptogrid(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_startpoint_on_jts() throws SQLException { + startpoint( JTS ); + } + + @Test + public void test_startpoint_on_geolatte() throws SQLException { + startpoint( GEOLATTE ); + } + + public void startpoint(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getStartPoint(); + String hql = format( "SELECT id, startpoint(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity g where geometrytype(geom) = 'ST_LineString'", + pckg ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_unionaggr_on_jts() throws SQLException { + unionaggr( JTS ); + } + + @Test + public void test_unionaggr_on_geolatte() throws SQLException { + unionaggr( GEOLATTE ); + } + + public void unionaggr(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getUnionAggr(); + String hql = format( "SELECT cast(count(g) as int), unionaggr(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity g", pckg ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_x_on_jts() throws SQLException { + x( JTS ); + } + + @Test + public void test_x_on_geolatte() throws SQLException { + x( GEOLATTE ); + } + + public void x(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getX(); + String hql = format( + "SELECT id, x(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where geometrytype(geom) in ('ST_Point') and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_xmax_on_jts() throws SQLException { + xmax( JTS ); + } + + @Test + public void test_xmax_on_geolatte() throws SQLException { + xmax( GEOLATTE ); + } + + public void xmax(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getXMax(); + String hql = format( + "SELECT id, xmax(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_xmin_on_jts() throws SQLException { + xmin( JTS ); + } + + @Test + public void test_xmin_on_geolatte() throws SQLException { + xmin( GEOLATTE ); + } + + public void xmin(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getXMin(); + String hql = format( + "SELECT id, xmin(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_y_on_jts() throws SQLException { + y( JTS ); + } + + @Test + public void test_y_on_geolatte() throws SQLException { + y( GEOLATTE ); + } + + public void y(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getY(); + String hql = format( + "SELECT id, y(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where geometrytype(geom) in ('ST_Point') and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_ymax_on_jts() throws SQLException { + ymax( JTS ); + } + + @Test + public void test_ymax_on_geolatte() throws SQLException { + ymax( GEOLATTE ); + } + + public void ymax(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getYMax(); + String hql = format( + "SELECT id, ymax(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_ymin_on_jts() throws SQLException { + ymin( JTS ); + } + + @Test + public void test_ymin_on_geolatte() throws SQLException { + ymin( GEOLATTE ); + } + + public void ymin(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getYMin(); + String hql = format( + "SELECT id, ymin(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_z_on_jts() throws SQLException { + z( JTS ); + } + + @Test + public void test_z_on_geolatte() throws SQLException { + z( GEOLATTE ); + } + + public void z(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getZ(); + String hql = format( + "SELECT id, z(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where geometrytype(geom) in ('ST_Point') and srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_zmax_on_jts() throws SQLException { + zmax( JTS ); + } + + @Test + public void test_zmax_on_geolatte() throws SQLException { + zmax( GEOLATTE ); + } + + public void zmax(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getZMax(); + String hql = format( + "SELECT id, zmax(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + @Test + public void test_zmin_on_jts() throws SQLException { + zmin( JTS ); + } + + @Test + public void test_zmin_on_geolatte() throws SQLException { + zmin( GEOLATTE ); + } + + public void zmin(String pckg) throws SQLException { + Map dbexpected = hanaExpectationsFactory.getZMin(); + String hql = format( + "SELECT id, zmin(geom) FROM org.hibernate.spatial.integration.%s.GeomEntity where srid(geom) = %d", + pckg, expectationsFactory.getTestSrid() ); + retrieveHQLResultsAndCompare( dbexpected, hql, pckg ); + } + + private String getGeometryTypeFromPackage(String pckg) { + switch ( pckg ) { + case GEOLATTE: + return org.geolatte.geom.Geometry.class.getName(); + case JTS: + return Geometry.class.getName(); + default: + throw new IllegalArgumentException( "Invalid package: " + pckg ); + } + } + + private Map createQueryParams(String filterParamName, Object value) { + Map params = new HashMap(); + params.put( filterParamName, value ); + return params; + } +} diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestSpatialRestrictions.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestSpatialRestrictions.java index 5f9a0ee8c5..98a4bb1ad7 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestSpatialRestrictions.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/integration/TestSpatialRestrictions.java @@ -18,11 +18,13 @@ import org.hibernate.criterion.Criterion; import org.hibernate.spatial.HSMessageLogger; import org.hibernate.spatial.SpatialFunction; import org.hibernate.spatial.criterion.SpatialRestrictions; +import org.hibernate.spatial.dialect.hana.HANASpatialDialect; import org.hibernate.spatial.integration.jts.GeomEntity; import org.hibernate.spatial.testing.SpatialDialectMatcher; import org.hibernate.spatial.testing.SpatialFunctionalTestCase; import org.hibernate.testing.Skip; +import org.hibernate.testing.SkipForDialect; import org.junit.Test; import org.jboss.logging.Logger; @@ -31,6 +33,7 @@ import static junit.framework.Assert.assertEquals; import static org.junit.Assert.fail; @Skip(condition = SpatialDialectMatcher.class, message = "No Spatial Dialect") +@SkipForDialect(value = HANASpatialDialect.class, comment = "The HANA dialect is tested via org.hibernate.spatial.dialect.hana.TestHANASpatialFunctions", jiraKey = "HHH-12426") public class TestSpatialRestrictions extends SpatialFunctionalTestCase { private static HSMessageLogger LOG = Logger.getMessageLogger( diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/AbstractExpectationsFactory.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/AbstractExpectationsFactory.java index abc6cec823..73d6fc0c97 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/AbstractExpectationsFactory.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/AbstractExpectationsFactory.java @@ -794,14 +794,22 @@ public abstract class AbstractExpectationsFactory { expected.put( id, (T) results.getString( 2 ) ); break; case INTEGER: - expected.put( id, (T) Long.valueOf( results.getLong( 2 ) ) ); - break; - case DOUBLE: - Double value = Double.valueOf( results.getDouble( 2 ) ); - if ( results.wasNull() ) { - value = null; //this is required because SQL Server converts automatically null to 0.0 + { + Long value = Long.valueOf( results.getLong( 2 ) ); + if ( results.wasNull() ) { + value = null; // This is required because the Hibernate BasicExtractor also checks ResultSet#wasNull which can lead to a mismatch between the expected and the actual results + } + expected.put( id, (T) value ); + } + break; + case DOUBLE: + { + Double value = Double.valueOf( results.getDouble( 2 ) ); + if ( results.wasNull() ) { + value = null; //this is required because SQL Server converts automatically null to 0.0 + } + expected.put( id, (T) value ); } - expected.put( id, (T) value ); break; case BOOLEAN: expected.put( id, (T) Boolean.valueOf( results.getBoolean( 2 ) ) ); diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/hana/HANAExpectationsFactory.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/hana/HANAExpectationsFactory.java index 690f14d329..4601a5a7e3 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/hana/HANAExpectationsFactory.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/hana/HANAExpectationsFactory.java @@ -17,6 +17,10 @@ import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.geom.Polygon; import com.vividsolutions.jts.io.ParseException; import com.vividsolutions.jts.io.WKTReader; + +import java.sql.SQLException; +import java.util.Map; + import org.geolatte.geom.jts.JTS; public class HANAExpectationsFactory extends AbstractExpectationsFactory { @@ -34,48 +38,46 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory { protected NativeSQLStatement createNativeBufferStatement(Double distance) { return createNativeSQLStatement( "select t.id, t.geom.ST_Buffer(?) from GeomTest t where t.geom.ST_SRID() = " + getTestSrid(), - new Object[] { distance } - ); + new Object[]{ distance } ); } @Override protected NativeSQLStatement createNativeConvexHullStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( - "select t.id, t.geom.ST_Union(ST_GeomFromText(?, " + getTestSrid() + ")).ST_ConvexHull().ST_AsEWKB() from GeomTest t where t.geom.ST_SRID() = " + getTestSrid(), - geom.toText() - ); + "select t.id, t.geom.ST_Union(ST_GeomFromText(?, " + getTestSrid() + ")).ST_ConvexHull().ST_AsEWKB() from GeomTest t where t.geom.ST_SRID() = " + + getTestSrid(), + geom.toText() ); } @Override protected NativeSQLStatement createNativeIntersectionStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( - "select t.id, t.geom.ST_Intersection(ST_GeomFromText(?, " + getTestSrid() + ")).ST_AsEWKB() from GeomTest t where t.geom.ST_SRID() = " + getTestSrid(), - geom.toText() - ); + "select t.id, t.geom.ST_Intersection(ST_GeomFromText(?, " + getTestSrid() + ")).ST_AsEWKB() from GeomTest t where t.geom.ST_SRID() = " + + getTestSrid(), + geom.toText() ); } @Override protected NativeSQLStatement createNativeDifferenceStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( - "select t.id, t.geom.ST_Difference(ST_GeomFromText(?, " + getTestSrid() + ")).ST_AsEWKB() from GeomTest t where t.geom.ST_SRID() = " + getTestSrid(), - geom.toText() - ); + "select t.id, t.geom.ST_Difference(ST_GeomFromText(?, " + getTestSrid() + ")).ST_AsEWKB() from GeomTest t where t.geom.ST_SRID() = " + + getTestSrid(), + geom.toText() ); } @Override protected NativeSQLStatement createNativeSymDifferenceStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( - "select t.id, t.geom.ST_SymDifference(ST_GeomFromText(?, " + getTestSrid() + ")).ST_AsEWKB() from GeomTest t where t.geom.ST_SRID() = " + getTestSrid(), - geom.toText() - ); + "select t.id, t.geom.ST_SymDifference(ST_GeomFromText(?, " + getTestSrid() + ")).ST_AsEWKB() from GeomTest t where t.geom.ST_SRID() = " + + getTestSrid(), + geom.toText() ); } @Override protected NativeSQLStatement createNativeGeomUnionStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( "select t.id, t.geom.ST_Union(ST_GeomFromText(?, " + getTestSrid() + ")).ST_AsEWKB() from GeomTest t where t.geom.ST_SRID() = " + getTestSrid(), - geom.toText() - ); + geom.toText() ); } @Override @@ -134,41 +136,41 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory { @Override protected NativeSQLStatement createNativeWithinStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( - "select t.id, t.geom.ST_Within(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_Within(ST_GeomFromText(?, " + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), - geom.toText() - ); + "select t.id, t.geom.ST_Within(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_Within(ST_GeomFromText(?, " + + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), + geom.toText() ); } @Override protected NativeSQLStatement createNativeEqualsStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( - "select t.id, t.geom.ST_Equals(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_Equals(ST_GeomFromText(?, " + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), - geom.toText() - ); + "select t.id, t.geom.ST_Equals(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_Equals(ST_GeomFromText(?, " + + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), + geom.toText() ); } @Override protected NativeSQLStatement createNativeCrossesStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( - "select t.id, t.geom.ST_Crosses(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_Crosses(ST_GeomFromText(?, " + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), - geom.toText() - ); + "select t.id, t.geom.ST_Crosses(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_Crosses(ST_GeomFromText(?, " + + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), + geom.toText() ); } @Override protected NativeSQLStatement createNativeContainsStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( - "select t.id, t.geom.ST_Contains(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_Contains(ST_GeomFromText(?, " + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), - geom.toText() - ); + "select t.id, t.geom.ST_Contains(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_Contains(ST_GeomFromText(?, " + + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), + geom.toText() ); } @Override protected NativeSQLStatement createNativeDisjointStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( - "select t.id, t.geom.ST_Disjoint(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_Disjoint(ST_GeomFromText(?, " + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), - geom.toText() - ); + "select t.id, t.geom.ST_Disjoint(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_Disjoint(ST_GeomFromText(?, " + + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), + geom.toText() ); } @Override @@ -185,33 +187,34 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory { @Override protected NativeSQLStatement createNativeIntersectsStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( - "select t.id, t.geom.ST_Intersects(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_Intersects(ST_GeomFromText(?, " + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), - geom.toText() - ); + "select t.id, t.geom.ST_Intersects(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_Intersects(ST_GeomFromText(?, " + + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), + geom.toText() ); } @Override protected NativeSQLStatement createNativeFilterStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( - "select t.id, t.geom.ST_IntersectsFilter(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_IntersectsFilter(ST_GeomFromText(?, " + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), - geom.toText() - ); + "select t.id, t.geom.ST_IntersectsFilter(ST_GeomFromText(?, " + getTestSrid() + + ")) from GeomTest t where t.geom.ST_IntersectsFilter(ST_GeomFromText(?, " + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + + getTestSrid(), + geom.toText() ); } @Override protected NativeSQLStatement createNativeTouchesStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( - "select t.id, t.geom.ST_Touches(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_Touches(ST_GeomFromText(?, " + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), - geom.toText() - ); + "select t.id, t.geom.ST_Touches(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_Touches(ST_GeomFromText(?, " + + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), + geom.toText() ); } @Override protected NativeSQLStatement createNativeOverlapsStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( - "select t.id, t.geom.ST_Overlaps(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_Overlaps(ST_GeomFromText(?, " + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), - geom.toText() - ); + "select t.id, t.geom.ST_Overlaps(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_Overlaps(ST_GeomFromText(?, " + + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), + geom.toText() ); } @Override @@ -228,16 +231,14 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory { "select t.id, t.geom.ST_WithinDistance(ST_GeomFromText(?, " + getTestSrid() + "), " + distance + ") from GeomTest t where t.geom.ST_WithinDistance(ST_GeomFromText(?, " + getTestSrid() + "), " + distance + ") = 1 and t.geom.ST_SRID() = " + getTestSrid(), - geom.toText() - ); + geom.toText() ); } @Override protected NativeSQLStatement createNativeDistanceStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( "select t.id, t.geom.ST_Distance(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_SRID() = " + getTestSrid(), - geom.toText() - ); + geom.toText() ); } @Override @@ -258,4 +259,842 @@ public class HANAExpectationsFactory extends AbstractExpectationsFactory { return 0; } + /** + * Returns the expected alpha shapes of all testsuite-suite geometries. + * + * @return map of identifier, alpha shape + * @throws SQLException + */ + public Map getAlphaShape(double radius) throws SQLException { + return retrieveExpected( createNativeAlphaShapeStatement( radius ), GEOMETRY ); + } + + private NativeSQLStatement createNativeAlphaShapeStatement(double radius) { + return createNativeSQLStatement( + "select t.id, t.geom.ST_AlphaShape(?).ST_AsEWKB() from GeomTest t where t.geom.ST_GeometryType() in ('ST_Point', 'ST_MultiPoint')", + new Object[]{ radius } ); + } + + /** + * Returns the expected area of all testsuite-suite geometries. + * + * @return map of identifier, area + * @throws SQLException + */ + public Map getArea() throws SQLException { + return retrieveExpected( createNativeAreaStatement(), DOUBLE ); + } + + private NativeSQLStatement createNativeAreaStatement() { + return createNativeSQLStatement( "select t.id, t.geom.ST_Area() from GeomTest t where t.geom.ST_GeometryType() in ('ST_Polygon', 'ST_MultiPolygon')" ); + } + + /** + * Returns the expected EWKB representation of all testsuite-suite geometries. + * + * @return map of identifier, EWKB + * @throws SQLException + */ + public Map getAsEWKB() throws SQLException { + return retrieveExpected( createNativeAsEWKBStatement(), OBJECT ); + } + + private NativeSQLStatement createNativeAsEWKBStatement() { + return createNativeSQLStatement( "select t.id, t.geom.ST_AsEWKB() from GeomTest t" ); + } + + /** + * Returns the expected EWKT representation of all testsuite-suite geometries. + * + * @return map of identifier, EWKT + * @throws SQLException + */ + public Map getAsEWKT() throws SQLException { + return retrieveExpected( createNativeAsEWKTStatement(), STRING ); + } + + private NativeSQLStatement createNativeAsEWKTStatement() { + return createNativeSQLStatement( "select t.id, t.geom.ST_AsEWKT() from GeomTest t" ); + } + + /** + * Returns the expected GeoJSON representation of all testsuite-suite geometries. + * + * @return map of identifier, GeoJSON + * @throws SQLException + */ + public Map getAsGeoJSON() throws SQLException { + return retrieveExpected( createNativeAsGeoJSONStatement(), STRING ); + } + + private NativeSQLStatement createNativeAsGeoJSONStatement() { + return createNativeSQLStatement( "select t.id, t.geom.ST_AsGeoJSON() from GeomTest t" ); + } + + /** + * Returns the expected SVG representation of all testsuite-suite geometries. + * + * @return map of identifier, SVG + * @throws SQLException + */ + public Map getAsSVG() throws SQLException { + return retrieveExpected( createNativeAsSVGStatement(), STRING ); + } + + private NativeSQLStatement createNativeAsSVGStatement() { + return createNativeSQLStatement( "select t.id, t.geom.ST_AsSVG() from GeomTest t" ); + } + + /** + * Returns the expected aggregated SVG representation of all testsuite-suite geometries. + * + * @return map of count, SVG + * @throws SQLException + */ + public Map getAsSVGAggr() throws SQLException { + return retrieveExpected( createNativeAsSVGAggrStatement(), STRING ); + } + + private NativeSQLStatement createNativeAsSVGAggrStatement() { + return createNativeSQLStatement( "select cast(count(*) as int), ST_AsSVGAggr(t.geom) from GeomTest t" ); + } + + /** + * Returns the expected WKB representation of all testsuite-suite geometries. + * + * @return map of identifier, WKB + * @throws SQLException + */ + public Map getAsWKB() throws SQLException { + return retrieveExpected( createNativeAsWKBStatement(), OBJECT ); + } + + private NativeSQLStatement createNativeAsWKBStatement() { + return createNativeSQLStatement( "select t.id, t.geom.ST_AsWKB() from GeomTest t" ); + } + + /** + * Returns the expected WKT representation of all testsuite-suite geometries. + * + * @return map of identifier, WKT + * @throws SQLException + */ + public Map getAsWKT() throws SQLException { + return retrieveExpected( createNativeAsWKTStatement(), STRING ); + } + + private NativeSQLStatement createNativeAsWKTStatement() { + return createNativeSQLStatement( "select t.id, t.geom.ST_AsWKT() from GeomTest t" ); + } + + /** + * Returns the expected centroid of all testsuite-suite geometries. + * + * @return map of id, centroid + * @throws SQLException + */ + public Map getCentroid() throws SQLException { + return retrieveExpected( createNativeCentroidStatement(), GEOMETRY ); + } + + private NativeSQLStatement createNativeCentroidStatement() { + return createNativeSQLStatement( "select id, t.geom.ST_Centroid() from GeomTest t where t.geom.ST_GeometryType() = 'ST_Polygon'" ); + } + + /** + * Returns the expected aggregated convex hull representation of all testsuite-suite geometries. + * + * @return map of count, convex hull + * @throws SQLException + */ + public Map getConvexHullAggr() throws SQLException { + return retrieveExpected( createNativeConvexHullAggrStatement(), GEOMETRY ); + } + + private NativeSQLStatement createNativeConvexHullAggrStatement() { + return createNativeSQLStatement( "select cast(count(*) as int), ST_ConvexHullAggr(t.geom) from GeomTest t" ); + } + + /** + * Returns the expected number of coordinate dimensions of all testsuite-suite geometries. + * + * @return map of identifier, coordinate dimension + * @throws SQLException + */ + public Map getCoordDim() throws SQLException { + return retrieveExpected( createNativeCoordDimStatement(), INTEGER ); + } + + private NativeSQLStatement createNativeCoordDimStatement() { + return createNativeSQLStatement( "select t.id, t.geom.ST_CoordDim() from GeomTest t" ); + } + + /** + * Returns the testsuite-suite geometries that are covered by the given geometry. + * + * @return map of identifier, whether the geometry is covered + * @throws SQLException + */ + public Map getCoveredBy(Geometry geom) throws SQLException { + return retrieveExpected( createNativeCoveredByStatement( geom ), BOOLEAN ); + } + + private NativeSQLStatement createNativeCoveredByStatement(Geometry geom) { + return createNativeSQLStatementAllWKTParams( + "select t.id, t.geom.ST_CoveredBy(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_CoveredBy(ST_GeomFromText(?, " + + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), + geom.toText() ); + } + + /** + * Returns the testsuite-suite geometries that are cover the given geometry. + * + * @return map of identifier, whether the geometry covers the given geometry + * @throws SQLException + */ + public Map getCovers(Geometry geom) throws SQLException { + return retrieveExpected( createNativeCoversStatement( geom ), BOOLEAN ); + } + + private NativeSQLStatement createNativeCoversStatement(Geometry geom) { + return createNativeSQLStatementAllWKTParams( + "select t.id, t.geom.ST_Covers(ST_GeomFromText(?, " + getTestSrid() + ")) from GeomTest t where t.geom.ST_Covers(ST_GeomFromText(?, " + + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), + geom.toText() ); + } + + /** + * Returns the expected endpoint of all testsuite-suite geometries. + * + * @return map of id, endpoint + * @throws SQLException + */ + public Map getEndPoint() throws SQLException { + return retrieveExpected( createNativeEndPointStatement(), GEOMETRY ); + } + + private NativeSQLStatement createNativeEndPointStatement() { + return createNativeSQLStatement( "select id, t.geom.ST_EndPoint() from GeomTest t where t.geom.ST_GeometryType() = 'ST_LineString'" ); + } + + /** + * Returns the expected aggregated bounding rectangle of all testsuite-suite geometries. + * + * @return map of count, bounding rectangle + * @throws SQLException + */ + public Map getEnvelopeAggr() throws SQLException { + return retrieveExpected( createNativeEnvelopeAggrStatement(), GEOMETRY ); + } + + private NativeSQLStatement createNativeEnvelopeAggrStatement() { + return createNativeSQLStatement( "select cast(count(*) as int), ST_EnvelopeAggr(t.geom) from GeomTest t" ); + } + + /** + * Returns the expected exterior ring of all testsuite-suite geometries. + * + * @return map of id, exterior ring + * @throws SQLException + */ + public Map getExteriorRing() throws SQLException { + return retrieveExpected( createNativeExteriorRingStatement(), GEOMETRY ); + } + + private NativeSQLStatement createNativeExteriorRingStatement() { + return createNativeSQLStatement( "select id, t.geom.ST_ExteriorRing() from GeomTest t where t.geom.ST_GeometryType() = 'ST_Polygon'" ); + } + + /** + * Returns the geometry from an EWKB representation. + * + * @return map of id, geometry + * @throws SQLException + */ + public Map getGeomFromEWKB(byte[] ewkb) throws SQLException { + return retrieveExpected( createNativeGeomFromEWKBStatement( ewkb ), GEOMETRY ); + } + + private NativeSQLStatement createNativeGeomFromEWKBStatement(byte[] ewkb) { + return createNativeSQLStatement( "select 1, ST_GeomFromEWKB(?) from GeomTest t", new Object[]{ ewkb } ); + } + + /** + * Returns the geometry from an EWKT representation. + * + * @return map of id, geometry + * @throws SQLException + */ + public Map getGeomFromEWKT(String ewkt) throws SQLException { + return retrieveExpected( createNativeGeomFromEWKTStatement( ewkt ), GEOMETRY ); + } + + private NativeSQLStatement createNativeGeomFromEWKTStatement(String ewkt) { + return createNativeSQLStatement( "select 1, ST_GeomFromEWKT(?) from GeomTest t", new Object[]{ ewkt } ); + } + + /** + * Returns the geometry from a text representation. + * + * @return map of id, geometry + * @throws SQLException + */ + public Map getGeomFromText(String text) throws SQLException { + return retrieveExpected( createNativeGeomFromTextStatement( text ), GEOMETRY ); + } + + private NativeSQLStatement createNativeGeomFromTextStatement(String text) { + return createNativeSQLStatement( "select 1, ST_GeomFromText(?) from GeomTest t", new Object[]{ text } ); + } + + /** + * Returns the geometry from a WKB representation. + * + * @return map of id, geometry + * @throws SQLException + */ + public Map getGeomFromWKB(byte[] wkb) throws SQLException { + return retrieveExpected( createNativeGeomFromWKBStatement( wkb ), GEOMETRY ); + } + + private NativeSQLStatement createNativeGeomFromWKBStatement(byte[] wkb) { + return createNativeSQLStatement( "select 1, ST_GeomFromWKB(?) from GeomTest t", new Object[]{ wkb } ); + } + + /** + * Returns the geometry from a WKT representation. + * + * @return map of id, geometry + * @throws SQLException + */ + public Map getGeomFromWKT(String wkt) throws SQLException { + return retrieveExpected( createNativeGeomFromWKTStatement( wkt ), GEOMETRY ); + } + + private NativeSQLStatement createNativeGeomFromWKTStatement(String wkt) { + return createNativeSQLStatement( "select 1, ST_GeomFromWKT(?) from GeomTest t", new Object[]{ wkt } ); + } + + /** + * Returns the expected nth geometry of all testsuite-suite geometries. + * + * @return map of id, geometry + * @throws SQLException + */ + public Map getGeometryN(int n) throws SQLException { + return retrieveExpected( createNativeGeometryNStatement( n ), GEOMETRY ); + } + + private NativeSQLStatement createNativeGeometryNStatement(int n) { + return createNativeSQLStatement( "select id, t.geom.ST_GeometryN(?) from GeomTest t where t.geom.ST_GeometryType() = 'ST_GeometryCollection'", + new Object[]{ n } ); + } + + /** + * Returns the expected nth interior ring of all testsuite-suite geometries. + * + * @return map of id, interior ring + * @throws SQLException + */ + public Map getInteriorRingN(int n) throws SQLException { + return retrieveExpected( createNativeInteriorRingNStatement( n ), GEOMETRY ); + } + + private NativeSQLStatement createNativeInteriorRingNStatement(int n) { + return createNativeSQLStatement( "select id, t.geom.ST_InteriorRingN(?) from GeomTest t where t.geom.ST_GeometryType() = 'ST_Polygon'", + new Object[]{ n } ); + } + + /** + * Returns the expected aggregated intersection of all testsuite-suite geometries. + * + * @return map of count, intersection + * @throws SQLException + */ + public Map getIntersectionAggr() throws SQLException { + return retrieveExpected( createNativeIntersectionAggrStatement(), GEOMETRY ); + } + + private NativeSQLStatement createNativeIntersectionAggrStatement() { + return createNativeSQLStatement( "select cast(count(*) as int), ST_IntersectionAggr(t.geom) from GeomTest t" ); + } + + /** + * Returns the testsuite-suite geometries that intersect the given rectangle. + * + * @return map of identifier, whether the geometry intersects the given rectangle + * @throws SQLException + */ + public Map getIntersectsRect(Point pmin, Point pmax) throws SQLException { + return retrieveExpected( createNativeIntersectsRectStatement( pmin, pmax ), BOOLEAN ); + } + + private NativeSQLStatement createNativeIntersectsRectStatement(Point pmin, Point pmax) { + return createNativeSQLStatement( + "select t.id, t.geom.ST_IntersectsRect(ST_GeomFromText(?, " + getTestSrid() + "), ST_GeomFromText(?, " + getTestSrid() + + ")) from GeomTest t where t.geom.ST_IntersectsRect(ST_GeomFromText(?, " + + getTestSrid() + "), ST_GeomFromText(?, " + getTestSrid() + ")) = 1 and t.geom.ST_SRID() = " + getTestSrid(), + new Object[]{ pmin.toText(), pmax.toText(), pmin.toText(), pmax.toText() } ); + } + + /** + * Returns the testsuite-suite geometries that are 3D geometries. + * + * @return map of identifier, whether the geometry is 3D + * @throws SQLException + */ + public Map getIs3D() throws SQLException { + return retrieveExpected( createNativeIs3DStatement(), BOOLEAN ); + } + + private NativeSQLStatement createNativeIs3DStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_Is3D() from GeomTest t where t.geom.ST_Is3D() = 1 and t.geom.ST_SRID() = " + getTestSrid() ); + } + + /** + * Returns the testsuite-suite geometries that are closed. + * + * @return map of identifier, whether the geometry is closed + * @throws SQLException + */ + public Map getIsClosed() throws SQLException { + return retrieveExpected( createNativeIsClosedStatement(), BOOLEAN ); + } + + private NativeSQLStatement createNativeIsClosedStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_IsClosed() from GeomTest t where t.geom.ST_GeometryType() in ('ST_LineString', 'ST_MultiLineString') and t.geom.ST_IsClosed() = 1 and t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the testsuite-suite geometries that are measured. + * + * @return map of identifier, whether the geometry is measured + * @throws SQLException + */ + public Map getIsMeasured() throws SQLException { + return retrieveExpected( createNativeIsMeasuredStatement(), BOOLEAN ); + } + + private NativeSQLStatement createNativeIsMeasuredStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_IsMeasured() from GeomTest t where t.geom.ST_IsMeasured() = 1 and t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the testsuite-suite geometries that are rings. + * + * @return map of identifier, whether the geometry is a ring + * @throws SQLException + */ + public Map getIsRing() throws SQLException { + return retrieveExpected( createNativeIsRingStatement(), BOOLEAN ); + } + + private NativeSQLStatement createNativeIsRingStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_IsRing() from GeomTest t where t.geom.ST_GeometryType() in ('ST_LineString') and t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the testsuite-suite geometries that are valid. + * + * @return map of identifier, whether the geometry is valid + * @throws SQLException + */ + public Map getIsValid() throws SQLException { + return retrieveExpected( createNativeIsValidStatement(), BOOLEAN ); + } + + private NativeSQLStatement createNativeIsValidStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_IsValid() from GeomTest t where t.geom.ST_IsValid() = 1 and t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the length of all testsuite-suite geometries. + * + * @return map of identifier, length + * @throws SQLException + */ + public Map getLength() throws SQLException { + return retrieveExpected( createNativeLengthStatement(), DOUBLE ); + } + + private NativeSQLStatement createNativeLengthStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_Length() from GeomTest t where t.geom.ST_GeometryType() in ('ST_LineString', 'ST_MultiLineString') and t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the measure value of all testsuite-suite geometries. + * + * @return map of identifier, measure value + * @throws SQLException + */ + public Map getM() throws SQLException { + return retrieveExpected( createNativeMStatement(), DOUBLE ); + } + + private NativeSQLStatement createNativeMStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_M() from GeomTest t where t.geom.ST_GeometryType() in ('ST_Point') and t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the maximum measure value of all testsuite-suite geometries. + * + * @return map of identifier, maximum measure value + * @throws SQLException + */ + public Map getMMax() throws SQLException { + return retrieveExpected( createNativeMMaxStatement(), DOUBLE ); + } + + private NativeSQLStatement createNativeMMaxStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_MMax() from GeomTest t where t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the minimum measure value of all testsuite-suite geometries. + * + * @return map of identifier, minimum measure value + * @throws SQLException + */ + public Map getMMin() throws SQLException { + return retrieveExpected( createNativeMMinStatement(), DOUBLE ); + } + + private NativeSQLStatement createNativeMMinStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_MMin() from GeomTest t where t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the number of geometries of all testsuite-suite geometries. + * + * @return map of identifier, number of geometries + * @throws SQLException + */ + public Map getNumGeometries() throws SQLException { + return retrieveExpected( createNativeNumGeometriesStatement(), INTEGER ); + } + + private NativeSQLStatement createNativeNumGeometriesStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_NumGeometries() from GeomTest t where (t.geom.ST_GeometryType() in ('ST_GeometryCollection')) and t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the number of interior rings of all testsuite-suite geometries. + * + * @return map of identifier, number of interior rings + * @throws SQLException + */ + public Map getNumInteriorRing() throws SQLException { + return retrieveExpected( createNativeNumInteriorRingStatement(), INTEGER ); + } + + private NativeSQLStatement createNativeNumInteriorRingStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_NumInteriorRing() from GeomTest t where t.geom.ST_GeometryType() in ('ST_Polygon') and t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the number of interior rings of all testsuite-suite geometries. + * + * @return map of identifier, number of interior rings + * @throws SQLException + */ + public Map getNumInteriorRings() throws SQLException { + return retrieveExpected( createNativeNumInteriorRingsStatement(), INTEGER ); + } + + private NativeSQLStatement createNativeNumInteriorRingsStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_NumInteriorRings() from GeomTest t where t.geom.ST_GeometryType() in ('ST_Polygon') and t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the number of points of all testsuite-suite geometries. + * + * @return map of identifier, number of points + * @throws SQLException + */ + public Map getNumPoints() throws SQLException { + return retrieveExpected( createNativeNumPointsStatement(), INTEGER ); + } + + private NativeSQLStatement createNativeNumPointsStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_NumPoints() from GeomTest t where t.geom.ST_GeometryType() in ('ST_LineString') and t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the testsuite-suite geometries that are equal. + * + * @return map of identifier, whether the geometry is equal + * @throws SQLException + */ + public Map getOrderingEquals(Geometry geom) throws SQLException { + return retrieveExpected( createNativeOrderingEqualsStatement( geom ), BOOLEAN ); + } + + private NativeSQLStatement createNativeOrderingEqualsStatement(Geometry geom) { + return createNativeSQLStatementAllWKTParams( + "select t.id, t.geom.ST_OrderingEquals(ST_GeomFromText(?)) from GeomTest t where t.geom.ST_OrderingEquals(ST_GeomFromText(?)) = 1 and t.geom.ST_SRID() = " + + getTestSrid(), + geom.toText() ); + } + + /** + * Returns the perimeter of all testsuite-suite geometries. + * + * @return map of identifier, perimeter + * @throws SQLException + */ + public Map getPerimeter() throws SQLException { + return retrieveExpected( createNativePerimeterStatement(), DOUBLE ); + } + + private NativeSQLStatement createNativePerimeterStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_Perimeter() from GeomTest t where t.geom.ST_GeometryType() in ('ST_Polygon', 'ST_MultiPolygon') and t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns a point on the surface of all testsuite-suite geometries. + * + * @return map of identifier, point on surface + * @throws SQLException + */ + public Map getPointOnSurface() throws SQLException { + return retrieveExpected( createNativePointOnSurfaceStatement(), GEOMETRY ); + } + + private NativeSQLStatement createNativePointOnSurfaceStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_PointOnSurface() from GeomTest t where t.geom.ST_GeometryType() in ('ST_Polygon', 'ST_MultiPolygon') and t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the nth point of all testsuite-suite geometries. + * + * @return map of identifier, point + * @throws SQLException + */ + public Map getPointN(int n) throws SQLException { + return retrieveExpected( createNativePointNStatement( n ), GEOMETRY ); + } + + private NativeSQLStatement createNativePointNStatement(int n) { + return createNativeSQLStatement( + "select t.id, t.geom.ST_PointN(?) from GeomTest t where t.geom.ST_GeometryType() in ('ST_LineString') and t.geom.ST_SRID() = " + + getTestSrid(), + new Object[]{ n } ); + } + + /** + * Returns a copy of all testsuite-suite geometries with all points snapped to the grid. + * + * @return map of identifier, geometry + * @throws SQLException + */ + public Map getSnapToGrid() throws SQLException { + return retrieveExpected( createNativeSnapToGridStatement(), GEOMETRY ); + } + + private NativeSQLStatement createNativeSnapToGridStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_SnapToGrid() from GeomTest t where t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the expected startpoint of all testsuite-suite geometries. + * + * @return map of id, startpoint + * @throws SQLException + */ + public Map getStartPoint() throws SQLException { + return retrieveExpected( createNativeStartPointStatement(), GEOMETRY ); + } + + private NativeSQLStatement createNativeStartPointStatement() { + return createNativeSQLStatement( "select id, t.geom.ST_StartPoint() from GeomTest t where t.geom.ST_GeometryType() = 'ST_LineString'" ); + } + + /** + * Returns the expected aggregated union of all testsuite-suite geometries. + * + * @return map of count, union + * @throws SQLException + */ + public Map getUnionAggr() throws SQLException { + return retrieveExpected( createNativeUnionAggrStatement(), GEOMETRY ); + } + + private NativeSQLStatement createNativeUnionAggrStatement() { + return createNativeSQLStatement( "select cast(count(*) as int), ST_UnionAggr(t.geom) from GeomTest t" ); + } + + /** + * Returns the x coordinate of all testsuite-suite geometries. + * + * @return map of identifier, x coordinate + * @throws SQLException + */ + public Map getX() throws SQLException { + return retrieveExpected( createNativeXStatement(), DOUBLE ); + } + + private NativeSQLStatement createNativeXStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_X() from GeomTest t where t.geom.ST_GeometryType() in ('ST_Point') and t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the maximum x coordinate of all testsuite-suite geometries. + * + * @return map of identifier, maximum x coordinate + * @throws SQLException + */ + public Map getXMax() throws SQLException { + return retrieveExpected( createNativeXMaxStatement(), DOUBLE ); + } + + private NativeSQLStatement createNativeXMaxStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_XMax() from GeomTest t where t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the minimum x coordinate of all testsuite-suite geometries. + * + * @return map of identifier, minumum x coordinate + * @throws SQLException + */ + public Map getXMin() throws SQLException { + return retrieveExpected( createNativeXMinStatement(), DOUBLE ); + } + + private NativeSQLStatement createNativeXMinStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_XMin() from GeomTest t where t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the y coordinate of all testsuite-suite geometries. + * + * @return map of identifier, y coordinate + * @throws SQLException + */ + public Map getY() throws SQLException { + return retrieveExpected( createNativeYStatement(), DOUBLE ); + } + + private NativeSQLStatement createNativeYStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_Y() from GeomTest t where t.geom.ST_GeometryType() in ('ST_Point') and t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the maximum y coordinate of all testsuite-suite geometries. + * + * @return map of identifier, maximum y coordinate + * @throws SQLException + */ + public Map getYMax() throws SQLException { + return retrieveExpected( createNativeYMaxStatement(), DOUBLE ); + } + + private NativeSQLStatement createNativeYMaxStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_YMax() from GeomTest t where t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the minimum y coordinate of all testsuite-suite geometries. + * + * @return map of identifier, minumum y coordinate + * @throws SQLException + */ + public Map getYMin() throws SQLException { + return retrieveExpected( createNativeYMinStatement(), DOUBLE ); + } + + private NativeSQLStatement createNativeYMinStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_YMin() from GeomTest t where t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the z coordinate of all testsuite-suite geometries. + * + * @return map of identifier, z coordinate + * @throws SQLException + */ + public Map getZ() throws SQLException { + return retrieveExpected( createNativeZStatement(), DOUBLE ); + } + + private NativeSQLStatement createNativeZStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_Z() from GeomTest t where t.geom.ST_GeometryType() in ('ST_Point') and t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the maximum z coordinate of all testsuite-suite geometries. + * + * @return map of identifier, maximum z coordinate + * @throws SQLException + */ + public Map getZMax() throws SQLException { + return retrieveExpected( createNativeZMaxStatement(), DOUBLE ); + } + + private NativeSQLStatement createNativeZMaxStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_ZMax() from GeomTest t where t.geom.ST_SRID() = " + + getTestSrid() ); + } + + /** + * Returns the minimum z coordinate of all testsuite-suite geometries. + * + * @return map of identifier, minumum z coordinate + * @throws SQLException + */ + public Map getZMin() throws SQLException { + return retrieveExpected( createNativeZMinStatement(), DOUBLE ); + } + + private NativeSQLStatement createNativeZMinStatement() { + return createNativeSQLStatement( + "select t.id, t.geom.ST_ZMin() from GeomTest t where t.geom.ST_SRID() = " + + getTestSrid() ); + } }