HHH-14804 Upgrade MySQL8 support
This commit is contained in:
parent
2deee38103
commit
65aa8f7a5b
|
@ -43,7 +43,7 @@ sourceSets.test.resources {
|
|||
tasks.test {
|
||||
// for now we cannot run with 'h2' project.db due to compatability issues
|
||||
// H2 requires 4.200 but H2GIS 1.5 needs 4.197
|
||||
enabled = ['pgsql', 'pgsql_ci', 'cockroachdb', 'mariadb', 'mysql_docker', 'mysql_docker'].contains( project.db )
|
||||
enabled = ['pgsql', 'pgsql_ci', 'cockroachdb', 'mariadb', 'mysql_ci', 'mysql_docker'].contains( project.db )
|
||||
}
|
||||
|
||||
tasks.test.include '**/*'
|
||||
|
|
|
@ -31,22 +31,19 @@ public class GeometryLiteralFormatter<T> implements JdbcLiteralFormatter<T> {
|
|||
}
|
||||
|
||||
@Override
|
||||
//todo -- clean this up
|
||||
public void appendJdbcLiteral(
|
||||
SqlAppender appender, T value, Dialect dialect, WrapperOptions wrapperOptions) {
|
||||
appender.appendSql( geomFromTextName );
|
||||
int srid = 0;
|
||||
appender.appendSql( "('" );
|
||||
Geometry<?> geom;
|
||||
if ( javaType instanceof GeolatteGeometryJavaTypeDescriptor ) {
|
||||
appender.appendSql( Wkt.toWkt( (Geometry<?>) value, wktDialect ) );
|
||||
srid = ( (Geometry<?>) value ).getSRID();
|
||||
geom = (Geometry<?>) value;
|
||||
}
|
||||
else {
|
||||
appender.appendSql( Wkt.toWkt( jts2Gl( value ), wktDialect ) );
|
||||
srid = ( (org.locationtech.jts.geom.Geometry) value ).getSRID();
|
||||
geom = jts2Gl( value );
|
||||
}
|
||||
appender.appendSql( "ST_GeomFromText('" );
|
||||
appender.appendSql( Wkt.toWkt( geom, Wkt.Dialect.SFA_1_1_0 ) );
|
||||
appender.appendSql( "'," );
|
||||
appender.appendSql( srid );
|
||||
appender.appendSql( ( Math.max( geom.getSRID(), 0 ) ) );
|
||||
appender.appendSql( ")" );
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import java.sql.SQLException;
|
|||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.spatial.GeolatteGeometryJavaTypeDescriptor;
|
||||
import org.hibernate.spatial.GeometryLiteralFormatter;
|
||||
import org.hibernate.type.SqlTypes;
|
||||
import org.hibernate.type.descriptor.ValueBinder;
|
||||
import org.hibernate.type.descriptor.ValueExtractor;
|
||||
|
@ -53,20 +54,7 @@ public class GeoDBGeometryType implements JdbcType {
|
|||
//todo -- simplify as with postgis/mariadb
|
||||
@Override
|
||||
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaType<T> javaTypeDescriptor) {
|
||||
return (appender, value, dialect, wrapperOptions) -> {
|
||||
Geometry<?> geom;
|
||||
if ( javaTypeDescriptor instanceof GeolatteGeometryJavaTypeDescriptor ) {
|
||||
geom = (Geometry<?>) value;
|
||||
}
|
||||
else {
|
||||
geom = jts2Gl( value );
|
||||
}
|
||||
appender.appendSql( "ST_GeomFromText('" );
|
||||
appender.appendSql( Wkt.toWkt( geom, Wkt.Dialect.SFA_1_1_0 ) );
|
||||
appender.appendSql( "'," );
|
||||
appender.appendSql( ( geom.getSRID() ) );
|
||||
appender.appendSql( ")" );
|
||||
};
|
||||
return new GeometryLiteralFormatter<T>( javaTypeDescriptor, Wkt.Dialect.SFA_1_1_0, "ST_GeomFromText" );
|
||||
}
|
||||
|
||||
private <T> Geometry<?> jts2Gl(T value) {
|
||||
|
|
|
@ -6,9 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.spatial.dialect.mysql;
|
||||
|
||||
import org.hibernate.dialect.InnoDBStorageEngine;
|
||||
import org.hibernate.dialect.MySQLStorageEngine;
|
||||
|
||||
/**
|
||||
* A Dialect for MySQL 5 using InnoDB engine, with support for its spatial features
|
||||
*
|
||||
|
|
|
@ -1,176 +0,0 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.dialect.mysql;
|
||||
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.dialect.SpatialFunctionsRegistry;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
||||
/**
|
||||
* An {@code Iterable} over the spatial functions supported by MySQL 5.x.
|
||||
*
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
*/
|
||||
class MySQL5SpatialFunctions extends SpatialFunctionsRegistry {
|
||||
|
||||
MySQL5SpatialFunctions() {
|
||||
functionMap.put(
|
||||
"dimension", new StandardSQLFunction(
|
||||
"dimension",
|
||||
StandardBasicTypes.INTEGER
|
||||
)
|
||||
);
|
||||
functionMap.put(
|
||||
"geometrytype", new StandardSQLFunction(
|
||||
"geometrytype", StandardBasicTypes.STRING
|
||||
)
|
||||
);
|
||||
functionMap.put(
|
||||
"srid", new StandardSQLFunction(
|
||||
"srid",
|
||||
StandardBasicTypes.INTEGER
|
||||
)
|
||||
);
|
||||
functionMap.put(
|
||||
"envelope", new StandardSQLFunction(
|
||||
"envelope"
|
||||
)
|
||||
);
|
||||
functionMap.put(
|
||||
"astext", new StandardSQLFunction(
|
||||
"astext",
|
||||
StandardBasicTypes.STRING
|
||||
)
|
||||
);
|
||||
functionMap.put(
|
||||
"asbinary", new StandardSQLFunction(
|
||||
"asbinary",
|
||||
StandardBasicTypes.BINARY
|
||||
)
|
||||
);
|
||||
functionMap.put(
|
||||
"isempty", new StandardSQLFunction(
|
||||
"isempty",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
functionMap.put(
|
||||
"issimple", new StandardSQLFunction(
|
||||
"issimple",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
// functionMap.put(
|
||||
// "boundary", new StandardSQLFunction(
|
||||
// "boundary"
|
||||
// )
|
||||
// );
|
||||
|
||||
// Register functions for spatial relation constructs
|
||||
functionMap.put(
|
||||
"overlaps", new StandardSQLFunction(
|
||||
"overlaps",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
functionMap.put(
|
||||
"intersects", new StandardSQLFunction(
|
||||
"intersects",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
functionMap.put(
|
||||
"equals", new StandardSQLFunction(
|
||||
"equals",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
functionMap.put(
|
||||
"contains", new StandardSQLFunction(
|
||||
"contains",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
functionMap.put(
|
||||
"crosses", new StandardSQLFunction(
|
||||
"crosses",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
functionMap.put(
|
||||
"disjoint", new StandardSQLFunction(
|
||||
"disjoint",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
functionMap.put(
|
||||
"touches", new StandardSQLFunction(
|
||||
"touches",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
functionMap.put(
|
||||
"within", new StandardSQLFunction(
|
||||
"within",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
// functionMap.put(
|
||||
// "relate", new StandardSQLFunction(
|
||||
// "relate",
|
||||
// StandardBasicTypes.BOOLEAN
|
||||
// )
|
||||
// );
|
||||
//
|
||||
// // register the spatial analysis functions
|
||||
// functionMap.put(
|
||||
// "distance", new StandardSQLFunction(
|
||||
// "distance",
|
||||
// StandardBasicTypes.DOUBLE
|
||||
// )
|
||||
// );
|
||||
// functionMap.put(
|
||||
// "buffer", new StandardSQLFunction(
|
||||
// "buffer"
|
||||
// )
|
||||
// );
|
||||
// functionMap.put(
|
||||
// "convexhull", new StandardSQLFunction(
|
||||
// "convexhull"
|
||||
// )
|
||||
// );
|
||||
// functionMap.put(
|
||||
// "difference", new StandardSQLFunction(
|
||||
// "difference"
|
||||
// )
|
||||
// );
|
||||
// functionMap.put(
|
||||
// "intersection", new StandardSQLFunction(
|
||||
// "intersection"
|
||||
// )
|
||||
// );
|
||||
// functionMap.put(
|
||||
// "symdifference", new StandardSQLFunction(
|
||||
// "symdifference"
|
||||
// )
|
||||
// );
|
||||
// functionMap.put(
|
||||
// "geomunion", new StandardSQLFunction(
|
||||
// "union"
|
||||
// )
|
||||
// );
|
||||
|
||||
functionMap.put(
|
||||
SpatialFunction.filter.name(), new StandardSQLFunction(
|
||||
"MBRIntersects",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.dialect.mysql;
|
||||
|
||||
import org.hibernate.dialect.MySQL8Dialect;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
|
||||
/**
|
||||
* Created by Karel Maesen, Geovise BVBA on 2019-03-07.
|
||||
*/
|
||||
public class MySQL8SpatialDialect extends MySQL8Dialect implements SpatialDialect {
|
||||
}
|
|
@ -1,182 +0,0 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.dialect.mysql;
|
||||
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
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"
|
||||
)
|
||||
);
|
||||
|
||||
functionMap.put(
|
||||
SpatialFunction.filter.name(), new StandardSQLFunction(
|
||||
"MBRIntersects",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -16,7 +16,6 @@ import org.hibernate.spatial.HSMessageLogger;
|
|||
import org.hibernate.spatial.JTSGeometryType;
|
||||
import org.hibernate.spatial.KeyedSqmFunctionDescriptors;
|
||||
import org.hibernate.spatial.contributor.ContributorImplementor;
|
||||
import org.hibernate.spatial.dialect.mariadb.MariaDBSqmFunctionDescriptors;
|
||||
|
||||
public class MySQLDialectContributor implements ContributorImplementor {
|
||||
|
||||
|
|
|
@ -7,11 +7,31 @@
|
|||
|
||||
package org.hibernate.spatial.dialect.mysql;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.boot.model.FunctionContributions;
|
||||
import org.hibernate.spatial.BaseSqmFunctionDescriptors;
|
||||
import org.hibernate.spatial.CommonSpatialFunction;
|
||||
|
||||
public class MySqlSqmFunctionDescriptors extends BaseSqmFunctionDescriptors {
|
||||
|
||||
final static private List<CommonSpatialFunction> unsupported = new ArrayList<>();
|
||||
|
||||
static {
|
||||
unsupported.add( CommonSpatialFunction.ST_BOUNDARY );
|
||||
unsupported.add( CommonSpatialFunction.ST_RELATE );
|
||||
}
|
||||
|
||||
public MySqlSqmFunctionDescriptors(FunctionContributions functionContributions) {
|
||||
super( functionContributions );
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonSpatialFunction[] filter(CommonSpatialFunction[] functions) {
|
||||
return Arrays.stream( functions )
|
||||
.filter( f -> !unsupported.contains( f ) )
|
||||
.toArray( CommonSpatialFunction[]::new );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@ import org.hibernate.spatial.testing.domain.GeomEntityLike;
|
|||
|
||||
import org.hibernate.testing.orm.junit.DialectContext;
|
||||
|
||||
import org.geolatte.geom.Geometry;
|
||||
|
||||
import static org.hibernate.spatial.testing.datareader.TestSupport.TestDataPurpose.SpatialFunctionsData;
|
||||
import static org.hibernate.spatial.testing.datareader.TestSupport.TestDataPurpose.StoreRetrieveData;
|
||||
|
||||
|
@ -32,9 +34,11 @@ public class SpatialTestDataProvider {
|
|||
protected final NativeSQLTemplates templates;
|
||||
protected final PredicateRegexes predicateRegexes;
|
||||
protected final Map<CommonSpatialFunction, String> hqlOverrides;
|
||||
protected final Geometry<?> filterGeometry;
|
||||
private final TestData funcTestData;
|
||||
protected TestData testData;
|
||||
protected GeomCodec codec;
|
||||
protected List<CommonSpatialFunction> exludeFromTest;
|
||||
|
||||
public SpatialTestDataProvider() {
|
||||
try {
|
||||
|
@ -44,7 +48,9 @@ public class SpatialTestDataProvider {
|
|||
hqlOverrides = support.hqlOverrides();
|
||||
codec = support.codec();
|
||||
testData = support.createTestData( StoreRetrieveData );
|
||||
exludeFromTest = support.getExcludeFromTests();
|
||||
funcTestData = support.createTestData( SpatialFunctionsData );
|
||||
filterGeometry = support.getFilterGeometry();
|
||||
}
|
||||
catch (InstantiationException | IllegalAccessException e) {
|
||||
throw new RuntimeException( e );
|
||||
|
|
|
@ -64,8 +64,9 @@ public class CommonFunctionTests extends SpatialTestBase {
|
|||
public Stream<DynamicTest> testFunction() {
|
||||
|
||||
return
|
||||
TestTemplates.all( templates, hqlOverrides )
|
||||
TestTemplates.all( templates, hqlOverrides, filterGeometry )
|
||||
.filter( f -> isSupported( f.function ) )
|
||||
.filter( f -> !exludeFromTest.contains( f.function ) )
|
||||
.flatMap( t -> Stream.of(
|
||||
t.build( Model.JTSMODEL, codec ),
|
||||
t.build( Model.GLMODEL, codec )
|
||||
|
@ -98,7 +99,11 @@ public class CommonFunctionTests extends SpatialTestBase {
|
|||
return () -> {
|
||||
expected = template.executeNativeQuery( scope );
|
||||
received = template.executeHQL( scope, fnName );
|
||||
assertEquals( expected, received );
|
||||
if ( !expected.equals( received ) ) {
|
||||
for ( int i = 0; i < expected.size(); i++ ) {
|
||||
assertEquals( expected.get( i ), received.get( i ) );
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,16 +36,6 @@ import static org.geolatte.geom.crs.CoordinateReferenceSystems.WGS84;
|
|||
public class TestGeometryConstructionWithParameter extends SpatialTestBase {
|
||||
|
||||
final private Map<CommonSpatialFunction, String> templates = new HashMap<>();
|
||||
final private Geometry<G2D> geometry = polygon(
|
||||
WGS84,
|
||||
ring(
|
||||
g( 0, 0 ),
|
||||
g( 10, 0 ),
|
||||
g( 10, 10 ),
|
||||
g( 0, 10 ),
|
||||
g( 0, 0 )
|
||||
)
|
||||
);
|
||||
|
||||
TestGeometryConstructionWithParameter() {
|
||||
templates.put(
|
||||
|
@ -92,7 +82,7 @@ public class TestGeometryConstructionWithParameter extends SpatialTestBase {
|
|||
scope.inSession( session -> {
|
||||
String hql = templates.get( func );
|
||||
session.createQuery( hql )
|
||||
.setParameter( "poly", geometry )
|
||||
.setParameter( "poly", filterGeometry )
|
||||
.getResultList();
|
||||
//we just check that this parses for now.
|
||||
} );
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.hibernate.spatial.CommonSpatialFunction;
|
|||
import org.hibernate.spatial.testing.dialects.NativeSQLTemplates;
|
||||
|
||||
import org.geolatte.geom.G2D;
|
||||
import org.geolatte.geom.Geometry;
|
||||
import org.geolatte.geom.Polygon;
|
||||
|
||||
import static org.geolatte.geom.builder.DSL.g;
|
||||
|
@ -37,14 +38,11 @@ public abstract class TestTemplates {
|
|||
return new FunctionTestTemplate.Builder( function );
|
||||
}
|
||||
|
||||
static final Polygon<G2D> filter = polygon(
|
||||
WGS84,
|
||||
ring( g( 0, 0 ), g( 0, 10 ), g( 10, 10 ), g( 10, 0 ), g( 0, 0 ) )
|
||||
);
|
||||
|
||||
public static Stream<FunctionTestTemplate.Builder> all(
|
||||
NativeSQLTemplates sqlTemplates,
|
||||
Map<CommonSpatialFunction, String> hqlOverrides) {
|
||||
Map<CommonSpatialFunction, String> hqlOverrides,
|
||||
Geometry<?>filter) {
|
||||
|
||||
Map<CommonSpatialFunction, String> templates = sqlTemplates.all();
|
||||
return templates
|
||||
|
|
|
@ -45,11 +45,6 @@ abstract public class SpatialPredicatesTest extends SpatialTestBase {
|
|||
|
||||
public final static TestSupport.TestDataPurpose PURPOSE = TestSupport.TestDataPurpose.SpatialFunctionsData;
|
||||
|
||||
static final Polygon<G2D> filter = polygon(
|
||||
WGS84,
|
||||
ring( g( 0, 0 ), g( 0, 10 ), g( 10, 10 ), g( 10, 0 ), g( 0, 0 ) )
|
||||
);
|
||||
|
||||
@Override
|
||||
public TestSupport.TestDataPurpose purpose() {
|
||||
return PURPOSE;
|
||||
|
@ -117,7 +112,7 @@ abstract public class SpatialPredicatesTest extends SpatialTestBase {
|
|||
try {
|
||||
query.select( root )
|
||||
.where( (Expression<Boolean>) method.invoke(
|
||||
null, criteriaBuilder, root.get( "geom" ), model.from.apply( filter ) ) );
|
||||
null, criteriaBuilder, root.get( "geom" ), model.from.apply( filterGeometry ) ) );
|
||||
}
|
||||
catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new JUnitException( "Failure to invoke Geometry Predicate", e );
|
||||
|
|
|
@ -14,16 +14,24 @@
|
|||
|
||||
package org.hibernate.spatial.testing.datareader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.NotYetImplementedFor6Exception;
|
||||
import org.hibernate.spatial.CommonSpatialFunction;
|
||||
import org.hibernate.spatial.GeomCodec;
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.dialects.NativeSQLTemplates;
|
||||
import org.hibernate.spatial.testing.dialects.PredicateRegexes;
|
||||
|
||||
import org.geolatte.geom.Geometry;
|
||||
|
||||
import static org.geolatte.geom.builder.DSL.g;
|
||||
import static org.geolatte.geom.builder.DSL.polygon;
|
||||
import static org.geolatte.geom.builder.DSL.ring;
|
||||
import static org.geolatte.geom.crs.CoordinateReferenceSystems.WGS84;
|
||||
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
|
@ -46,6 +54,10 @@ public abstract class TestSupport {
|
|||
return new HashMap<>();
|
||||
}
|
||||
|
||||
public List<CommonSpatialFunction> getExcludeFromTests() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public enum TestDataPurpose {
|
||||
SpatialFunctionsData,
|
||||
StoreRetrieveData
|
||||
|
@ -57,4 +69,11 @@ public abstract class TestSupport {
|
|||
throw new NotYetImplementedFor6Exception();
|
||||
}
|
||||
|
||||
public Geometry<?> getFilterGeometry() {
|
||||
return polygon(
|
||||
WGS84,
|
||||
ring( g( 0, 0 ), g( 0, 10 ), g( 10, 10 ), g( 10, 0 ), g( 0, 0 ) )
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,20 +8,27 @@
|
|||
package org.hibernate.spatial.testing.dialects.mysql;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.spatial.CommonSpatialFunction;
|
||||
import org.hibernate.spatial.GeomCodec;
|
||||
import org.hibernate.spatial.dialect.mariadb.MariaDBGeometryType;
|
||||
import org.hibernate.spatial.dialect.mysql.MySQLGeometryType;
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.testing.JTSGeometryEquality;
|
||||
import org.hibernate.spatial.testing.datareader.TestData;
|
||||
import org.hibernate.spatial.testing.datareader.TestSupport;
|
||||
import org.hibernate.spatial.testing.dialects.NativeSQLTemplates;
|
||||
import org.hibernate.spatial.testing.dialects.PredicateRegexes;
|
||||
|
||||
import org.geolatte.geom.Geometry;
|
||||
import org.geolatte.geom.crs.CoordinateReferenceSystems;
|
||||
import org.geolatte.geom.crs.CrsId;
|
||||
import org.geolatte.geom.crs.LinearUnit;
|
||||
import org.geolatte.geom.crs.ProjectedCoordinateReferenceSystem;
|
||||
|
||||
import static org.geolatte.geom.builder.DSL.c;
|
||||
import static org.geolatte.geom.builder.DSL.polygon;
|
||||
import static org.geolatte.geom.builder.DSL.ring;
|
||||
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
|
@ -29,6 +36,8 @@ import org.geolatte.geom.Geometry;
|
|||
*/
|
||||
public class MySQLTestSupport extends TestSupport {
|
||||
|
||||
ProjectedCoordinateReferenceSystem crs = CoordinateReferenceSystems.mkProjected( CrsId.valueOf( 0 ), LinearUnit.METER );
|
||||
|
||||
@Override
|
||||
public TestData createTestData(TestDataPurpose purpose) {
|
||||
return TestData.fromFile( "mysql/test-mysql-functions-data-set.xml" );
|
||||
|
@ -49,6 +58,26 @@ public class MySQLTestSupport extends TestSupport {
|
|||
return super.hqlOverrides();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CommonSpatialFunction> getExcludeFromTests() {
|
||||
List<CommonSpatialFunction> exclusions = super.getExcludeFromTests();
|
||||
//these actually work, but the st_geomfromtext normalises the interior rings on polygons/geometry collections
|
||||
//thereby invalidating the test
|
||||
//todo allow a more relaxed geometry comparison that treats rings the same regardless of CCW or CW order
|
||||
exclusions.add(CommonSpatialFunction.ST_UNION);
|
||||
exclusions.add( CommonSpatialFunction.ST_SYMDIFFERENCE );
|
||||
return exclusions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Geometry<?> getFilterGeometry() {
|
||||
|
||||
return polygon(
|
||||
crs,
|
||||
ring( c( 0, 0 ), c( 0, 10 ), c( 10, 10 ), c( 10, 0 ), c( 0, 0 ) )
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeomCodec codec() {
|
||||
return new GeomCodec() {
|
||||
|
|
|
@ -9,6 +9,48 @@ package org.hibernate.spatial.testing.dialects.mysql;
|
|||
|
||||
import org.hibernate.spatial.testing.dialects.NativeSQLTemplates;
|
||||
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_BUFFER;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_CONTAINS;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_CONVEXHULL;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_CROSSES;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_DIFFERENCE;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_DISJOINT;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_DISTANCE;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_EQUALS;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_INTERSECTION;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_INTERSECTS;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_OVERLAPS;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_RELATE;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_SYMDIFFERENCE;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_TOUCHES;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_UNION;
|
||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_WITHIN;
|
||||
|
||||
public class MySqlNativeSqlTemplates extends NativeSQLTemplates {
|
||||
|
||||
public MySqlNativeSqlTemplates() {
|
||||
super();
|
||||
sqls.put( ST_OVERLAPS, "select id, st_overlaps(geom, st_geomfromtext(:filter, 0)) as result from %s" );
|
||||
sqls.put( ST_INTERSECTS, "select id, st_intersects(geom, st_geomfromtext(:filter, 0)) as result from %s" );
|
||||
sqls.put( ST_CROSSES, "select id, st_crosses(geom, st_geomfromtext(:filter, 0)) as result from %s" );
|
||||
sqls.put( ST_CONTAINS, "select id, st_contains(geom, st_geomfromtext(:filter, 0)) as result from %s" );
|
||||
sqls.put( ST_DISJOINT, "select id, st_disjoint(geom, st_geomfromtext(:filter, 0)) as result from %s" );
|
||||
sqls.put( ST_RELATE, "select id, st_relate(geom, st_geomfromtext(:filter, 0)) as result from %s" );
|
||||
sqls.put( ST_TOUCHES, "select id, st_touches(geom, st_geomfromtext(:filter, 0)) as result from %s" );
|
||||
sqls.put( ST_WITHIN, "select id, st_within(geom, st_geomfromtext(:filter, 0)) as result from %s" );
|
||||
sqls.put( ST_EQUALS, "select id, st_equals(geom, st_geomfromtext(:filter, 0)) as result from %s" );
|
||||
sqls.put( ST_DISTANCE, "select id, st_distance(geom, st_geomfromtext(:filter, 0)) as result from %s" );
|
||||
sqls.put( ST_BUFFER, "select id, st_buffer(geom, 2) as result from %s" );
|
||||
sqls.put( ST_CONVEXHULL, "select id, st_convexhull(geom) as result from %s" );
|
||||
sqls.put( ST_DIFFERENCE, "select id, st_difference(geom, st_geomfromtext(:filter, 0)) as result from %s" );
|
||||
sqls.put(
|
||||
ST_INTERSECTION,
|
||||
"select id, st_intersection(geom, st_geomfromtext(:filter, 0)) as result from %s"
|
||||
);
|
||||
sqls.put(
|
||||
ST_SYMDIFFERENCE,
|
||||
"select id, st_symdifference(geom, st_geomfromtext(:filter, 0)) as result from %s"
|
||||
);
|
||||
sqls.put( ST_UNION, "select id, st_union(geom, st_geomfromtext(:filter, 0)) as result from %s" );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,48 +16,48 @@ In MySQL these are stored as null objects.
|
|||
<Element>
|
||||
<id>1</id>
|
||||
<type>POINT</type>
|
||||
<wkt>SRID=4326;POINT(10 5)</wkt>
|
||||
<wkt>SRID=0;POINT(10 5)</wkt>
|
||||
</Element>
|
||||
<Element>
|
||||
<id>2</id>
|
||||
<type>POINT</type>
|
||||
<wkt>SRID=4326;POINT(52.25 2.53)</wkt>
|
||||
<wkt>SRID=0;POINT(52.25 2.53)</wkt>
|
||||
</Element>
|
||||
|
||||
<Element>
|
||||
<id>3</id>
|
||||
<type>POINT</type>
|
||||
<wkt>SRID=4326;POINT(51 12)</wkt>
|
||||
<wkt>SRID=0;POINT(51 12)</wkt>
|
||||
</Element>
|
||||
<Element>
|
||||
<id>4</id>
|
||||
<type>POINT</type>
|
||||
<wkt>SRID=4326;POINT(10.0 2.0)</wkt>
|
||||
<wkt>SRID=0;POINT(10.0 2.0)</wkt>
|
||||
</Element>
|
||||
|
||||
<Element>
|
||||
<id>5</id>
|
||||
<type>LINESTRING</type>
|
||||
<wkt>SRID=4326;LINESTRING(10.0 5.0, 20.0 15.0)</wkt>
|
||||
<wkt>SRID=0;LINESTRING(10.0 5.0, 20.0 15.0)</wkt>
|
||||
</Element>
|
||||
|
||||
<Element>
|
||||
<id>6</id>
|
||||
<type>LINESTRING</type>
|
||||
<wkt>SRID=4326;LINESTRING(10.0 5.0, 20.0 15.0, 30.3 22.4, 10 30.0)</wkt>
|
||||
<wkt>SRID=0;LINESTRING(10.0 5.0, 20.0 15.0, 30.3 22.4, 10 30.0)</wkt>
|
||||
</Element>
|
||||
|
||||
|
||||
<Element>
|
||||
<id>11</id>
|
||||
<type>MULTILINESTRING</type>
|
||||
<wkt>SRID=4326;MULTILINESTRING((10.0 5.0, 20.0 15.0),( 25.0 30.0, 30.0 20.0))</wkt>
|
||||
<wkt>SRID=0;MULTILINESTRING((10.0 5.0, 20.0 15.0),( 25.0 30.0, 30.0 20.0))</wkt>
|
||||
</Element>
|
||||
|
||||
<Element>
|
||||
<id>12</id>
|
||||
<type>MULTILINESTRING</type>
|
||||
<wkt>SRID=4326;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
|
||||
<wkt>SRID=0;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))
|
||||
</wkt>
|
||||
</Element>
|
||||
|
@ -66,28 +66,28 @@ In MySQL these are stored as null objects.
|
|||
<Element>
|
||||
<id>16</id>
|
||||
<type>POLYGON</type>
|
||||
<wkt>SRID=4326;POLYGON( (0 0, 0 10, 10 10, 10 0, 0 0) )</wkt>
|
||||
<wkt>SRID=0;POLYGON( (0 0, 0 10, 10 10, 10 0, 0 0) )</wkt>
|
||||
</Element>
|
||||
<Element>
|
||||
<id>18</id>
|
||||
<type>POLYGON</type>
|
||||
<wkt>SRID=4326;POLYGON( (0 0, 0 10, 10 10, 10 0, 0 0), (2 2, 2 5, 5 5,5 2, 2 2))</wkt>
|
||||
<wkt>SRID=0;POLYGON( (0 0, 0 10, 10 10, 10 0, 0 0), (2 2, 2 5, 5 5,5 2, 2 2))</wkt>
|
||||
</Element>
|
||||
<Element>
|
||||
<id>19</id>
|
||||
<type>POLYGON</type>
|
||||
<wkt>SRID=4326;POLYGON( (50 50, 50 70, 70 70, 70 50, 50 50) )</wkt>
|
||||
<wkt>SRID=0;POLYGON( (50 50, 50 70, 70 70, 70 50, 50 50) )</wkt>
|
||||
</Element>
|
||||
|
||||
<Element>
|
||||
<id>20</id>
|
||||
<type>MULTIPOLYGON</type>
|
||||
<wkt>SRID=4326;MULTIPOLYGON( ((10 20, 30 40, 44 50, 10 20)), ((55 50, 60 70, 70 78, 55 50)) )</wkt>
|
||||
<wkt>SRID=0;MULTIPOLYGON( ((10 20, 30 40, 44 50, 10 20)), ((55 50, 60 70, 70 78, 55 50)) )</wkt>
|
||||
</Element>
|
||||
<Element>
|
||||
<id>22</id>
|
||||
<type>MULTIPOLYGON</type>
|
||||
<wkt>SRID=4326;MULTIPOLYGON(( (0 0, 0 50, 50 50, 50 0, 0 0), (10 10, 10 20, 20 20, 20 10, 10 10) ),((15 10, 12
|
||||
<wkt>SRID=0;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)) )
|
||||
</wkt>
|
||||
|
@ -97,28 +97,28 @@ In MySQL these are stored as null objects.
|
|||
<Element>
|
||||
<id>25</id>
|
||||
<type>MULTIPOINT</type>
|
||||
<wkt>SRID=4326;MULTIPOINT(21 2, 25 5, 30 3)</wkt>
|
||||
<wkt>SRID=0;MULTIPOINT(21 2, 25 5, 30 3)</wkt>
|
||||
</Element>
|
||||
<Element>
|
||||
<id>26</id>
|
||||
<type>MULTIPOINT</type>
|
||||
<wkt>SRID=4326;MULTIPOINT(21 2)</wkt>
|
||||
<wkt>SRID=0;MULTIPOINT(21 2)</wkt>
|
||||
</Element>
|
||||
|
||||
<Element>
|
||||
<id>30</id>
|
||||
<type>GEOMETRYCOLLECTION</type>
|
||||
<wkt>SRID=4326;GEOMETRYCOLLECTION(POINT(4 0), LINESTRING(4 2, 5 3))</wkt>
|
||||
<wkt>SRID=0;GEOMETRYCOLLECTION(POINT(4 0), LINESTRING(4 2, 5 3))</wkt>
|
||||
</Element>
|
||||
<Element>
|
||||
<id>31</id>
|
||||
<type>GEOMETRYCOLLECTION</type>
|
||||
<wkt>SRID=4326;GEOMETRYCOLLECTION(POINT(4 0), LINESTRING(4 2, 5 3), POLYGON((0 0, 3 0, 3 3,0 3, 0 0)))</wkt>
|
||||
<wkt>SRID=0;GEOMETRYCOLLECTION(POINT(4 0), LINESTRING(4 2, 5 3), POLYGON((0 0, 3 0, 3 3,0 3, 0 0)))</wkt>
|
||||
</Element>
|
||||
<Element>
|
||||
<id>32</id>
|
||||
<type>GEOMETRYCOLLECTION</type>
|
||||
<wkt>SRID=4326;GEOMETRYCOLLECTION(POINT(4 0), LINESTRING(4 2, 5 3), POLYGON((0 0, 3 0, 3 3,0 3, 0 0),(1 1, 2 1,
|
||||
<wkt>SRID=0;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)))
|
||||
</wkt>
|
||||
|
@ -126,7 +126,7 @@ In MySQL these are stored as null objects.
|
|||
<Element>
|
||||
<id>33</id>
|
||||
<type>GEOMETRYCOLLECTION</type>
|
||||
<wkt>SRID=4326;GEOMETRYCOLLECTION( MULTIPOINT(21 2, 25 5, 30 3), MULTIPOLYGON( ((10 20, 30 40, 44 50, 10 20)),
|
||||
<wkt>SRID=0;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)))
|
||||
</wkt>
|
||||
|
|
Loading…
Reference in New Issue