diff --git a/hibernate-spatial/databases/mysql8/resources/hibernate.properties b/hibernate-spatial/databases/mysql8/resources/hibernate.properties index b5383e0260..485889cd4e 100644 --- a/hibernate-spatial/databases/mysql8/resources/hibernate.properties +++ b/hibernate-spatial/databases/mysql8/resources/hibernate.properties @@ -5,7 +5,7 @@ # See the lgpl.txt file in the root directory or . # -hibernate.dialect org.hibernate.spatial.dialect.mysql.MySQL56SpatialDialect +hibernate.dialect org.hibernate.spatial.dialect.mysql.MySQL8SpatialDialect hibernate.connection.driver_class com.mysql.jdbc.Driver hibernate.connection.url jdbc:mysql://localhost:3306/hibern8 hibernate.connection.username hibernateormtest diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQL56SpatialDialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQL56SpatialDialect.java index 8becd61f71..b6043763e1 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQL56SpatialDialect.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQL56SpatialDialect.java @@ -48,13 +48,13 @@ public class MySQL56SpatialDialect extends MySQL55Dialect implements SpatialDial MySQLGeometryTypeDescriptor.INSTANCE.getSqlType(), "GEOMETRY" ); - final MySQLSpatialFunctions functionsToRegister = overrideObjectShapeFunctions( new MySQLSpatialFunctions() ); + final MySQL5SpatialFunctions functionsToRegister = overrideObjectShapeFunctions( new MySQL5SpatialFunctions() ); for ( Map.Entry entry : functionsToRegister ) { registerFunction( entry.getKey(), entry.getValue() ); } } - private MySQLSpatialFunctions overrideObjectShapeFunctions(MySQLSpatialFunctions mysqlFunctions) { + private MySQL5SpatialFunctions overrideObjectShapeFunctions(MySQL5SpatialFunctions mysqlFunctions) { mysqlFunctions.put( "contains", new StandardSQLFunction( "ST_Contains", StandardBasicTypes.BOOLEAN ) ); mysqlFunctions.put( "crosses", new StandardSQLFunction( "ST_Crosses", StandardBasicTypes.BOOLEAN ) ); mysqlFunctions.put( "disjoint", new StandardSQLFunction( "ST_Disjoint", StandardBasicTypes.BOOLEAN ) ); diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQL5SpatialDialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQL5SpatialDialect.java index fad261e50b..059538a4e9 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQL5SpatialDialect.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQL5SpatialDialect.java @@ -37,7 +37,7 @@ public class MySQL5SpatialDialect extends MySQL5Dialect implements SpatialDialec MySQLGeometryTypeDescriptor.INSTANCE.getSqlType(), "GEOMETRY" ); - for ( Map.Entry entry : new MySQLSpatialFunctions() ) { + for ( Map.Entry entry : new MySQL5SpatialFunctions() ) { registerFunction( entry.getKey(), entry.getValue() ); } } diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQLSpatialFunctions.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQL5SpatialFunctions.java similarity index 97% rename from hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQLSpatialFunctions.java rename to hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQL5SpatialFunctions.java index 148f4269ea..40bd5fbf98 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQLSpatialFunctions.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQL5SpatialFunctions.java @@ -11,13 +11,13 @@ import org.hibernate.spatial.dialect.SpatialFunctionsRegistry; import org.hibernate.type.StandardBasicTypes; /** - * An {@code Iterable} over the spatial functions supported by MySQL. + * An {@code Iterable} over the spatial functions supported by MySQL 5.x. * * @author Karel Maesen, Geovise BVBA */ -class MySQLSpatialFunctions extends SpatialFunctionsRegistry { +class MySQL5SpatialFunctions extends SpatialFunctionsRegistry { - MySQLSpatialFunctions() { + MySQL5SpatialFunctions() { functionMap.put( "dimension", new StandardSQLFunction( "dimension", diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQL8SpatialDialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQL8SpatialDialect.java new file mode 100644 index 0000000000..d079f82f0f --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQL8SpatialDialect.java @@ -0,0 +1,124 @@ +/* + * 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.mysql; + +import java.util.Map; + +import org.hibernate.HibernateException; +import org.hibernate.boot.model.TypeContributions; +import org.hibernate.dialect.MySQL8Dialect; +import org.hibernate.dialect.function.SQLFunction; +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.type.descriptor.sql.SqlTypeDescriptor; + +/** + * Created by Karel Maesen, Geovise BVBA on 2019-03-07. + */ +public class MySQL8SpatialDialect extends MySQL8Dialect implements SpatialDialect { + + private MySQLSpatialDialect dialectDelegate = new MySQLSpatialDialect(); + private MySQL8SpatialFunctions spatialFunctions = new MySQL8SpatialFunctions(); + + /** + * Constructs an instance + */ + public MySQL8SpatialDialect() { + super(); + registerColumnType( + MySQLGeometryTypeDescriptor.INSTANCE.getSqlType(), + "GEOMETRY" + ); + for ( Map.Entry entry : spatialFunctions ) { + registerFunction( entry.getKey(), entry.getValue() ); + } + } + + @Override + public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { + dialectDelegate.contributeTypes( typeContributions, serviceRegistry ); + } + + @Override + public 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 + public String getTypeName(int code, long length, int precision, int scale) throws HibernateException { + return dialectDelegate.getTypeName( code, length, precision, scale ); + } + + @Override + public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) { + return dialectDelegate.remapSqlTypeDescriptor( sqlTypeDescriptor ); + } + + @Override + public String getSpatialFilterExpression(String columnName) { + return dialectDelegate.getSpatialFilterExpression( columnName ); + } + + @Override + public String getSpatialAggregateSQL(String columnName, int aggregation) { + return dialectDelegate.getSpatialAggregateSQL( columnName, aggregation ); + } + + @Override + public String getDWithinSQL(String columnName) { + return dialectDelegate.getDWithinSQL( columnName ); + } + + @Override + public String getHavingSridSQL(String columnName) { + return " (ST_SRID(" + columnName + ") = ?) "; + } + + @Override + public String getIsEmptySQL(String columnName, boolean isEmpty) { + final String emptyExpr = " ST_IsEmpty(" + columnName + ") "; + return isEmpty ? emptyExpr : "( NOT " + emptyExpr + ")"; + } + + @Override + public boolean supportsFiltering() { + return true; + } + + @Override + public boolean supports(SpatialFunction function) { + return spatialFunctions.get( function.toString() ) != null; + } +} diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQL8SpatialFunctions.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQL8SpatialFunctions.java new file mode 100644 index 0000000000..4084e99b17 --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQL8SpatialFunctions.java @@ -0,0 +1,174 @@ +/* + * 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.mysql; + +import org.hibernate.dialect.function.StandardSQLFunction; +import org.hibernate.spatial.dialect.SpatialFunctionsRegistry; +import org.hibernate.type.StandardBasicTypes; + +/** + * An {@code Iterable} over the spatial functions supported by MySQL 8. + * + * @author Karel Maesen, Geovise BVBA + */ +class MySQL8SpatialFunctions extends SpatialFunctionsRegistry { + + MySQL8SpatialFunctions() { + 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( +// "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( +// "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" + ) + ); + } + +} diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQLSpatialDialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQLSpatialDialect.java index ac6ff26365..e8c8645f86 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQLSpatialDialect.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQLSpatialDialect.java @@ -36,7 +36,7 @@ public class MySQLSpatialDialect extends MySQLDialect implements SpatialDialect MySQLGeometryTypeDescriptor.INSTANCE.getSqlType(), "GEOMETRY" ); - for ( Map.Entry entry : new MySQLSpatialFunctions() ) { + for ( Map.Entry entry : new MySQL5SpatialFunctions() ) { registerFunction( entry.getKey(), entry.getValue() ); } } 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 f3432f1f35..6dd4dda86e 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 @@ -14,6 +14,7 @@ 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.mysql.MySQL56TestSupport; +import org.hibernate.spatial.testing.dialects.mysql.MySQL8TestSupport; import org.hibernate.spatial.testing.dialects.mysql.MySQLTestSupport; import org.hibernate.spatial.testing.dialects.oracle.OracleSDOTestSupport; import org.hibernate.spatial.testing.dialects.postgis.PostgisTestSupport; @@ -55,6 +56,11 @@ public class TestSupportFactories { "org.hibernate.spatial.dialect.mysql.MySQL5InnoDBSpatialDialect".equals( canonicalName ) ) { return MySQLTestSupport.class; } + + if ( "org.hibernate.spatial.dialect.mysql.MySQL8SpatialDialect".equals( canonicalName ) ) { + return MySQL8TestSupport.class; + } + if ( "org.hibernate.spatial.dialect.mysql.MySQL56SpatialDialect".equals( canonicalName ) || "org.hibernate.spatial.dialect.mysql.MySQL56InnoDBSpatialDialect".equals( canonicalName ) ) { return MySQL56TestSupport.class; 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 new file mode 100644 index 0000000000..4b05cee14f --- /dev/null +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mysql/MySQL8ExpectationsFactory.java @@ -0,0 +1,246 @@ +/* + * 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.mysql; + +import org.hibernate.spatial.testing.AbstractExpectationsFactory; +import org.hibernate.spatial.testing.DataSourceUtils; +import org.hibernate.spatial.testing.NativeSQLStatement; + +import org.geolatte.geom.ByteBuffer; +import org.geolatte.geom.codec.Wkb; +import org.geolatte.geom.codec.WkbDecoder; +import org.geolatte.geom.jts.JTS; +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.Point; + +/** + * @author Karel Maesen, Geovise BVBA + * creation-date: 10/9/13 + */ +public class MySQL8ExpectationsFactory extends AbstractExpectationsFactory { + + + MySQL8ExpectationsFactory(DataSourceUtils dataSourceUtils) { + super( dataSourceUtils ); + } + + @Override + protected NativeSQLStatement createNativeTouchesStatement(Geometry geom) { + return createNativeSQLStatementAllWKTParams( + "select t.id, ST_Touches(t.geom, ST_GeomFromText(?, 31370)) from geomtest t where ST_Touches(t.geom, ST_geomFromText(?, 31370)) = 1 ", + geom.toText() + ); + } + + @Override + protected NativeSQLStatement createNativeOverlapsStatement(Geometry geom) { + return createNativeSQLStatementAllWKTParams( + "select t.id, ST_overlaps(t.geom, ST_GeomFromText(?, 31370)) from geomtest t where ST_Overlaps(t.geom, ST_geomFromText(?, 31370)) = 1 ", + geom.toText() + ); + } + + @Override + protected NativeSQLStatement createNativeIntersectsStatement(Geometry geom) { + return createNativeSQLStatementAllWKTParams( + "select t.id, ST_Intersects(t.geom, ST_GeomFromText(?, 31370)) from geomtest t where ST_Intersects(t.geom, ST_GeomFromText(?, 31370)) = 1 ", + geom.toText() + ); + } + + @Override + protected NativeSQLStatement createNativeWithinStatement(Geometry geom) { + return createNativeSQLStatementAllWKTParams( + "select t.id, ST_Within(t.geom, ST_GeomFromText(?, 31370)) from geomtest t where ST_Within(t.geom, ST_GeomFromText(?, 31370)) = 1 ", + geom.toText() + ); + } + + @Override + protected NativeSQLStatement createNativeEqualsStatement(Geometry geom) { + return createNativeSQLStatementAllWKTParams( + "select t.id, ST_Equals(t.geom, ST_GeomFromText(?, 31370)) from geomtest t where ST_Equals(t.geom, ST_GeomFromText(?, 31370)) = 1 ", + geom.toText() + ); + } + + @Override + protected NativeSQLStatement createNativeCrossesStatement(Geometry geom) { + return createNativeSQLStatementAllWKTParams( + "select t.id, ST_Crosses(t.geom, ST_GeomFromText(?, 31370)) from geomtest t where ST_Crosses(t.geom, ST_geomFromText(?, 31370)) = 1 ", + geom.toText() + ); + } + + @Override + protected NativeSQLStatement createNativeContainsStatement(Geometry geom) { + return createNativeSQLStatementAllWKTParams( + "select t.id, ST_Contains(t.geom, ST_GeomFromText(?, 31370)) from geomtest t where ST_Contains(t.geom, ST_geomFromText(?, 31370)) = 1 ", + geom.toText() + ); + } + + @Override + protected NativeSQLStatement createNativeDisjointStatement(Geometry geom) { + return createNativeSQLStatementAllWKTParams( + "select t.id, ST_Disjoint(t.geom, ST_GeomFromText(?, 31370)) from geomtest t where ST_Disjoint(t.geom, ST_geomFromText(?, 31370)) = 1 ", + geom.toText() + ); + } + + + + @Override + protected NativeSQLStatement createNativeRelateStatement(Geometry geom, String matrix) { + throw new UnsupportedOperationException(); + } + + @Override + protected NativeSQLStatement createNativeDwithinStatement(Point geom, double distance) { + throw new UnsupportedOperationException(); + } + + + @Override + protected NativeSQLStatement createNativeFilterStatement(Geometry geom) { + return createNativeSQLStatementAllWKTParams( + "select t.id, MBRIntersects(t.geom, ST_GeomFromtext(?, 31370)) from geomtest t where MBRIntersects(t.geom, ST_GeomFromtext(?, 31370)) = 1", + geom.toText() + ); + } + + @Override + protected NativeSQLStatement createNativeDistanceStatement(Geometry geom) { + return createNativeSQLStatementAllWKTParams( + "select t.id, ST_distance(t.geom, ST_GeomFromText(?, 31370)) from geomtest t ", + geom.toText() + ); + } + + @Override + protected NativeSQLStatement createNativeDimensionSQL() { + return createNativeSQLStatement( "select id, ST_dimension(geom) from geomtest" ); + } + + @Override + protected NativeSQLStatement createNativeBufferStatement(Double distance) { + return createNativeSQLStatement( + "select t.id, ST_buffer(t.geom,?) from geomtest t ", + new Object[] { distance } + ); + } + + @Override + protected NativeSQLStatement createNativeConvexHullStatement(Geometry geom) { + return createNativeSQLStatementAllWKTParams( + "select t.id, ST_convexhull(ST_Union(t.geom, ST_GeomFromText(?, 31370))) from geomtest t", + geom.toText() + ); + } + + @Override + protected NativeSQLStatement createNativeIntersectionStatement(Geometry geom) { + return createNativeSQLStatementAllWKTParams( + "select t.id, ST_intersection(t.geom, ST_GeomFromtext(?, 31370)) from geomtest t ", + geom.toText() + ); + } + + @Override + protected NativeSQLStatement createNativeDifferenceStatement(Geometry geom) { + return createNativeSQLStatementAllWKTParams( + "select t.id, ST_Difference(t.geom, ST_GeomFromtext(?, 31370)) from geomtest t ", + geom.toText() + ); + } + + @Override + protected NativeSQLStatement createNativeSymDifferenceStatement(Geometry geom) { + return createNativeSQLStatementAllWKTParams( + "select t.id, ST_Symdifference(t.geom, ST_GeomFromtext(?, 31370)) from geomtest t ", + geom.toText() + ); + } + + @Override + protected NativeSQLStatement createNativeGeomUnionStatement(Geometry geom) { + return createNativeSQLStatementAllWKTParams( + "select t.id, ST_Union(t.geom, ST_GeomFromtext(?, 31370)) from geomtest t", + geom.toText() + ); + } + + @Override + protected NativeSQLStatement createNativeAsTextStatement() { + return createNativeSQLStatement( "select id, ST_astext(geom) from geomtest" ); + } + + @Override + protected NativeSQLStatement createNativeSridStatement() { + return createNativeSQLStatement( "select id, ST_SRID(geom) from geomtest" ); + } + + @Override + protected NativeSQLStatement createNativeIsSimpleStatement() { + return createNativeSQLStatement( "select id, ST_IsSimple(geom) from geomtest" ); + } + + @Override + protected NativeSQLStatement createNativeIsEmptyStatement() { + return createNativeSQLStatement( "select id, ST_IsEmpty(geom) from geomtest" ); + } + + @Override + protected NativeSQLStatement createNativeIsNotEmptyStatement() { + return createNativeSQLStatement( "select id, not ST_IsEmpty(geom) from geomtest" ); + } + + @Override + protected NativeSQLStatement createNativeBoundaryStatement() { + throw new UnsupportedOperationException(); + } + + @Override + protected NativeSQLStatement createNativeEnvelopeStatement() { + return createNativeSQLStatement( "select id, ST_Envelope(geom) from geomtest" ); + } + + @Override + protected NativeSQLStatement createNativeAsBinaryStatement() { + return createNativeSQLStatement( "select id, ST_AsBinary(geom) from geomtest" ); + } + + @Override + protected NativeSQLStatement createNativeGeometryTypeStatement() { + return createNativeSQLStatement( "select id, ST_GeometryType(geom) from geomtest" ); + } + + @Override + protected NativeSQLStatement createNativeTransformStatement(int epsg) { + throw new UnsupportedOperationException(); + } + + @Override + protected NativeSQLStatement createNativeHavingSRIDStatement(int srid) { + return createNativeSQLStatement( "select t.id, (ST_Srid(t.geom) = " + srid + ") from geomtest t where ST_SRID(t.geom) = " + srid ); + } + + @Override + protected Geometry decode(Object bytes) { + if ( bytes == null ) { + return null; + } + ByteBuffer buffer = ByteBuffer.from( (byte[]) bytes ); + WkbDecoder decoder = Wkb.newDecoder( Wkb.Dialect.MYSQL_WKB ); + return JTS.to( decoder.decode( buffer ) ); + } + + @Override + public int getTestSrid() { + return 31370; + } +} diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mysql/MySQL8ExpressionTemplate.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mysql/MySQL8ExpressionTemplate.java new file mode 100644 index 0000000000..82cf41ad53 --- /dev/null +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mysql/MySQL8ExpressionTemplate.java @@ -0,0 +1,30 @@ +/* + * 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.mysql; + +import org.hibernate.spatial.testing.TestDataElement; +import org.hibernate.spatial.testing.WktUtility; + +/** + * Created by Karel Maesen, Geovise BVBA on 2019-03-07. + */ +public class MySQL8ExpressionTemplate extends MySQLExpressionTemplate { + + static final String SQL_TEMPLATE = "insert into geomtest (id, type, geom) values (%d, '%s', ST_GeomFromText('%s', %d))"; + + public String toInsertSql(TestDataElement testDataElement) { + String wkt = WktUtility.getWkt( testDataElement.wkt ); + int srid = WktUtility.getSRID( testDataElement.wkt ); + return String.format( + SQL_TEMPLATE, + testDataElement.id, + testDataElement.type, + wkt, + srid + ); + } +} diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mysql/MySQL8TestSupport.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mysql/MySQL8TestSupport.java new file mode 100644 index 0000000000..7848286f6a --- /dev/null +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mysql/MySQL8TestSupport.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.mysql; + +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.testing.junit4.BaseCoreFunctionalTestCase; + +/** + * Created by Karel Maesen, Geovise BVBA on 2019-03-07. + */ +public class MySQL8TestSupport extends MySQLTestSupport { + + @Override + public TestData createTestData(BaseCoreFunctionalTestCase testcase) { + return TestData.fromFile( "mysql/test-mysql8-functions-data-set.xml" ); + } + + @Override + public SQLExpressionTemplate getSQLExpressionTemplate() { + return new MySQL8ExpressionTemplate(); + } + + @Override + public AbstractExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils) { + return new MySQL8ExpectationsFactory( dataSourceUtils ); + } +} diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mysql/MySQLExpressionTemplate.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mysql/MySQLExpressionTemplate.java index f39f57cc14..db57af0185 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mysql/MySQLExpressionTemplate.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/dialects/mysql/MySQLExpressionTemplate.java @@ -4,7 +4,6 @@ * 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.mysql; diff --git a/hibernate-spatial/src/test/resources/mysql/test-mysql8-functions-data-set.xml b/hibernate-spatial/src/test/resources/mysql/test-mysql8-functions-data-set.xml new file mode 100644 index 0000000000..1ea78924cf --- /dev/null +++ b/hibernate-spatial/src/test/resources/mysql/test-mysql8-functions-data-set.xml @@ -0,0 +1,132 @@ + + + + + + + 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))) + + + + +