HHH-14802 Update CockroachDB support for 6
This commit is contained in:
parent
bc44d65eb3
commit
9316c161c7
|
@ -192,7 +192,7 @@ The `GEOGRAPHY` type is not currently supported.
|
||||||
====
|
====
|
||||||
|
|
||||||
CockroachDB::
|
CockroachDB::
|
||||||
The dialect `CockroachDB202SpatialDialect` support the `GEOMETRY` type in CockroachDB v20.2 and later.
|
The dialect `CockroachDB202` support the `GEOMETRY` type in CockroachDB v20.2 and later.
|
||||||
|
|
||||||
[NOTE]
|
[NOTE]
|
||||||
====
|
====
|
||||||
|
|
|
@ -148,7 +148,7 @@ ext {
|
||||||
'connection.init_sql' : ''
|
'connection.init_sql' : ''
|
||||||
],
|
],
|
||||||
postgis : [
|
postgis : [
|
||||||
'db.dialect' : 'org.hibernate.dialect.PostgreSQLDialect',
|
'db.dialect' : 'org.hibernate.spatial.dialect.postgis.PostgisPG95Dialect',
|
||||||
'jdbc.driver': 'org.postgresql.Driver',
|
'jdbc.driver': 'org.postgresql.Driver',
|
||||||
'jdbc.user' : 'hibernate_orm_test',
|
'jdbc.user' : 'hibernate_orm_test',
|
||||||
'jdbc.pass' : 'hibernate_orm_test',
|
'jdbc.pass' : 'hibernate_orm_test',
|
||||||
|
|
|
@ -87,6 +87,9 @@ public class CockroachDialect extends Dialect {
|
||||||
registerColumnType( Types.NCLOB, "string" );
|
registerColumnType( Types.NCLOB, "string" );
|
||||||
|
|
||||||
registerColumnType( Types.JAVA_OBJECT, "json" );
|
registerColumnType( Types.JAVA_OBJECT, "json" );
|
||||||
|
|
||||||
|
//register geometry type
|
||||||
|
registerColumnType( 5432, "geometry" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -11,21 +11,24 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import org.hibernate.dialect.CockroachDialect;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.dialect.PostgreSQLDialect;
|
import org.hibernate.dialect.PostgreSQLDialect;
|
||||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
|
import org.hibernate.spatial.dialect.cockroachdb.CockroachDbContributor;
|
||||||
import org.hibernate.spatial.dialect.postgis.PostgisDialectContributor;
|
import org.hibernate.spatial.dialect.postgis.PostgisDialectContributor;
|
||||||
|
|
||||||
class ContributorResolver {
|
class ContributorResolver {
|
||||||
|
|
||||||
private final static Map<Class<? extends Dialect>,
|
private final static Map<Class<? extends Dialect>,
|
||||||
Function<ServiceRegistry, ContributorImplementor>> ContributorMap = new HashMap<>();
|
Function<ServiceRegistry, ContributorImplementor>> CONTRIBUTOR_MAP = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
//TypeContributorImplementor
|
//TypeContributorImplementor
|
||||||
ContributorMap.put( PostgreSQLDialect.class, PostgisDialectContributor::new );
|
CONTRIBUTOR_MAP.put( PostgreSQLDialect.class, PostgisDialectContributor::new );
|
||||||
|
CONTRIBUTOR_MAP.put( CockroachDialect.class, CockroachDbContributor::new );
|
||||||
}
|
}
|
||||||
|
|
||||||
private ContributorResolver() {
|
private ContributorResolver() {
|
||||||
|
@ -34,9 +37,9 @@ class ContributorResolver {
|
||||||
static ContributorImplementor resolveSpatialtypeContributorImplementor(ServiceRegistry serviceRegistry) {
|
static ContributorImplementor resolveSpatialtypeContributorImplementor(ServiceRegistry serviceRegistry) {
|
||||||
JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
|
JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
|
||||||
Dialect dialect = jdbcServices.getDialect();
|
Dialect dialect = jdbcServices.getDialect();
|
||||||
for ( Class<?> dialectClass : ContributorMap.keySet() ) {
|
for ( Class<?> dialectClass : CONTRIBUTOR_MAP.keySet() ) {
|
||||||
if ( dialectClass.isAssignableFrom( dialect.getClass() ) ) {
|
if ( dialectClass.isAssignableFrom( dialect.getClass() ) ) {
|
||||||
return ContributorMap.get( dialectClass ).apply( serviceRegistry );
|
return CONTRIBUTOR_MAP.get( dialectClass ).apply( serviceRegistry );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1,46 +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.cockroachdb;
|
|
||||||
|
|
||||||
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.dialect.postgis.PGGeometryTypeDescriptor;
|
|
||||||
import org.hibernate.spatial.dialect.postgis.PostgisFunctions;
|
|
||||||
import org.hibernate.spatial.dialect.postgis.PostgisSupport;
|
|
||||||
|
|
||||||
public class CockroachDBSpatialSupport extends PostgisSupport implements SpatialDialect {
|
|
||||||
|
|
||||||
CockroachDBSpatialSupport() {
|
|
||||||
super( new CockroachDBSpatialFunctions() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
|
||||||
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_2 ) );
|
|
||||||
typeContributions.contributeType( new JTSGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_2 ) );
|
|
||||||
|
|
||||||
typeContributions.contributeJavaTypeDescriptor( GeolatteGeometryJavaTypeDescriptor.INSTANCE );
|
|
||||||
typeContributions.contributeJavaTypeDescriptor( JTSGeometryJavaTypeDescriptor.INSTANCE );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class CockroachDBSpatialFunctions extends PostgisFunctions {
|
|
||||||
|
|
||||||
CockroachDBSpatialFunctions() {
|
|
||||||
super();
|
|
||||||
this.functionMap.remove( "geomunion" );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* 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.cockroachdb;
|
||||||
|
|
||||||
|
import org.hibernate.boot.model.TypeContributions;
|
||||||
|
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
|
||||||
|
import org.hibernate.service.ServiceRegistry;
|
||||||
|
import org.hibernate.spatial.FunctionKey;
|
||||||
|
import org.hibernate.spatial.GeolatteGeometryType;
|
||||||
|
import org.hibernate.spatial.HSMessageLogger;
|
||||||
|
import org.hibernate.spatial.JTSGeometryType;
|
||||||
|
import org.hibernate.spatial.contributor.ContributorImplementor;
|
||||||
|
import org.hibernate.spatial.dialect.postgis.PGGeometryTypeDescriptor;
|
||||||
|
import org.hibernate.spatial.dialect.postgis.PostgisSqmFunctionDescriptors;
|
||||||
|
|
||||||
|
public class CockroachDbContributor implements ContributorImplementor {
|
||||||
|
|
||||||
|
private final ServiceRegistry serviceRegistry;
|
||||||
|
|
||||||
|
public CockroachDbContributor(ServiceRegistry serviceRegistry) {
|
||||||
|
this.serviceRegistry = serviceRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contributeTypes(TypeContributions typeContributions) {
|
||||||
|
HSMessageLogger.LOGGER.typeContributions( this.getClass().getCanonicalName() );
|
||||||
|
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_2 ) );
|
||||||
|
typeContributions.contributeType( new JTSGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_2 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contributeFunctions(SqmFunctionRegistry functionRegistry) {
|
||||||
|
HSMessageLogger.LOGGER.functionContributions( this.getClass().getCanonicalName() );
|
||||||
|
PostgisSqmFunctionDescriptors postgisFunctions = new PostgisSqmFunctionDescriptors( getServiceRegistry() );
|
||||||
|
|
||||||
|
postgisFunctions.asMap()
|
||||||
|
.forEach( (key, desc) -> {
|
||||||
|
if ( isUnsupported( key ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
functionRegistry.register( key.getName(), desc );
|
||||||
|
key.getAltName().ifPresent( altName -> functionRegistry.registerAlternateKey(
|
||||||
|
altName,
|
||||||
|
key.getName()
|
||||||
|
) );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isUnsupported(FunctionKey key) {
|
||||||
|
return key.getName().equalsIgnoreCase( "st_union" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServiceRegistry getServiceRegistry() {
|
||||||
|
return this.serviceRegistry;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,82 +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.cockroachdb;
|
|
||||||
|
|
||||||
import org.hibernate.boot.model.TypeContributions;
|
|
||||||
import org.hibernate.service.ServiceRegistry;
|
|
||||||
import org.hibernate.spatial.SpatialDialect;
|
|
||||||
import org.hibernate.spatial.SpatialFunction;
|
|
||||||
import org.hibernate.spatial.dialect.SpatialFunctionsRegistry;
|
|
||||||
|
|
||||||
public interface CockroachSpatialDialectTrait extends SpatialDialect {
|
|
||||||
|
|
||||||
CockroachDBSpatialSupport DELEGATE = new CockroachDBSpatialSupport();
|
|
||||||
|
|
||||||
default SpatialFunctionsRegistry functionsToRegister() {
|
|
||||||
return DELEGATE.functionsToRegister();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
default String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
|
||||||
return DELEGATE.getSpatialRelateSQL( columnName, spatialRelation );
|
|
||||||
}
|
|
||||||
|
|
||||||
default void delegateContributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
|
||||||
DELEGATE.contributeTypes( typeContributions, serviceRegistry );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the SQL fragment for the SQL WHERE-expression when parsing
|
|
||||||
* <code>org.hibernate.spatial.criterion.SpatialFilterExpression</code>s
|
|
||||||
* into prepared statements.
|
|
||||||
*
|
|
||||||
* @param columnName The name of the geometry-typed column to which the filter is
|
|
||||||
* be applied
|
|
||||||
*
|
|
||||||
* @return Rhe SQL fragment for the {@code SpatialFilterExpression}
|
|
||||||
*/
|
|
||||||
default String getSpatialFilterExpression(String columnName) {
|
|
||||||
return DELEGATE.getSpatialFilterExpression( columnName );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
default String getSpatialAggregateSQL(String columnName, int aggregation) {
|
|
||||||
return DELEGATE.getSpatialAggregateSQL( columnName, aggregation );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
default String getDWithinSQL(String columnName) {
|
|
||||||
return DELEGATE.getDWithinSQL( columnName );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
default String getHavingSridSQL(String columnName) {
|
|
||||||
return DELEGATE.getHavingSridSQL( columnName );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
default String getIsEmptySQL(String columnName, boolean isEmpty) {
|
|
||||||
return DELEGATE.getIsEmptySQL( columnName, isEmpty );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
default boolean supportsFiltering() {
|
|
||||||
return DELEGATE.supportsFiltering();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
default boolean supports(SpatialFunction function) {
|
|
||||||
return DELEGATE.supports( function );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
default boolean isSpatial(int typeCode) {
|
|
||||||
return DELEGATE.isSpatial( typeCode );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -27,12 +27,8 @@ public class PostgisDialectContributor implements ContributorImplementor {
|
||||||
|
|
||||||
public void contributeTypes(TypeContributions typeContributions) {
|
public void contributeTypes(TypeContributions typeContributions) {
|
||||||
HSMessageLogger.LOGGER.typeContributions( this.getClass().getCanonicalName() );
|
HSMessageLogger.LOGGER.typeContributions( this.getClass().getCanonicalName() );
|
||||||
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_1 ) );
|
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_2 ) );
|
||||||
typeContributions.contributeType( new JTSGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_1 ) );
|
typeContributions.contributeType( new JTSGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_2 ) );
|
||||||
|
|
||||||
//Isn't this redundant?
|
|
||||||
typeContributions.contributeJavaTypeDescriptor( GeolatteGeometryJavaTypeDescriptor.INSTANCE );
|
|
||||||
typeContributions.contributeJavaTypeDescriptor( JTSGeometryJavaTypeDescriptor.INSTANCE );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,253 +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.postgis;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import org.hibernate.QueryException;
|
|
||||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|
||||||
import org.hibernate.query.sqm.function.NamedSqmFunctionDescriptor;
|
|
||||||
import org.hibernate.query.sqm.produce.function.ArgumentsValidator;
|
|
||||||
import org.hibernate.query.sqm.produce.function.NamedFunctionDescriptorBuilder;
|
|
||||||
import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators;
|
|
||||||
import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers;
|
|
||||||
import org.hibernate.spatial.SpatialFunction;
|
|
||||||
import org.hibernate.spatial.dialect.SpatialFunctionsRegistry;
|
|
||||||
import org.hibernate.sql.ast.SqlAstTranslator;
|
|
||||||
import org.hibernate.sql.ast.spi.SqlAppender;
|
|
||||||
import org.hibernate.sql.ast.tree.SqlAstNode;
|
|
||||||
import org.hibernate.sql.ast.tree.predicate.Predicate;
|
|
||||||
import org.hibernate.type.StandardBasicTypes;
|
|
||||||
import org.hibernate.type.Type;
|
|
||||||
|
|
||||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_ASTEXT;
|
|
||||||
import static org.hibernate.spatial.CommonSpatialFunction.ST_GEOMETRYTYPE;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Functions registered in all Postgis Dialects
|
|
||||||
* <p>
|
|
||||||
* Created by Karel Maesen, Geovise BVBA on 29/10/16.
|
|
||||||
* @deprecated replaced by DialectSpatialSqmFunctionDescriptors
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class PostgisFunctions extends SpatialFunctionsRegistry {
|
|
||||||
|
|
||||||
public PostgisFunctions() {
|
|
||||||
|
|
||||||
put(
|
|
||||||
"dimension", new StandardSQLFunction(
|
|
||||||
"st_dimension",
|
|
||||||
StandardBasicTypes.INTEGER
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
put(
|
|
||||||
"srid", new StandardSQLFunction(
|
|
||||||
"st_srid",
|
|
||||||
StandardBasicTypes.INTEGER
|
|
||||||
)
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"envelope", new StandardSQLFunction(
|
|
||||||
"st_envelope"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"makeenvelope", new StandardSQLFunction(
|
|
||||||
"st_makeenvelope"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
put(
|
|
||||||
"asbinary", new StandardSQLFunction(
|
|
||||||
"st_asbinary",
|
|
||||||
StandardBasicTypes.BINARY
|
|
||||||
)
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"isempty", new StandardSQLFunction(
|
|
||||||
"st_isempty",
|
|
||||||
StandardBasicTypes.BOOLEAN
|
|
||||||
)
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"issimple", new StandardSQLFunction(
|
|
||||||
"st_issimple",
|
|
||||||
StandardBasicTypes.BOOLEAN
|
|
||||||
)
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"boundary", new StandardSQLFunction(
|
|
||||||
"st_boundary"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Register functions for spatial relation constructs
|
|
||||||
put(
|
|
||||||
"overlaps", new StandardSQLFunction(
|
|
||||||
"st_overlaps",
|
|
||||||
StandardBasicTypes.BOOLEAN
|
|
||||||
)
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"intersects", new StandardSQLFunction(
|
|
||||||
"st_intersects",
|
|
||||||
StandardBasicTypes.BOOLEAN
|
|
||||||
)
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"equals", new StandardSQLFunction(
|
|
||||||
"st_equals",
|
|
||||||
StandardBasicTypes.BOOLEAN
|
|
||||||
)
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"contains", new StandardSQLFunction(
|
|
||||||
"st_contains",
|
|
||||||
StandardBasicTypes.BOOLEAN
|
|
||||||
)
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"crosses", new StandardSQLFunction(
|
|
||||||
"st_crosses",
|
|
||||||
StandardBasicTypes.BOOLEAN
|
|
||||||
)
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"disjoint", new StandardSQLFunction(
|
|
||||||
"st_disjoint",
|
|
||||||
StandardBasicTypes.BOOLEAN
|
|
||||||
)
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"touches", new StandardSQLFunction(
|
|
||||||
"st_touches",
|
|
||||||
StandardBasicTypes.BOOLEAN
|
|
||||||
)
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"within", new StandardSQLFunction(
|
|
||||||
"st_within",
|
|
||||||
StandardBasicTypes.BOOLEAN
|
|
||||||
)
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"relate", new StandardSQLFunction(
|
|
||||||
"st_relate",
|
|
||||||
StandardBasicTypes.BOOLEAN
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// register the spatial analysis functions
|
|
||||||
put(
|
|
||||||
"distance", new StandardSQLFunction(
|
|
||||||
"st_distance",
|
|
||||||
StandardBasicTypes.DOUBLE
|
|
||||||
)
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"buffer", new StandardSQLFunction( "st_buffer"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"convexhull", new StandardSQLFunction(
|
|
||||||
"st_convexhull"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"difference", new StandardSQLFunction(
|
|
||||||
"st_difference"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"intersection", new StandardSQLFunction(
|
|
||||||
"st_intersection"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"symdifference",
|
|
||||||
new StandardSQLFunction( "st_symdifference" )
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"geomunion", new StandardSQLFunction(
|
|
||||||
"st_union"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
//register Spatial Aggregate function
|
|
||||||
put(
|
|
||||||
"extent", new ExtentFunction()
|
|
||||||
);
|
|
||||||
|
|
||||||
// //register Spatial Filter function
|
|
||||||
// put(
|
|
||||||
// SpatialFunction.filter.name(), new FilterFunction()
|
|
||||||
// );
|
|
||||||
|
|
||||||
//other common functions
|
|
||||||
put(
|
|
||||||
"dwithin", new StandardSQLFunction(
|
|
||||||
"st_dwithin",
|
|
||||||
StandardBasicTypes.BOOLEAN
|
|
||||||
)
|
|
||||||
);
|
|
||||||
put(
|
|
||||||
"transform", new StandardSQLFunction(
|
|
||||||
"st_transform"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ExtentFunction extends StandardSQLFunction {
|
|
||||||
|
|
||||||
public ExtentFunction() {
|
|
||||||
super( "st_extent" );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(
|
|
||||||
SqlAppender sqlAppender,
|
|
||||||
List<SqlAstNode> sqlAstArguments,
|
|
||||||
Predicate filter,
|
|
||||||
SqlAstTranslator<?> translator) {
|
|
||||||
super.render( sqlAppender, sqlAstArguments, filter, translator );
|
|
||||||
sqlAppender.appendSql( "::geometry" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// private static class FilterFunction extends StandardSQLFunction {
|
|
||||||
//
|
|
||||||
// public FilterFunction() {
|
|
||||||
// super( "&&" );
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public String render(
|
|
||||||
// Type firstArgumentType, List arguments, SessionFactoryImplementor sessionFactory) {
|
|
||||||
// int argumentCount = arguments.size();
|
|
||||||
// if ( argumentCount != 2 ) {
|
|
||||||
// throw new QueryException( String.format(
|
|
||||||
// Locale.ENGLISH,
|
|
||||||
// "2 arguments expected, received %d",
|
|
||||||
// argumentCount
|
|
||||||
// ) );
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return Stream.of(
|
|
||||||
// String.valueOf( arguments.get( 0 ) ),
|
|
||||||
// getRenderedName( arguments ),
|
|
||||||
// String.valueOf( arguments.get( 1 ) )
|
|
||||||
// ).collect( Collectors.joining( " ", "(", ")" ) );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
|
|
@ -11,11 +11,16 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.boot.model.TypeContributions;
|
import org.hibernate.boot.model.TypeContributions;
|
||||||
import org.hibernate.dialect.PostgreSQLDialect;
|
import org.hibernate.dialect.PostgreSQLDialect;
|
||||||
|
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class PostgisPG10Dialect extends PostgreSQLDialect {
|
public class PostgisPG10Dialect extends PostgreSQLDialect {
|
||||||
|
|
||||||
|
public PostgisPG10Dialect(DialectResolutionInfo resolutionInfo) {
|
||||||
|
super( resolutionInfo );
|
||||||
|
}
|
||||||
|
|
||||||
public PostgisPG10Dialect() {
|
public PostgisPG10Dialect() {
|
||||||
super( 100 );
|
super( 100 );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +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.postgis;
|
|
||||||
|
|
||||||
import org.hibernate.dialect.PostgreSQLDialect;
|
|
||||||
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extends the {@code PostgreSQL91Dialect} to add support for the Postgis spatial types, functions and operators .
|
|
||||||
* <p>
|
|
||||||
* Created by Karel Maesen, Geovise BVBA on 01/11/16.
|
|
||||||
*
|
|
||||||
* @deprecated A SpatialDialect is no longer required. Use the standard Dialect for this database.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class PostgisPG91Dialect extends PostgreSQLDialect {
|
|
||||||
public PostgisPG91Dialect(DialectResolutionInfo info) {
|
|
||||||
super( info );
|
|
||||||
}
|
|
||||||
|
|
||||||
public PostgisPG91Dialect() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public PostgisPG91Dialect(int version) {
|
|
||||||
super( version );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,34 +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.postgis;
|
|
||||||
|
|
||||||
import org.hibernate.dialect.PostgreSQL92Dialect;
|
|
||||||
import org.hibernate.dialect.PostgreSQLDialect;
|
|
||||||
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
|
|
||||||
import org.hibernate.spatial.SpatialDialect;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extends the {@code PostgreSQL92Dialect} to add support for the Postgis spatial types, functions and operators .
|
|
||||||
* <p>
|
|
||||||
* Created by Karel Maesen, Geovise BVBA on 01/11/16.
|
|
||||||
*
|
|
||||||
* @deprecated A SpatialDialect is no longer required. Use the standard Dialect for this database.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class PostgisPG92Dialect extends PostgreSQLDialect {
|
|
||||||
public PostgisPG92Dialect(DialectResolutionInfo info) {
|
|
||||||
super( info );
|
|
||||||
}
|
|
||||||
|
|
||||||
public PostgisPG92Dialect() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public PostgisPG92Dialect(int version) {
|
|
||||||
super( version );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,31 +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.postgis;
|
|
||||||
|
|
||||||
import org.hibernate.dialect.PostgreSQLDialect;
|
|
||||||
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* * Extends the {@code PostgreSQL9Dialect} to add support for the Postgis spatial types, functions and operators .
|
|
||||||
* <p>
|
|
||||||
* Created by Karel Maesen, Geovise BVBA on 01/11/16.
|
|
||||||
*
|
|
||||||
* @deprecated A SpatialDialect is no longer required. Use the standard Dialect for this database.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class PostgisPG9Dialect extends PostgreSQLDialect {
|
|
||||||
public PostgisPG9Dialect(DialectResolutionInfo info) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public PostgisPG9Dialect() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public PostgisPG9Dialect(int version) {
|
|
||||||
super( version );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -28,7 +28,7 @@ public class PostgisSqmFunctionDescriptors implements KeyedSqmFunctionDescriptor
|
||||||
|
|
||||||
private final Map<FunctionKey, SqmFunctionDescriptor> map = new HashMap<>();
|
private final Map<FunctionKey, SqmFunctionDescriptor> map = new HashMap<>();
|
||||||
|
|
||||||
PostgisSqmFunctionDescriptors(ServiceRegistry serviceRegistry) {
|
public PostgisSqmFunctionDescriptors(ServiceRegistry serviceRegistry) {
|
||||||
Arrays.stream( values() )
|
Arrays.stream( values() )
|
||||||
.forEach( cf -> map.put( cf.getKey(), toPGFunction( cf ) ) );
|
.forEach( cf -> map.put( cf.getKey(), toPGFunction( cf ) ) );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,196 +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.postgis;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.sql.Types;
|
|
||||||
|
|
||||||
import org.hibernate.annotations.Remove;
|
|
||||||
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.SpatialAggregate;
|
|
||||||
import org.hibernate.spatial.SpatialDialect;
|
|
||||||
import org.hibernate.spatial.SpatialFunction;
|
|
||||||
import org.hibernate.spatial.SpatialRelation;
|
|
||||||
import org.hibernate.spatial.dialect.SpatialFunctionsRegistry;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Karel Maesen, Geovise BVBA on 29/10/16.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class PostgisSupport implements SpatialDialect, Serializable {
|
|
||||||
|
|
||||||
private final SpatialFunctionsRegistry postgisFunctions;
|
|
||||||
|
|
||||||
public PostgisSupport(SpatialFunctionsRegistry functions) {
|
|
||||||
postgisFunctions = functions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PostgisSupport() {
|
|
||||||
postgisFunctions = new PostgisFunctions();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
|
||||||
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_1 ) );
|
|
||||||
typeContributions.contributeType( new JTSGeometryType( PGGeometryTypeDescriptor.INSTANCE_WKB_1 ) );
|
|
||||||
|
|
||||||
typeContributions.contributeJavaTypeDescriptor( GeolatteGeometryJavaTypeDescriptor.INSTANCE );
|
|
||||||
typeContributions.contributeJavaTypeDescriptor( JTSGeometryJavaTypeDescriptor.INSTANCE );
|
|
||||||
}
|
|
||||||
|
|
||||||
public SpatialFunctionsRegistry functionsToRegister() {
|
|
||||||
return postgisFunctions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSpatial(int typeCode){
|
|
||||||
return typeCode == Types.OTHER || typeCode == PGGeometryTypeDescriptor.INSTANCE_WKB_1.getJdbcTypeCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the SQL fragment for the SQL WHERE-clause when parsing
|
|
||||||
* <code>org.hibernatespatial.criterion.SpatialRelateExpression</code>s
|
|
||||||
* into prepared statements.
|
|
||||||
* <p/>
|
|
||||||
*
|
|
||||||
* @param columnName The name of the geometry-typed column to which the relation is
|
|
||||||
* applied
|
|
||||||
* @param spatialRelation The type of spatial relation (as defined in
|
|
||||||
* <code>SpatialRelation</code>).
|
|
||||||
*
|
|
||||||
* @return SQL fragment {@code SpatialRelateExpression}
|
|
||||||
*/
|
|
||||||
|
|
||||||
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"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the SQL fragment for the SQL WHERE-expression when parsing
|
|
||||||
* <code>org.hibernate.spatial.criterion.SpatialFilterExpression</code>s
|
|
||||||
* into prepared statements.
|
|
||||||
*
|
|
||||||
* @param columnName The name of the geometry-typed column to which the filter is
|
|
||||||
* be applied
|
|
||||||
*
|
|
||||||
* @return Rhe SQL fragment for the {@code SpatialFilterExpression}
|
|
||||||
*/
|
|
||||||
|
|
||||||
public String getSpatialFilterExpression(String columnName) {
|
|
||||||
return "(" + columnName + " && ? ) ";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the SQL fragment for the specfied Spatial aggregate expression.
|
|
||||||
*
|
|
||||||
* @param columnName The name of the Geometry property
|
|
||||||
* @param aggregation The type of <code>SpatialAggregate</code>
|
|
||||||
*
|
|
||||||
* @return The SQL fragment for the projection
|
|
||||||
*/
|
|
||||||
|
|
||||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
|
||||||
switch ( aggregation ) {
|
|
||||||
case SpatialAggregate.EXTENT:
|
|
||||||
final StringBuilder stbuf = new StringBuilder();
|
|
||||||
stbuf.append( "st_extent(" ).append( columnName ).append( ")::geometry" );
|
|
||||||
return stbuf.toString();
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Aggregation of type "
|
|
||||||
+ aggregation + " are not supported by this dialect"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns The SQL fragment when parsing a <code>DWithinExpression</code>.
|
|
||||||
*
|
|
||||||
* @param columnName The geometry column to test against
|
|
||||||
*
|
|
||||||
* @return The SQL fragment when parsing a <code>DWithinExpression</code>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public String getDWithinSQL(String columnName) {
|
|
||||||
return "ST_DWithin(" + columnName + ",?,?)";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the SQL fragment when parsing a <code>HavingSridExpression</code>.
|
|
||||||
*
|
|
||||||
* @param columnName The geometry column to test against
|
|
||||||
*
|
|
||||||
* @return The SQL fragment for a <code>HavingSridExpression</code>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public String getHavingSridSQL(String columnName) {
|
|
||||||
return "( ST_srid(" + columnName + ") = ?)";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the SQL fragment when parsing a <code>IsEmptyExpression</code> or
|
|
||||||
* <code>IsNotEmpty</code> expression.
|
|
||||||
*
|
|
||||||
* @param columnName The geometry column
|
|
||||||
* @param isEmpty Whether the geometry is tested for empty or non-empty
|
|
||||||
*
|
|
||||||
* @return The SQL fragment for the isempty function
|
|
||||||
*/
|
|
||||||
|
|
||||||
public String getIsEmptySQL(String columnName, boolean isEmpty) {
|
|
||||||
final String emptyExpr = " ST_IsEmpty(" + columnName + ") ";
|
|
||||||
return isEmpty ? emptyExpr : "( NOT " + emptyExpr + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if this <code>SpatialDialect</code> supports a specific filtering function.
|
|
||||||
* <p> This is intended to signal DB-support for fast window queries, or MBR-overlap queries.</p>
|
|
||||||
*
|
|
||||||
* @return True if filtering is supported
|
|
||||||
*/
|
|
||||||
|
|
||||||
public boolean supportsFiltering() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Does this dialect supports the specified <code>SpatialFunction</code>.
|
|
||||||
*
|
|
||||||
* @param function <code>SpatialFunction</code>
|
|
||||||
*
|
|
||||||
* @return True if this <code>SpatialDialect</code> supports the spatial function specified by the function parameter.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public boolean supports(SpatialFunction function) {
|
|
||||||
return ( postgisFunctions.get( function.toString() ) != null );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -20,8 +20,6 @@ import javax.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
|
||||||
import org.hibernate.dialect.PostgreSQLDialect;
|
import org.hibernate.dialect.PostgreSQLDialect;
|
||||||
import org.hibernate.spatial.GeolatteGeometryType;
|
|
||||||
import org.hibernate.spatial.dialect.postgis.PostgisPG95Dialect;
|
|
||||||
|
|
||||||
import org.hibernate.testing.RequiresDialect;
|
import org.hibernate.testing.RequiresDialect;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
@ -30,7 +28,6 @@ import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.geolatte.geom.C2D;
|
import org.geolatte.geom.C2D;
|
||||||
import org.geolatte.geom.Geometry;
|
|
||||||
import org.geolatte.geom.Point;
|
import org.geolatte.geom.Point;
|
||||||
import org.geolatte.geom.Polygon;
|
import org.geolatte.geom.Polygon;
|
||||||
import org.geolatte.geom.crs.CoordinateReferenceSystem;
|
import org.geolatte.geom.crs.CoordinateReferenceSystem;
|
||||||
|
|
|
@ -11,6 +11,8 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -53,6 +55,7 @@ public class TestSpatialSchemaGeneration {
|
||||||
.execute( EnumSet.of( TargetType.SCRIPT ), SchemaExport.Action.BOTH, metadata );
|
.execute( EnumSet.of( TargetType.SCRIPT ), SchemaExport.Action.BOTH, metadata );
|
||||||
final List<String> sqlLines = Files.readAllLines( output.toPath(), Charset.defaultCharset() );
|
final List<String> sqlLines = Files.readAllLines( output.toPath(), Charset.defaultCharset() );
|
||||||
String result = sqlLines.stream().collect( Collectors.joining( " " ) ).toLowerCase( Locale.ROOT );
|
String result = sqlLines.stream().collect( Collectors.joining( " " ) ).toLowerCase( Locale.ROOT );
|
||||||
assertThat( result, stringContainsInOrder( List.of( "geometry", "geom" ) ) );
|
Iterable<String> geomElems = Arrays.asList( "geometry", "geom" );
|
||||||
|
assertThat( result, stringContainsInOrder( geomElems ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ package org.hibernate.spatial.integration.functions;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.hibernate.spatial.integration.SpatialTestDataProvider;
|
import org.hibernate.spatial.integration.SpatialTestDataProvider;
|
||||||
|
@ -55,12 +56,22 @@ public class CommonFunctionTests extends SpatialTestDataProvider
|
||||||
implements SessionFactoryScopeAware {
|
implements SessionFactoryScopeAware {
|
||||||
|
|
||||||
private SessionFactoryScope scope;
|
private SessionFactoryScope scope;
|
||||||
|
private Set<String> supportedFunctions;
|
||||||
List received;
|
List received;
|
||||||
List expected;
|
List expected;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectSessionFactoryScope(SessionFactoryScope scope) {
|
public void injectSessionFactoryScope(SessionFactoryScope scope) {
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
|
//scope is set to null during test cleanup
|
||||||
|
if ( scope != null ) {
|
||||||
|
this.supportedFunctions = scope.getSessionFactory()
|
||||||
|
.getQueryEngine()
|
||||||
|
.getSqmFunctionRegistry()
|
||||||
|
.getFunctions()
|
||||||
|
.keySet();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
|
@ -84,9 +95,10 @@ public class CommonFunctionTests extends SpatialTestDataProvider
|
||||||
|
|
||||||
@TestFactory
|
@TestFactory
|
||||||
public Stream<DynamicTest> testFunction() {
|
public Stream<DynamicTest> testFunction() {
|
||||||
|
|
||||||
return
|
return
|
||||||
TestTemplates.all( templates, hqlOverrides )
|
TestTemplates.all( templates, hqlOverrides )
|
||||||
// TODO -- filter for supported functions
|
.filter( this::isSupported )
|
||||||
.flatMap( t -> Stream.of(
|
.flatMap( t -> Stream.of(
|
||||||
t.build( Model.JTSMODEL, codec ),
|
t.build( Model.JTSMODEL, codec ),
|
||||||
t.build( Model.GLMODEL, codec )
|
t.build( Model.GLMODEL, codec )
|
||||||
|
@ -95,6 +107,10 @@ public class CommonFunctionTests extends SpatialTestDataProvider
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isSupported(FunctionTestTemplate.Builder builder) {
|
||||||
|
return supportedFunctions.contains( builder.function.name() );
|
||||||
|
}
|
||||||
|
|
||||||
protected Stream<DynamicTest> buildTests(FunctionTestTemplate template) {
|
protected Stream<DynamicTest> buildTests(FunctionTestTemplate template) {
|
||||||
return Stream.of(
|
return Stream.of(
|
||||||
template.getFunctionName(),
|
template.getFunctionName(),
|
||||||
|
|
|
@ -17,15 +17,15 @@ import java.util.Objects;
|
||||||
public interface RowObjectMapper<T> {
|
public interface RowObjectMapper<T> {
|
||||||
default Data apply(Object obj) {
|
default Data apply(Object obj) {
|
||||||
Object[] row = (Object[]) obj;
|
Object[] row = (Object[]) obj;
|
||||||
return new Data( (Integer) row[0], (T) row[1] );
|
return new Data( (Number) row[0], (T) row[1] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Data {
|
class Data {
|
||||||
final Integer id;
|
final Number id;
|
||||||
Object datum;
|
Object datum;
|
||||||
|
|
||||||
Data(Integer id, Object datum) {
|
Data(Number id, Object datum) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.datum = datum;
|
this.datum = datum;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ class Data {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Data data = (Data) o;
|
Data data = (Data) o;
|
||||||
return Objects.equals( id, data.id ) && isEquals( datum, data.datum );
|
return Objects.equals( id.intValue(), data.id.intValue() ) && isEquals( datum, data.datum );
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEquals(Object thisDatum, Object thatDatum) {
|
private boolean isEquals(Object thisDatum, Object thatDatum) {
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class RequireFunctionExtension implements ExecutionCondition {
|
||||||
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
|
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
|
||||||
Optional<Object> testInstance = context.getTestInstance();
|
Optional<Object> testInstance = context.getTestInstance();
|
||||||
|
|
||||||
if ( testInstance.isEmpty() ) {
|
if ( !testInstance.isPresent() ) {
|
||||||
return ENABLED;
|
return ENABLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class TestSupportFactories {
|
||||||
return MariaDBTestSupport.class;
|
return MariaDBTestSupport.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( dialect instanceof SpatialDialect ) && CockroachDialect.class.isAssignableFrom( dialect.getClass() ) ) {
|
if ( CockroachDialect.class.isAssignableFrom( dialect.getClass() ) ) {
|
||||||
return CockroachDBTestSupport.class;
|
return CockroachDBTestSupport.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,24 @@
|
||||||
|
|
||||||
package org.hibernate.spatial.testing.dialects.cockroachdb;
|
package org.hibernate.spatial.testing.dialects.cockroachdb;
|
||||||
|
|
||||||
|
import org.hibernate.spatial.GeomCodec;
|
||||||
|
import org.hibernate.spatial.dialect.postgis.PGGeometryTypeDescriptor;
|
||||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||||
import org.hibernate.spatial.testing.datareader.TestData;
|
import org.hibernate.spatial.testing.datareader.TestData;
|
||||||
import org.hibernate.spatial.testing.datareader.TestSupport;
|
import org.hibernate.spatial.testing.datareader.TestSupport;
|
||||||
|
import org.hibernate.spatial.testing.dialects.NativeSQLTemplates;
|
||||||
|
import org.hibernate.spatial.testing.dialects.postgis.PostgisNativeSQLTemplates;
|
||||||
|
|
||||||
|
import org.geolatte.geom.Geometry;
|
||||||
|
import org.geolatte.geom.codec.Wkt;
|
||||||
|
|
||||||
public class CockroachDBTestSupport extends TestSupport {
|
public class CockroachDBTestSupport extends TestSupport {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NativeSQLTemplates templates() {
|
||||||
|
return new PostgisNativeSQLTemplates();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TestData createTestData(TestDataPurpose purpose) {
|
public TestData createTestData(TestDataPurpose purpose) {
|
||||||
switch ( purpose ) {
|
switch ( purpose ) {
|
||||||
|
@ -23,4 +35,18 @@ public class CockroachDBTestSupport extends TestSupport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GeomCodec codec() {
|
||||||
|
return new GeomCodec() {
|
||||||
|
@Override
|
||||||
|
public Geometry<?> toGeometry(Object in) {
|
||||||
|
return PGGeometryTypeDescriptor.INSTANCE_WKB_2.toGeometry( in );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object fromGeometry(Geometry<?> in) {
|
||||||
|
return Wkt.toWkt( in, Wkt.Dialect.POSTGIS_EWKT_1 );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class PostgisTestSupport extends TestSupport {
|
||||||
return new GeomCodec() {
|
return new GeomCodec() {
|
||||||
@Override
|
@Override
|
||||||
public Geometry<?> toGeometry(Object in) {
|
public Geometry<?> toGeometry(Object in) {
|
||||||
return PGGeometryTypeDescriptor.INSTANCE_WKB_1.toGeometry( in );
|
return PGGeometryTypeDescriptor.INSTANCE_WKB_2.toGeometry( in );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
#
|
#
|
||||||
# Default unit/integration test config.
|
# Default unit/integration test config.
|
||||||
|
|
||||||
hibernate.dialect @db.dialect@
|
hibernate.dialect @db.dialect@
|
||||||
hibernate.connection.driver_class @jdbc.driver@
|
hibernate.connection.driver_class @jdbc.driver@
|
||||||
hibernate.connection.url @jdbc.url@
|
hibernate.connection.url @jdbc.url@
|
||||||
|
@ -27,12 +26,15 @@ hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFa
|
||||||
#hibernate.jdbc.batch_versioned_data true
|
#hibernate.jdbc.batch_versioned_data true
|
||||||
## Configs for spatial databases (used during testing on local dev environment).
|
## Configs for spatial databases (used during testing on local dev environment).
|
||||||
#
|
#
|
||||||
# hibernate.dialect org.hibernate.dialect.PostgreSQLDialect
|
#hibernate.dialect org.hibernate.spatial.dialect.postgis.PostgisPG95Dialect
|
||||||
# hibernate.connection.driver_class org.postgresql.Driver
|
|
||||||
# hibernate.connection.url jdbc:postgresql://localhost:5432/hibernate_orm_test?preparedStatementCacheQueries=0
|
#hibernate.dialect org.hibernate.dialect.PostgreSQLDialect
|
||||||
# hibernate.connection.username hibernate_orm_test
|
#hibernate.connection.driver_class org.postgresql.Driver
|
||||||
hibernate.connection.password hibernate_orm_test
|
#hibernate.connection.url jdbc:postgresql://localhost:5432/hibernate_orm_test?preparedStatementCacheQueries=0
|
||||||
##
|
#hibernate.connection.username hibernate_orm_test
|
||||||
|
#hibernate.connection.password hibernate_orm_test
|
||||||
|
|
||||||
|
>>>>>>> 5aae4945cb (Update CockroachDB support for 6)
|
||||||
## GeoDb (H2 spatial extension)
|
## GeoDb (H2 spatial extension)
|
||||||
##
|
##
|
||||||
#hibernate.dialect org.hibernate.spatial.dialect.h2geodb.GeoDBDialect
|
#hibernate.dialect org.hibernate.spatial.dialect.h2geodb.GeoDBDialect
|
||||||
|
@ -104,3 +106,12 @@ hibernate.connection.password hibernate_orm_test
|
||||||
#hibernate.spatial.db2.srid 4326
|
#hibernate.spatial.db2.srid 4326
|
||||||
#hibernate.connection.username db2inst1
|
#hibernate.connection.username db2inst1
|
||||||
#hibernate.connection.password dbinst1-pwd
|
#hibernate.connection.password dbinst1-pwd
|
||||||
|
|
||||||
|
##
|
||||||
|
## CockroachDB
|
||||||
|
##
|
||||||
|
#hibernate.dialect org.hibernate.dialect.CockroachDialect
|
||||||
|
#hibernate.connection.driver_class org.postgresql.Driver
|
||||||
|
#hibernate.connection.url jdbc:postgresql://localhost:26257/defaultdb?sslmode=disable&preparedStatementCacheQueries=0
|
||||||
|
#hibernate.connection.username root
|
||||||
|
#hibernate.connection.password
|
Loading…
Reference in New Issue