From e9dd160d7f7254cd519c06cf59b8409c5a7b4ddb Mon Sep 17 00:00:00 2001 From: Karel Maesen Date: Wed, 17 Mar 2021 21:53:53 +0100 Subject: [PATCH] HHH-14090 Add MariaDB103SpatialDialect --- gradle/databases.gradle | 7 + .../mariadb/MariaDB103SpatialDialect.java | 42 ++++ .../mariadb/MariaDB103SpatialFunctions.java | 179 ++++++++++++++++++ .../MariaDBGeometryTypeDescriptor.java | 102 ++++++++++ .../mariadb/MariaDBSpatialDialectTrait.java | 102 ++++++++++ .../spatial/testing/TestSupportFactories.java | 8 +- .../mariadb/MariaDBExpectationsFactory.java | 18 ++ .../mariadb/MariaDBExpressionTemplate.java | 16 ++ .../dialects/mariadb/MariaDBTestSupport.java | 35 ++++ .../mysql/MySQL8ExpectationsFactory.java | 7 +- .../test-mariadb-functions-data-set.xml | 135 +++++++++++++ 11 files changed, 647 insertions(+), 4 deletions(-) create mode 100644 hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mariadb/MariaDB103SpatialDialect.java create mode 100644 hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mariadb/MariaDB103SpatialFunctions.java create mode 100644 hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mariadb/MariaDBGeometryTypeDescriptor.java create mode 100644 hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mariadb/MariaDBSpatialDialectTrait.java create mode 100644 hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mariadb/MariaDBExpectationsFactory.java create mode 100644 hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mariadb/MariaDBExpressionTemplate.java create mode 100644 hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mariadb/MariaDBTestSupport.java create mode 100644 hibernate-spatial/src/test/resources/mariadb/test-mariadb-functions-data-set.xml diff --git a/gradle/databases.gradle b/gradle/databases.gradle index 8f0795dae0..8e62ba2fee 100644 --- a/gradle/databases.gradle +++ b/gradle/databases.gradle @@ -91,6 +91,13 @@ ext { 'jdbc.pass' : 'hibernate_orm_test', 'jdbc.url' : 'jdbc:mariadb://' + dbHost + '/hibernate_orm_test' ], + mariadb_spatial_ci : [ + 'db.dialect' : 'org.hibernate.spatial.dialect.mariadb.MariaDB103SpatialDialect', + 'jdbc.driver': 'org.mariadb.jdbc.Driver', + 'jdbc.user' : 'root', + 'jdbc.pass' : 'hibernate_orm_test', + 'jdbc.url' : 'jdbc:mariadb://' + dbHost + '/hibernate_orm_test' + ], postgis : [ 'db.dialect' : 'org.hibernate.spatial.dialect.postgis.PostgisPG95Dialect', 'jdbc.driver': 'org.postgresql.Driver', diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mariadb/MariaDB103SpatialDialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mariadb/MariaDB103SpatialDialect.java new file mode 100644 index 0000000000..48a98d0c93 --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mariadb/MariaDB103SpatialDialect.java @@ -0,0 +1,42 @@ +/* + * 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.mariadb; + +import java.util.Map; + +import org.hibernate.boot.model.TypeContributions; +import org.hibernate.dialect.MariaDB103Dialect; +import org.hibernate.dialect.function.SQLFunction; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.spatial.dialect.SpatialFunctionsRegistry; + +public class MariaDB103SpatialDialect extends MariaDB103Dialect implements MariaDBSpatialDialectTrait { + + final private SpatialFunctionsRegistry spatialFunctions = new MariaDB103SpatialFunctions(); + + public MariaDB103SpatialDialect() { + super(); + registerColumnType( + MariaDBGeometryTypeDescriptor.INSTANCE.getSqlType(), + "GEOMETRY" + ); + for ( Map.Entry entry : spatialFunctions ) { + registerFunction( entry.getKey(), entry.getValue() ); + } + } + + @Override + public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { + delegateContributeTypes( typeContributions, serviceRegistry ); + } + + @Override + public SpatialFunctionsRegistry spatialFunctions() { + return spatialFunctions; + } +} diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mariadb/MariaDB103SpatialFunctions.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mariadb/MariaDB103SpatialFunctions.java new file mode 100644 index 0000000000..944678fe57 --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mariadb/MariaDB103SpatialFunctions.java @@ -0,0 +1,179 @@ +/* + * 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.mariadb; + +import org.hibernate.dialect.function.StandardSQLFunction; +import org.hibernate.spatial.SpatialFunction; +import org.hibernate.spatial.dialect.SpatialFunctionsRegistry; +import org.hibernate.type.StandardBasicTypes; + +class MariaDB103SpatialFunctions extends SpatialFunctionsRegistry { + + public MariaDB103SpatialFunctions() { + functionMap.put( + "dimension", new StandardSQLFunction( + "ST_Dimension", + StandardBasicTypes.INTEGER + ) + ); + functionMap.put( + "geometrytype", new StandardSQLFunction( + "ST_GeometryType", StandardBasicTypes.STRING + ) + ); + functionMap.put( + "srid", new StandardSQLFunction( + "ST_SRID", + StandardBasicTypes.INTEGER + ) + ); + functionMap.put( + "envelope", new StandardSQLFunction( + "ST_Envelope" + ) + ); + functionMap.put( + "astext", new StandardSQLFunction( + "ST_Astext", + StandardBasicTypes.STRING + ) + ); + functionMap.put( + "asbinary", new StandardSQLFunction( + "ST_Asbinary", + StandardBasicTypes.BINARY + ) + ); + functionMap.put( + "isempty", new StandardSQLFunction( + "ST_IsEmpty", + StandardBasicTypes.BOOLEAN + ) + ); + functionMap.put( + "issimple", new StandardSQLFunction( + "ST_IsSimple", + StandardBasicTypes.BOOLEAN + ) + ); + functionMap.put( + "boundary", new StandardSQLFunction( + "ST_Boundary" + ) + ); + + // Register functions for spatial relation constructs + functionMap.put( + "overlaps", new StandardSQLFunction( + "ST_Overlaps", + StandardBasicTypes.BOOLEAN + ) + ); + functionMap.put( + "intersects", new StandardSQLFunction( + "ST_Intersects", + StandardBasicTypes.BOOLEAN + ) + ); + functionMap.put( + "equals", new StandardSQLFunction( + "ST_Equals", + StandardBasicTypes.BOOLEAN + ) + ); + functionMap.put( + "contains", new StandardSQLFunction( + "ST_Contains", + StandardBasicTypes.BOOLEAN + ) + ); + functionMap.put( + "crosses", new StandardSQLFunction( + "ST_Crosses", + StandardBasicTypes.BOOLEAN + ) + ); + functionMap.put( + "disjoint", new StandardSQLFunction( + "ST_Disjoint", + StandardBasicTypes.BOOLEAN + ) + ); + functionMap.put( + "touches", new StandardSQLFunction( + "ST_Touches", + StandardBasicTypes.BOOLEAN + ) + ); + functionMap.put( + "within", new StandardSQLFunction( + "ST_Within", + StandardBasicTypes.BOOLEAN + ) + ); + functionMap.put( + "relate", new StandardSQLFunction( + "ST_Relate", + StandardBasicTypes.BOOLEAN + ) + ); + + // register the spatial analysis functions + functionMap.put( + "distance", new StandardSQLFunction( + "ST_Distance", + StandardBasicTypes.DOUBLE + ) + ); + + functionMap.put( + "buffer", new StandardSQLFunction( + "ST_Buffer" + ) + ); + + functionMap.put( + "convexhull", new StandardSQLFunction( + "ST_ConvexHull" + ) + ); + + functionMap.put( + "difference", new StandardSQLFunction( + "ST_Difference" + ) + ); + + functionMap.put( + "intersection", new StandardSQLFunction( + "ST_Intersection" + ) + ); + + functionMap.put( + "symdifference", new StandardSQLFunction( + "ST_SymDifference" + ) + ); + + functionMap.put( + "geomunion", new StandardSQLFunction( + "ST_Union" + ) + ); + + functionMap.put( + SpatialFunction.filter.name(), new StandardSQLFunction( + "MBRIntersects", + StandardBasicTypes.BOOLEAN + ) + ); + } + +} + diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mariadb/MariaDBGeometryTypeDescriptor.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mariadb/MariaDBGeometryTypeDescriptor.java new file mode 100644 index 0000000000..929b028681 --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mariadb/MariaDBGeometryTypeDescriptor.java @@ -0,0 +1,102 @@ +/* + * 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.mariadb; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Types; + +import org.hibernate.type.descriptor.ValueBinder; +import org.hibernate.type.descriptor.ValueExtractor; +import org.hibernate.type.descriptor.WrapperOptions; +import org.hibernate.type.descriptor.java.JavaTypeDescriptor; +import org.hibernate.type.descriptor.sql.BasicBinder; +import org.hibernate.type.descriptor.sql.BasicExtractor; +import org.hibernate.type.descriptor.sql.SqlTypeDescriptor; + +import org.geolatte.geom.ByteBuffer; +import org.geolatte.geom.ByteOrder; +import org.geolatte.geom.Geometry; +import org.geolatte.geom.codec.Wkb; +import org.geolatte.geom.codec.WkbDecoder; +import org.geolatte.geom.codec.WkbEncoder; + +public class MariaDBGeometryTypeDescriptor implements SqlTypeDescriptor { + + public static final MariaDBGeometryTypeDescriptor INSTANCE = new MariaDBGeometryTypeDescriptor(); + final WkbEncoder encoder = Wkb.newEncoder( Wkb.Dialect.MYSQL_WKB ); + final WkbDecoder decoder = Wkb.newDecoder( Wkb.Dialect.MYSQL_WKB ); + + @Override + public int getSqlType() { + return Types.ARRAY; + } + + @Override + public boolean canBeRemapped() { + return false; + } + + @Override + public ValueBinder getBinder(JavaTypeDescriptor javaTypeDescriptor) { + + return new BasicBinder( javaTypeDescriptor, this ) { + @Override + protected void doBind( + PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { + final byte[] bytes = valueToByteArray( value, options ); + st.setBytes( index, bytes ); + } + + @Override + protected void doBind( + CallableStatement st, X value, String name, WrapperOptions options) throws SQLException { + final byte[] bytes = valueToByteArray( value, options ); + st.setBytes( name, bytes ); + } + + private byte[] valueToByteArray(X value, WrapperOptions options) { + final Geometry geometry = getJavaDescriptor().unwrap( value, Geometry.class, options ); + final ByteBuffer buffer = encoder.encode( geometry, ByteOrder.NDR ); + return buffer == null ? null : buffer.toByteArray(); + } + }; + } + + @Override + public ValueExtractor getExtractor(JavaTypeDescriptor javaTypeDescriptor) { + return new BasicExtractor( javaTypeDescriptor, this ) { + + @Override + protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException { + return getJavaDescriptor().wrap( toGeometry( rs.getBytes( name ) ), options ); + } + + @Override + protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException { + return getJavaDescriptor().wrap( toGeometry( statement.getBytes( index ) ), options ); + } + + @Override + protected X doExtract(CallableStatement statement, String name, WrapperOptions options) + throws SQLException { + return getJavaDescriptor().wrap( toGeometry( statement.getBytes( name ) ), options ); + } + }; + } + + private Geometry toGeometry(byte[] bytes) { + if ( bytes == null ) { + return null; + } + final ByteBuffer buffer = ByteBuffer.from( bytes ); + return decoder.decode( buffer ); + } +} diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mariadb/MariaDBSpatialDialectTrait.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mariadb/MariaDBSpatialDialectTrait.java new file mode 100644 index 0000000000..b3b853ae12 --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mariadb/MariaDBSpatialDialectTrait.java @@ -0,0 +1,102 @@ +/* + * 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.mariadb; + +import java.util.Locale; + +import org.hibernate.boot.model.TypeContributions; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.spatial.GeolatteGeometryJavaTypeDescriptor; +import org.hibernate.spatial.GeolatteGeometryType; +import org.hibernate.spatial.JTSGeometryJavaTypeDescriptor; +import org.hibernate.spatial.JTSGeometryType; +import org.hibernate.spatial.SpatialDialect; +import org.hibernate.spatial.SpatialFunction; +import org.hibernate.spatial.SpatialRelation; +import org.hibernate.spatial.dialect.SpatialFunctionsRegistry; + +public interface MariaDBSpatialDialectTrait extends SpatialDialect { + + + default void delegateContributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { + typeContributions.contributeType( new GeolatteGeometryType( MariaDBGeometryTypeDescriptor.INSTANCE ) ); + typeContributions.contributeType( new JTSGeometryType( MariaDBGeometryTypeDescriptor.INSTANCE ) ); + + typeContributions.contributeJavaTypeDescriptor( GeolatteGeometryJavaTypeDescriptor.INSTANCE ); + typeContributions.contributeJavaTypeDescriptor( JTSGeometryJavaTypeDescriptor.INSTANCE ); + } + + + SpatialFunctionsRegistry spatialFunctions(); + + @Override + default String getSpatialRelateSQL(String columnName, int spatialRelation) { + switch ( spatialRelation ) { + case SpatialRelation.WITHIN: + return " ST_within(" + columnName + ",?)"; + case SpatialRelation.CONTAINS: + return " ST_contains(" + columnName + ", ?)"; + case SpatialRelation.CROSSES: + return " ST_crosses(" + columnName + ", ?)"; + case SpatialRelation.OVERLAPS: + return " ST_overlaps(" + columnName + ", ?)"; + case SpatialRelation.DISJOINT: + return " ST_disjoint(" + columnName + ", ?)"; + case SpatialRelation.INTERSECTS: + return " ST_intersects(" + columnName + + ", ?)"; + case SpatialRelation.TOUCHES: + return " ST_touches(" + columnName + ", ?)"; + case SpatialRelation.EQUALS: + return " ST_equals(" + columnName + ", ?)"; + default: + throw new IllegalArgumentException( + "Spatial relation is not known by this dialect" + ); + } + } + + @Override + default String getSpatialFilterExpression(String columnName) { + return String.format( Locale.ENGLISH, "MBRIntersects(%s,?)", columnName + ); + } + + @Override + default String getSpatialAggregateSQL(String columnName, int aggregation) { + throw new UnsupportedOperationException( "MariaDB has no spatial aggregate functions." ); + } + + @Override + default String getDWithinSQL(String columnName) { + throw new UnsupportedOperationException( "MariaDB doesn't support the DWithin function." ); + } + + @Override + default String getHavingSridSQL(String columnName) { + return " (ST_SRID(" + columnName + ") = ?) "; + } + + @Override + default String getIsEmptySQL(String columnName, boolean isEmpty) { + final String emptyExpr = " ST_IsEmpty(" + columnName + ") "; + return isEmpty ? emptyExpr : "( NOT " + emptyExpr + ")"; + } + + @Override + default boolean supportsFiltering() { + return true; + } + + @Override + default boolean supports(SpatialFunction function) { + return spatialFunctions().get( function.toString() ) != null; + } + +} + diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/TestSupportFactories.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/TestSupportFactories.java index d71e78b4f2..e296c64540 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/TestSupportFactories.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/TestSupportFactories.java @@ -9,12 +9,14 @@ package org.hibernate.spatial.testing; import org.hibernate.dialect.CockroachDB192Dialect; import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.MariaDBDialect; import org.hibernate.dialect.PostgreSQL82Dialect; import org.hibernate.spatial.SpatialDialect; import org.hibernate.spatial.testing.dialects.cockroachdb.CockroachDBTestSupport; import org.hibernate.spatial.testing.dialects.db2.DB2TestSupport; import org.hibernate.spatial.testing.dialects.h2geodb.GeoDBTestSupport; import org.hibernate.spatial.testing.dialects.hana.HANATestSupport; +import org.hibernate.spatial.testing.dialects.mariadb.MariaDBTestSupport; import org.hibernate.spatial.testing.dialects.mysql.MySQL56TestSupport; import org.hibernate.spatial.testing.dialects.mysql.MySQL8TestSupport; import org.hibernate.spatial.testing.dialects.mysql.MySQLTestSupport; @@ -45,7 +47,11 @@ public class TestSupportFactories { return PostgisTestSupport.class; } - if ( ( dialect instanceof SpatialDialect ) && CockroachDB192Dialect.class.isAssignableFrom( dialect.getClass() ) ){ + if ( ( dialect instanceof SpatialDialect ) && MariaDBDialect.class.isAssignableFrom( dialect.getClass() ) ) { + return MariaDBTestSupport.class; + } + + if ( ( dialect instanceof SpatialDialect ) && CockroachDB192Dialect.class.isAssignableFrom( dialect.getClass() ) ) { return CockroachDBTestSupport.class; } diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mariadb/MariaDBExpectationsFactory.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mariadb/MariaDBExpectationsFactory.java new file mode 100644 index 0000000000..094216ce3c --- /dev/null +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mariadb/MariaDBExpectationsFactory.java @@ -0,0 +1,18 @@ +/* + * 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.testing.dialects.mariadb; + +import org.hibernate.spatial.testing.DataSourceUtils; +import org.hibernate.spatial.testing.dialects.mysql.MySQL8ExpectationsFactory; + +//for now, create the same expectations as for MySQL8 +public class MariaDBExpectationsFactory extends MySQL8ExpectationsFactory { + public MariaDBExpectationsFactory(DataSourceUtils dataSourceUtils) { + super( dataSourceUtils ); + } +} diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mariadb/MariaDBExpressionTemplate.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mariadb/MariaDBExpressionTemplate.java new file mode 100644 index 0000000000..1ff5f4da15 --- /dev/null +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mariadb/MariaDBExpressionTemplate.java @@ -0,0 +1,16 @@ +/* + * 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.testing.dialects.mariadb; + + +import org.hibernate.spatial.testing.dialects.mysql.MySQL8ExpressionTemplate; + +//for now, just extends the MySQL8 template +public class MariaDBExpressionTemplate extends MySQL8ExpressionTemplate { + +} diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mariadb/MariaDBTestSupport.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mariadb/MariaDBTestSupport.java new file mode 100644 index 0000000000..132d3f59e1 --- /dev/null +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mariadb/MariaDBTestSupport.java @@ -0,0 +1,35 @@ +/* + * 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.testing.dialects.mariadb; + +import org.hibernate.spatial.testing.AbstractExpectationsFactory; +import org.hibernate.spatial.testing.DataSourceUtils; +import org.hibernate.spatial.testing.SQLExpressionTemplate; +import org.hibernate.spatial.testing.TestData; +import org.hibernate.spatial.testing.TestSupport; + +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; + +public class MariaDBTestSupport extends TestSupport { + @Override + public TestData createTestData(BaseCoreFunctionalTestCase testcase) { + return TestData.fromFile( "mariadb/test-mariadb-functions-data-set.xml" ); + + } + + @Override + public AbstractExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils) { + return new MariaDBExpectationsFactory( dataSourceUtils ); + } + + @Override + public SQLExpressionTemplate getSQLExpressionTemplate() { + return new MariaDBExpressionTemplate(); + } +} diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mysql/MySQL8ExpectationsFactory.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mysql/MySQL8ExpectationsFactory.java index def100dcda..2fe2b796d2 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mysql/MySQL8ExpectationsFactory.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mysql/MySQL8ExpectationsFactory.java @@ -24,7 +24,7 @@ import org.locationtech.jts.geom.Point; public class MySQL8ExpectationsFactory extends AbstractExpectationsFactory { - MySQL8ExpectationsFactory(DataSourceUtils dataSourceUtils) { + public MySQL8ExpectationsFactory(DataSourceUtils dataSourceUtils) { super( dataSourceUtils ); } @@ -95,7 +95,8 @@ public class MySQL8ExpectationsFactory extends AbstractExpectationsFactory { @Override protected NativeSQLStatement createNativeRelateStatement(Geometry geom, String matrix) { - throw new UnsupportedOperationException(); + String sql = "select t.id, ST_Relate(t.geom, ST_GeomFromText(?, 31370), '" + matrix + "' ) from geomtest t where ST_Relate(t.geom, ST_GeomFromText(?, 31370), '" + matrix + "') = 1 "; + return createNativeSQLStatementAllWKTParams( sql, geom.toText() ); } @Override @@ -200,7 +201,7 @@ public class MySQL8ExpectationsFactory extends AbstractExpectationsFactory { @Override protected NativeSQLStatement createNativeBoundaryStatement() { - throw new UnsupportedOperationException(); + return createNativeSQLStatement( "select id, st_boundary(geom) from geomtest" ); } @Override diff --git a/hibernate-spatial/src/test/resources/mariadb/test-mariadb-functions-data-set.xml b/hibernate-spatial/src/test/resources/mariadb/test-mariadb-functions-data-set.xml new file mode 100644 index 0000000000..22baa09bac --- /dev/null +++ b/hibernate-spatial/src/test/resources/mariadb/test-mariadb-functions-data-set.xml @@ -0,0 +1,135 @@ + + + + + + + 1 + POINT + SRID=31370;POINT(10 5) + + + 2 + POINT + SRID=31370;POINT(52.25 2.53) + + + + 3 + POINT + SRID=31370;POINT(51 12) + + + 4 + POINT + SRID=31370;POINT(10.0 2.0) + + + + 5 + LINESTRING + SRID=31370;LINESTRING(10.0 5.0, 20.0 15.0) + + + + 6 + LINESTRING + SRID=31370;LINESTRING(10.0 5.0, 20.0 15.0, 30.3 22.4, 10 30.0) + + + + + 11 + MULTILINESTRING + SRID=31370;MULTILINESTRING((10.0 5.0, 20.0 15.0),( 25.0 30.0, 30.0 20.0)) + + + + 12 + MULTILINESTRING + SRID=31370;MULTILINESTRING((10.0 5.0, 20.0 15.0, 30.3 22.4, 10 30.0), (40.0 20.0, 42.0 18.0, 43.0 16.0, 40 + 14.0)) + + + + + + 16 + POLYGON + SRID=31370;POLYGON( (0 0, 0 10, 10 10, 10 0, 0 0) ) + + + 18 + POLYGON + SRID=31370;POLYGON( (0 0, 0 10, 10 10, 10 0, 0 0), (2 2, 2 5, 5 5,5 2, 2 2)) + + + 19 + POLYGON + SRID=31370;POLYGON( (50 50, 50 70, 70 70, 70 50, 50 50) ) + + + + 20 + MULTIPOLYGON + SRID=31370;MULTIPOLYGON( ((10 20, 30 40, 44 50, 10 20)), ((55 50, 60 70, 70 78, 55 50)) ) + + + 22 + MULTIPOLYGON + SRID=31370;MULTIPOLYGON(( (0 0, 0 50, 50 50, 50 0, 0 0), (10 10, 10 20, 20 20, 20 10, 10 10) ),((15 10, 12 + 14, 13 + 14, 15 10)) ) + + + + + + 25 + MULTIPOINT + SRID=31370;MULTIPOINT(21 2, 25 5, 30 3) + + + 26 + MULTIPOINT + SRID=31370;MULTIPOINT(21 2) + + + + 30 + GEOMETRYCOLLECTION + SRID=31370;GEOMETRYCOLLECTION(POINT(4 0), LINESTRING(4 2, 5 3)) + + + 31 + GEOMETRYCOLLECTION + SRID=31370;GEOMETRYCOLLECTION(POINT(4 0), LINESTRING(4 2, 5 3), POLYGON((0 0, 3 0, 3 3,0 3, 0 0))) + + + 32 + GEOMETRYCOLLECTION + SRID=31370;GEOMETRYCOLLECTION(POINT(4 0), LINESTRING(4 2, 5 3), POLYGON((0 0, 3 0, 3 3,0 3, 0 0),(1 1, 2 1, + 2 2, 1 2, + 1 1))) + + + + 33 + GEOMETRYCOLLECTION + SRID=31370;GEOMETRYCOLLECTION( MULTIPOINT(21 2, 25 5, 30 3), MULTIPOLYGON( ((10 20, 30 40, 44 50, 10 20)), + ((15 10, + 12 14, 13 14, 15 10)) ), MULTILINESTRING((10.0 5.0, 20.0 15.0),( 25.0 30.0, 30.0 20.0))) + + + + +