HHH-10211 - Postgis Dialects for all PostgreSQLDialect classes
This commit is contained in:
parent
6024520e08
commit
70d55987f8
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
|
||||
/**
|
||||
* Registers all available spatial functions for a <code>Dialect</code>
|
||||
*
|
||||
* Created by Karel Maesen, Geovise BVBA on 29/10/16.
|
||||
*/
|
||||
public abstract class SpatialFunctionsRegistry implements Iterable<Map.Entry<String, StandardSQLFunction>> {
|
||||
protected final Map<String, StandardSQLFunction> functionMap = new HashMap<String, StandardSQLFunction>();
|
||||
|
||||
public void put(String name, StandardSQLFunction function ) {
|
||||
this.functionMap.put( name, function );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Map.Entry<String, StandardSQLFunction>> iterator() {
|
||||
return functionMap.entrySet().iterator();
|
||||
}
|
||||
|
||||
public SQLFunction get(String functionName) {
|
||||
return functionMap.get( functionName );
|
||||
}
|
||||
}
|
|
@ -6,11 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.spatial.dialect.mysql;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.spatial.dialect.SpatialFunctionsRegistry;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
||||
/**
|
||||
|
@ -19,113 +16,111 @@ import org.hibernate.type.StandardBasicTypes;
|
|||
* @author Karel Maesen, Geovise BVBA
|
||||
*
|
||||
*/
|
||||
class MySQLSpatialFunctions implements Iterable<Map.Entry<String, StandardSQLFunction>> {
|
||||
|
||||
private final Map<String, StandardSQLFunction> functionsToRegister = new HashMap<String, StandardSQLFunction>();
|
||||
class MySQLSpatialFunctions extends SpatialFunctionsRegistry {
|
||||
|
||||
MySQLSpatialFunctions(){
|
||||
functionsToRegister.put(
|
||||
functionMap.put(
|
||||
"dimension", new StandardSQLFunction(
|
||||
"dimension",
|
||||
StandardBasicTypes.INTEGER
|
||||
)
|
||||
);
|
||||
functionsToRegister.put(
|
||||
functionMap.put(
|
||||
"geometrytype", new StandardSQLFunction(
|
||||
"geometrytype", StandardBasicTypes.STRING
|
||||
)
|
||||
);
|
||||
functionsToRegister.put(
|
||||
functionMap.put(
|
||||
"srid", new StandardSQLFunction(
|
||||
"srid",
|
||||
StandardBasicTypes.INTEGER
|
||||
)
|
||||
);
|
||||
functionsToRegister.put(
|
||||
functionMap.put(
|
||||
"envelope", new StandardSQLFunction(
|
||||
"envelope"
|
||||
)
|
||||
);
|
||||
functionsToRegister.put(
|
||||
functionMap.put(
|
||||
"astext", new StandardSQLFunction(
|
||||
"astext",
|
||||
StandardBasicTypes.STRING
|
||||
)
|
||||
);
|
||||
functionsToRegister.put(
|
||||
functionMap.put(
|
||||
"asbinary", new StandardSQLFunction(
|
||||
"asbinary",
|
||||
StandardBasicTypes.BINARY
|
||||
)
|
||||
);
|
||||
functionsToRegister.put(
|
||||
functionMap.put(
|
||||
"isempty", new StandardSQLFunction(
|
||||
"isempty",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
functionsToRegister.put(
|
||||
functionMap.put(
|
||||
"issimple", new StandardSQLFunction(
|
||||
"issimple",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
// functionsToRegister.put(
|
||||
// functionMap.put(
|
||||
// "boundary", new StandardSQLFunction(
|
||||
// "boundary"
|
||||
// )
|
||||
// );
|
||||
|
||||
// Register functions for spatial relation constructs
|
||||
functionsToRegister.put(
|
||||
functionMap.put(
|
||||
"overlaps", new StandardSQLFunction(
|
||||
"overlaps",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
functionsToRegister.put(
|
||||
functionMap.put(
|
||||
"intersects", new StandardSQLFunction(
|
||||
"intersects",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
functionsToRegister.put(
|
||||
functionMap.put(
|
||||
"equals", new StandardSQLFunction(
|
||||
"equals",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
functionsToRegister.put(
|
||||
functionMap.put(
|
||||
"contains", new StandardSQLFunction(
|
||||
"contains",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
functionsToRegister.put(
|
||||
functionMap.put(
|
||||
"crosses", new StandardSQLFunction(
|
||||
"crosses",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
functionsToRegister.put(
|
||||
functionMap.put(
|
||||
"disjoint", new StandardSQLFunction(
|
||||
"disjoint",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
functionsToRegister.put(
|
||||
functionMap.put(
|
||||
"touches", new StandardSQLFunction(
|
||||
"touches",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
functionsToRegister.put(
|
||||
functionMap.put(
|
||||
"within", new StandardSQLFunction(
|
||||
"within",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
// functionsToRegister.put(
|
||||
// functionMap.put(
|
||||
// "relate", new StandardSQLFunction(
|
||||
// "relate",
|
||||
// StandardBasicTypes.BOOLEAN
|
||||
|
@ -133,50 +128,42 @@ class MySQLSpatialFunctions implements Iterable<Map.Entry<String, StandardSQLFun
|
|||
// );
|
||||
//
|
||||
// // register the spatial analysis functions
|
||||
// functionsToRegister.put(
|
||||
// functionMap.put(
|
||||
// "distance", new StandardSQLFunction(
|
||||
// "distance",
|
||||
// StandardBasicTypes.DOUBLE
|
||||
// )
|
||||
// );
|
||||
// functionsToRegister.put(
|
||||
// functionMap.put(
|
||||
// "buffer", new StandardSQLFunction(
|
||||
// "buffer"
|
||||
// )
|
||||
// );
|
||||
// functionsToRegister.put(
|
||||
// functionMap.put(
|
||||
// "convexhull", new StandardSQLFunction(
|
||||
// "convexhull"
|
||||
// )
|
||||
// );
|
||||
// functionsToRegister.put(
|
||||
// functionMap.put(
|
||||
// "difference", new StandardSQLFunction(
|
||||
// "difference"
|
||||
// )
|
||||
// );
|
||||
// functionsToRegister.put(
|
||||
// functionMap.put(
|
||||
// "intersection", new StandardSQLFunction(
|
||||
// "intersection"
|
||||
// )
|
||||
// );
|
||||
// functionsToRegister.put(
|
||||
// functionMap.put(
|
||||
// "symdifference", new StandardSQLFunction(
|
||||
// "symdifference"
|
||||
// )
|
||||
// );
|
||||
// functionsToRegister.put(
|
||||
// functionMap.put(
|
||||
// "geomunion", new StandardSQLFunction(
|
||||
// "union"
|
||||
// )
|
||||
// );
|
||||
}
|
||||
|
||||
public void put(String name, StandardSQLFunction function ) {
|
||||
this.functionsToRegister.put( name, function );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Map.Entry<String, StandardSQLFunction>> iterator() {
|
||||
return functionsToRegister.entrySet().iterator();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<!DOCTYPE html>
|
||||
<!--
|
||||
~ 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>.
|
||||
-->
|
||||
|
||||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
<p>
|
||||
This package contains the Spatial Dialects supported by Hibnerate Spatial
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
|
@ -7,313 +7,12 @@
|
|||
package org.hibernate.spatial.dialect.postgis;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.PostgreSQL82Dialect;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.GeolatteGeometryType;
|
||||
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.type.StandardBasicTypes;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* A Dialect for Postgresql with support for the Postgis spatial types, functions and operators (release 1.3 or higher)
|
||||
*
|
||||
* @author Karel Maesen
|
||||
* @deprecated "Use one of the PostgisPGNNDialect dialects"
|
||||
*/
|
||||
public class PostgisDialect extends PostgreSQL82Dialect implements SpatialDialect {
|
||||
|
||||
|
||||
/**
|
||||
* Creates an instance
|
||||
*/
|
||||
public PostgisDialect() {
|
||||
super();
|
||||
registerTypesAndFunctions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
super.contributeTypes(
|
||||
typeContributions,
|
||||
serviceRegistry
|
||||
);
|
||||
|
||||
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryTypeDescriptor.INSTANCE ) );
|
||||
typeContributions.contributeType( new JTSGeometryType( PGGeometryTypeDescriptor.INSTANCE ) );
|
||||
}
|
||||
|
||||
protected void registerTypesAndFunctions() {
|
||||
|
||||
registerColumnType(
|
||||
PGGeometryTypeDescriptor.INSTANCE.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
|
||||
// registering OGC functions
|
||||
// (spec_simplefeatures_sql_99-04.pdf)
|
||||
|
||||
// section 2.1.1.1
|
||||
// Registerfunction calls for registering geometry functions:
|
||||
// first argument is the OGC standard functionname, second the name as
|
||||
// it occurs in the spatial dialect
|
||||
registerFunction(
|
||||
"dimension", new StandardSQLFunction(
|
||||
"st_dimension",
|
||||
StandardBasicTypes.INTEGER
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"geometrytype", new StandardSQLFunction(
|
||||
"st_geometrytype", StandardBasicTypes.STRING
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"srid", new StandardSQLFunction(
|
||||
"st_srid",
|
||||
StandardBasicTypes.INTEGER
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"envelope", new StandardSQLFunction(
|
||||
"st_envelope"
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"astext", new StandardSQLFunction(
|
||||
"st_astext",
|
||||
StandardBasicTypes.STRING
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"asbinary", new StandardSQLFunction(
|
||||
"st_asbinary",
|
||||
StandardBasicTypes.BINARY
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"isempty", new StandardSQLFunction(
|
||||
"st_isempty",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"issimple", new StandardSQLFunction(
|
||||
"st_issimple",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"boundary", new StandardSQLFunction(
|
||||
"st_boundary"
|
||||
)
|
||||
);
|
||||
|
||||
// Register functions for spatial relation constructs
|
||||
registerFunction(
|
||||
"overlaps", new StandardSQLFunction(
|
||||
"st_overlaps",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"intersects", new StandardSQLFunction(
|
||||
"st_intersects",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"equals", new StandardSQLFunction(
|
||||
"st_equals",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"contains", new StandardSQLFunction(
|
||||
"st_contains",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"crosses", new StandardSQLFunction(
|
||||
"st_crosses",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"disjoint", new StandardSQLFunction(
|
||||
"st_disjoint",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"touches", new StandardSQLFunction(
|
||||
"st_touches",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"within", new StandardSQLFunction(
|
||||
"st_within",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"relate", new StandardSQLFunction(
|
||||
"st_relate",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
|
||||
// register the spatial analysis functions
|
||||
registerFunction(
|
||||
"distance", new StandardSQLFunction(
|
||||
"st_distance",
|
||||
StandardBasicTypes.DOUBLE
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"buffer", new StandardSQLFunction(
|
||||
"st_buffer"
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"convexhull", new StandardSQLFunction(
|
||||
"st_convexhull"
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"difference", new StandardSQLFunction(
|
||||
"st_difference"
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"intersection", new StandardSQLFunction(
|
||||
"st_intersection"
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"symdifference",
|
||||
new StandardSQLFunction( "st_symdifference" )
|
||||
);
|
||||
registerFunction(
|
||||
"geomunion", new StandardSQLFunction(
|
||||
"st_union"
|
||||
)
|
||||
);
|
||||
|
||||
//register Spatial Aggregate function
|
||||
registerFunction(
|
||||
"extent", new ExtentFunction()
|
||||
);
|
||||
|
||||
//other common functions
|
||||
registerFunction(
|
||||
"dwithin", new StandardSQLFunction(
|
||||
"st_dwithin",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"transform", new StandardSQLFunction(
|
||||
"st_transform"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@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"
|
||||
);
|
||||
}
|
||||
@Deprecated
|
||||
public class PostgisDialect extends PostgisPG82Dialect {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDWithinSQL(String columnName) {
|
||||
return "ST_DWithin(" + 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 String getSpatialFilterExpression(String columnName) {
|
||||
return "(" + columnName + " && ? ) ";
|
||||
}
|
||||
|
||||
@Override
|
||||
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"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsFiltering() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return (getFunctions().get( function.toString() ) != null);
|
||||
}
|
||||
|
||||
private static class ExtentFunction extends StandardSQLFunction {
|
||||
|
||||
public ExtentFunction() {
|
||||
super( "st_extent" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String render(
|
||||
Type firstArgumentType, List arguments, SessionFactoryImplementor sessionFactory) {
|
||||
String rendered = super.render( firstArgumentType, arguments, sessionFactory );
|
||||
//add cast
|
||||
return rendered + "::geometry";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,204 @@
|
|||
/*
|
||||
* 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 org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.spatial.dialect.SpatialFunctionsRegistry;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* Functions registered in all Postgis Dialects
|
||||
*
|
||||
* Created by Karel Maesen, Geovise BVBA on 29/10/16.
|
||||
*/
|
||||
class PostgisFunctions extends SpatialFunctionsRegistry {
|
||||
|
||||
PostgisFunctions() {
|
||||
|
||||
put(
|
||||
"dimension", new StandardSQLFunction(
|
||||
"st_dimension",
|
||||
StandardBasicTypes.INTEGER
|
||||
)
|
||||
);
|
||||
put(
|
||||
"geometrytype", new StandardSQLFunction(
|
||||
"st_geometrytype", StandardBasicTypes.STRING
|
||||
)
|
||||
);
|
||||
put(
|
||||
"srid", new StandardSQLFunction(
|
||||
"st_srid",
|
||||
StandardBasicTypes.INTEGER
|
||||
)
|
||||
);
|
||||
put(
|
||||
"envelope", new StandardSQLFunction(
|
||||
"st_envelope"
|
||||
)
|
||||
);
|
||||
put(
|
||||
"astext", new StandardSQLFunction(
|
||||
"st_astext",
|
||||
StandardBasicTypes.STRING
|
||||
)
|
||||
);
|
||||
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()
|
||||
);
|
||||
|
||||
//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 String render(
|
||||
Type firstArgumentType, List arguments, SessionFactoryImplementor sessionFactory) {
|
||||
String rendered = super.render( firstArgumentType, arguments, sessionFactory );
|
||||
//add cast
|
||||
return rendered + "::geometry";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,8 +20,7 @@ import org.hibernate.type.StandardBasicTypes;
|
|||
*/
|
||||
public class PostgisNoSQLMM extends PostgisDialect {
|
||||
|
||||
@Override
|
||||
protected void registerTypesAndFunctions() {
|
||||
public PostgisNoSQLMM() {
|
||||
|
||||
registerColumnType(
|
||||
PGGeometryTypeDescriptor.INSTANCE.getSqlType(),
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* 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.Map;
|
||||
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.PostgreSQL82Dialect;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
|
||||
/**
|
||||
* A Dialect for Postgresql with support for the Postgis spatial types, functions and operators (release 1.3 or higher).
|
||||
*
|
||||
* This dialect extends the PostgreSQL82Dialect.
|
||||
*
|
||||
* Created by Karel Maesen, Geovise BVBA on 01/11/16.
|
||||
*/
|
||||
public class PostgisPG82Dialect extends PostgreSQL82Dialect implements SpatialDialect {
|
||||
|
||||
|
||||
private PostgisSupport support = new PostgisSupport();
|
||||
|
||||
/**
|
||||
* Creates an instance
|
||||
*/
|
||||
public PostgisPG82Dialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
PGGeometryTypeDescriptor.INSTANCE.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, StandardSQLFunction> entry : support.functionsToRegister() ) {
|
||||
registerFunction( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
super.contributeTypes(
|
||||
typeContributions,
|
||||
serviceRegistry
|
||||
);
|
||||
support.contributeTypes( typeContributions, serviceRegistry );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
return support.getSpatialRelateSQL( columnName, spatialRelation );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDWithinSQL(String columnName) {
|
||||
return support.getDWithinSQL( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHavingSridSQL(String columnName) {
|
||||
return support.getHavingSridSQL( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
return support.getIsEmptySQL( columnName, isEmpty );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialFilterExpression(String columnName) {
|
||||
return support.getSpatialFilterExpression( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
return support.getSpatialAggregateSQL( columnName, aggregation );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsFiltering() {
|
||||
return support.supportsFiltering();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return support.supports( function );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* 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.Map;
|
||||
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.PostgreSQL91Dialect;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
|
||||
/**
|
||||
* Created by Karel Maesen, Geovise BVBA on 01/11/16.
|
||||
*/
|
||||
public class PostgisPG91Dialect extends PostgreSQL91Dialect implements SpatialDialect {
|
||||
|
||||
|
||||
private PostgisSupport support = new PostgisSupport();
|
||||
/**
|
||||
* Creates an instance
|
||||
*/
|
||||
public PostgisPG91Dialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
PGGeometryTypeDescriptor.INSTANCE.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, StandardSQLFunction> entry : support.functionsToRegister() ) {
|
||||
registerFunction( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
super.contributeTypes(
|
||||
typeContributions,
|
||||
serviceRegistry
|
||||
);
|
||||
support.contributeTypes( typeContributions, serviceRegistry );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
@Override
|
||||
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
return support.getSpatialRelateSQL( columnName, spatialRelation );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
@Override
|
||||
public String getSpatialFilterExpression(String columnName) {
|
||||
return support.getSpatialFilterExpression( 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
|
||||
*/
|
||||
@Override
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
return support.getSpatialAggregateSQL( columnName, aggregation );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>.
|
||||
*/
|
||||
@Override
|
||||
public String getDWithinSQL(String columnName) {
|
||||
return support.getDWithinSQL( columnName );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SQL fragment when parsing an <code>HavingSridExpression</code>.
|
||||
*
|
||||
* @param columnName The geometry column to test against
|
||||
*
|
||||
* @return The SQL fragment for an <code>HavingSridExpression</code>.
|
||||
*/
|
||||
@Override
|
||||
public String getHavingSridSQL(String columnName) {
|
||||
return support.getHavingSridSQL( 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
|
||||
*/
|
||||
@Override
|
||||
public String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
return support.getIsEmptySQL( columnName, isEmpty );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@Override
|
||||
public boolean supportsFiltering() {
|
||||
return support.supportsFiltering();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return support.supports( function );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* 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.Map;
|
||||
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.PostgreSQL92Dialect;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
|
||||
/**
|
||||
* Created by Karel Maesen, Geovise BVBA on 01/11/16.
|
||||
*/
|
||||
public class PostgisPG92Dialect extends PostgreSQL92Dialect implements SpatialDialect {
|
||||
|
||||
|
||||
private PostgisSupport support = new PostgisSupport();
|
||||
/**
|
||||
* Creates an instance
|
||||
*/
|
||||
public PostgisPG92Dialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
PGGeometryTypeDescriptor.INSTANCE.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, StandardSQLFunction> entry : support.functionsToRegister() ) {
|
||||
registerFunction( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
super.contributeTypes(
|
||||
typeContributions,
|
||||
serviceRegistry
|
||||
);
|
||||
support.contributeTypes( typeContributions, serviceRegistry );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
@Override
|
||||
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
return support.getSpatialRelateSQL( columnName, spatialRelation );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
@Override
|
||||
public String getSpatialFilterExpression(String columnName) {
|
||||
return support.getSpatialFilterExpression( 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
|
||||
*/
|
||||
@Override
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
return support.getSpatialAggregateSQL( columnName, aggregation );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>.
|
||||
*/
|
||||
@Override
|
||||
public String getDWithinSQL(String columnName) {
|
||||
return support.getDWithinSQL( columnName );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SQL fragment when parsing an <code>HavingSridExpression</code>.
|
||||
*
|
||||
* @param columnName The geometry column to test against
|
||||
*
|
||||
* @return The SQL fragment for an <code>HavingSridExpression</code>.
|
||||
*/
|
||||
@Override
|
||||
public String getHavingSridSQL(String columnName) {
|
||||
return support.getHavingSridSQL( 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
|
||||
*/
|
||||
@Override
|
||||
public String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
return support.getIsEmptySQL( columnName, isEmpty );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@Override
|
||||
public boolean supportsFiltering() {
|
||||
return support.supportsFiltering();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return support.supports( function );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* 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.Map;
|
||||
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.PostgreSQL93Dialect;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
|
||||
/**
|
||||
* Created by Karel Maesen, Geovise BVBA on 01/11/16.
|
||||
*/
|
||||
public class PostgisPG93Dialect extends PostgreSQL93Dialect implements SpatialDialect {
|
||||
|
||||
|
||||
private PostgisSupport support = new PostgisSupport();
|
||||
/**
|
||||
* Creates an instance
|
||||
*/
|
||||
public PostgisPG93Dialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
PGGeometryTypeDescriptor.INSTANCE.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, StandardSQLFunction> entry : support.functionsToRegister() ) {
|
||||
registerFunction( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
super.contributeTypes(
|
||||
typeContributions,
|
||||
serviceRegistry
|
||||
);
|
||||
support.contributeTypes( typeContributions, serviceRegistry );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
@Override
|
||||
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
return support.getSpatialRelateSQL( columnName, spatialRelation );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
@Override
|
||||
public String getSpatialFilterExpression(String columnName) {
|
||||
return support.getSpatialFilterExpression( 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
|
||||
*/
|
||||
@Override
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
return support.getSpatialAggregateSQL( columnName, aggregation );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>.
|
||||
*/
|
||||
@Override
|
||||
public String getDWithinSQL(String columnName) {
|
||||
return support.getDWithinSQL( columnName );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SQL fragment when parsing an <code>HavingSridExpression</code>.
|
||||
*
|
||||
* @param columnName The geometry column to test against
|
||||
*
|
||||
* @return The SQL fragment for an <code>HavingSridExpression</code>.
|
||||
*/
|
||||
@Override
|
||||
public String getHavingSridSQL(String columnName) {
|
||||
return support.getHavingSridSQL( 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
|
||||
*/
|
||||
@Override
|
||||
public String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
return support.getIsEmptySQL( columnName, isEmpty );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@Override
|
||||
public boolean supportsFiltering() {
|
||||
return support.supportsFiltering();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return support.supports( function );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* 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.Map;
|
||||
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.PostgreSQL94Dialect;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
|
||||
/**
|
||||
* Created by Karel Maesen, Geovise BVBA on 01/11/16.
|
||||
*/
|
||||
public class PostgisPG94Dialect extends PostgreSQL94Dialect implements SpatialDialect {
|
||||
|
||||
|
||||
private PostgisSupport support = new PostgisSupport();
|
||||
/**
|
||||
* Creates an instance
|
||||
*/
|
||||
public PostgisPG94Dialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
PGGeometryTypeDescriptor.INSTANCE.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, StandardSQLFunction> entry : support.functionsToRegister() ) {
|
||||
registerFunction( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
super.contributeTypes(
|
||||
typeContributions,
|
||||
serviceRegistry
|
||||
);
|
||||
support.contributeTypes( typeContributions, serviceRegistry );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
@Override
|
||||
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
return support.getSpatialRelateSQL( columnName, spatialRelation );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
@Override
|
||||
public String getSpatialFilterExpression(String columnName) {
|
||||
return support.getSpatialFilterExpression( 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
|
||||
*/
|
||||
@Override
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
return support.getSpatialAggregateSQL( columnName, aggregation );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>.
|
||||
*/
|
||||
@Override
|
||||
public String getDWithinSQL(String columnName) {
|
||||
return support.getDWithinSQL( columnName );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SQL fragment when parsing an <code>HavingSridExpression</code>.
|
||||
*
|
||||
* @param columnName The geometry column to test against
|
||||
*
|
||||
* @return The SQL fragment for an <code>HavingSridExpression</code>.
|
||||
*/
|
||||
@Override
|
||||
public String getHavingSridSQL(String columnName) {
|
||||
return support.getHavingSridSQL( 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
|
||||
*/
|
||||
@Override
|
||||
public String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
return support.getIsEmptySQL( columnName, isEmpty );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@Override
|
||||
public boolean supportsFiltering() {
|
||||
return support.supportsFiltering();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return support.supports( function );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* 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.Map;
|
||||
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.PostgreSQL95Dialect;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
|
||||
/**
|
||||
* Created by Karel Maesen, Geovise BVBA on 01/11/16.
|
||||
*/
|
||||
public class PostgisPG95Dialect extends PostgreSQL95Dialect implements SpatialDialect {
|
||||
|
||||
|
||||
private PostgisSupport support = new PostgisSupport();
|
||||
/**
|
||||
* Creates an instance
|
||||
*/
|
||||
public PostgisPG95Dialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
PGGeometryTypeDescriptor.INSTANCE.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, StandardSQLFunction> entry : support.functionsToRegister() ) {
|
||||
registerFunction( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
super.contributeTypes(
|
||||
typeContributions,
|
||||
serviceRegistry
|
||||
);
|
||||
support.contributeTypes( typeContributions, serviceRegistry );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
@Override
|
||||
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
return support.getSpatialRelateSQL( columnName, spatialRelation );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
@Override
|
||||
public String getSpatialFilterExpression(String columnName) {
|
||||
return support.getSpatialFilterExpression( 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
|
||||
*/
|
||||
@Override
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
return support.getSpatialAggregateSQL( columnName, aggregation );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>.
|
||||
*/
|
||||
@Override
|
||||
public String getDWithinSQL(String columnName) {
|
||||
return support.getDWithinSQL( columnName );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SQL fragment when parsing an <code>HavingSridExpression</code>.
|
||||
*
|
||||
* @param columnName The geometry column to test against
|
||||
*
|
||||
* @return The SQL fragment for an <code>HavingSridExpression</code>.
|
||||
*/
|
||||
@Override
|
||||
public String getHavingSridSQL(String columnName) {
|
||||
return support.getHavingSridSQL( 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
|
||||
*/
|
||||
@Override
|
||||
public String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
return support.getIsEmptySQL( columnName, isEmpty );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@Override
|
||||
public boolean supportsFiltering() {
|
||||
return support.supportsFiltering();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return support.supports( function );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* 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.Map;
|
||||
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.PostgreSQL9Dialect;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
|
||||
/**
|
||||
* Created by Karel Maesen, Geovise BVBA on 01/11/16.
|
||||
*/
|
||||
public class PostgisPG9Dialect extends PostgreSQL9Dialect implements SpatialDialect {
|
||||
|
||||
|
||||
private PostgisSupport support = new PostgisSupport();
|
||||
/**
|
||||
* Creates an instance
|
||||
*/
|
||||
public PostgisPG9Dialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
PGGeometryTypeDescriptor.INSTANCE.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, StandardSQLFunction> entry : support.functionsToRegister() ) {
|
||||
registerFunction( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
super.contributeTypes(
|
||||
typeContributions,
|
||||
serviceRegistry
|
||||
);
|
||||
support.contributeTypes( typeContributions, serviceRegistry );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
@Override
|
||||
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
return support.getSpatialRelateSQL( columnName, spatialRelation );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
@Override
|
||||
public String getSpatialFilterExpression(String columnName) {
|
||||
return support.getSpatialFilterExpression( 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
|
||||
*/
|
||||
@Override
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
return support.getSpatialAggregateSQL( columnName, aggregation );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>.
|
||||
*/
|
||||
@Override
|
||||
public String getDWithinSQL(String columnName) {
|
||||
return support.getDWithinSQL( columnName );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SQL fragment when parsing an <code>HavingSridExpression</code>.
|
||||
*
|
||||
* @param columnName The geometry column to test against
|
||||
*
|
||||
* @return The SQL fragment for an <code>HavingSridExpression</code>.
|
||||
*/
|
||||
@Override
|
||||
public String getHavingSridSQL(String columnName) {
|
||||
return support.getHavingSridSQL( 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
|
||||
*/
|
||||
@Override
|
||||
public String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
return support.getIsEmptySQL( columnName, isEmpty );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@Override
|
||||
public boolean supportsFiltering() {
|
||||
return support.supportsFiltering();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return support.supports( function );
|
||||
}
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.dialect.postgis;
|
||||
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.GeolatteGeometryType;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Created by Karel Maesen, Geovise BVBA on 29/10/16.
|
||||
*/
|
||||
public class PostgisSupport implements SpatialDialect {
|
||||
|
||||
|
||||
private PostgisFunctions postgisFunctions = new PostgisFunctions();
|
||||
|
||||
void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryTypeDescriptor.INSTANCE ) );
|
||||
typeContributions.contributeType( new JTSGeometryType( PGGeometryTypeDescriptor.INSTANCE ) );
|
||||
}
|
||||
|
||||
public PostgisFunctions functionsToRegister() {
|
||||
return postgisFunctions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
@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"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
@Override
|
||||
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
|
||||
*/
|
||||
@Override
|
||||
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>.
|
||||
*/
|
||||
@Override
|
||||
public String getDWithinSQL(String columnName) {
|
||||
return "ST_DWithin(" + columnName + ",?,?)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SQL fragment when parsing an <code>HavingSridExpression</code>.
|
||||
*
|
||||
* @param columnName The geometry column to test against
|
||||
*
|
||||
* @return The SQL fragment for an <code>HavingSridExpression</code>.
|
||||
*/
|
||||
@Override
|
||||
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
|
||||
*/
|
||||
@Override
|
||||
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
|
||||
*/
|
||||
@Override
|
||||
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.
|
||||
*/
|
||||
@Override
|
||||
public boolean supports( SpatialFunction function) {
|
||||
return (postgisFunctions.get( function.toString() ) != null);
|
||||
}
|
||||
}
|
|
@ -8,6 +8,8 @@
|
|||
package org.hibernate.spatial.testing;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.PostgreSQL82Dialect;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.testing.dialects.h2geodb.GeoDBTestSupport;
|
||||
import org.hibernate.spatial.testing.dialects.mysql.MySQL56TestSupport;
|
||||
import org.hibernate.spatial.testing.dialects.mysql.MySQLTestSupport;
|
||||
|
@ -51,7 +53,9 @@ public class TestSupportFactories {
|
|||
|
||||
private static Class<? extends TestSupport> getSupportFactoryClass(Dialect dialect) {
|
||||
String canonicalName = dialect.getClass().getCanonicalName();
|
||||
if ( "org.hibernate.spatial.dialect.postgis.PostgisDialect".equals( canonicalName ) ) {
|
||||
|
||||
if ( (dialect instanceof SpatialDialect) && PostgreSQL82Dialect.class.isAssignableFrom( dialect.getClass() ) ) {
|
||||
//this test works because all postgis dialects ultimately derive of the Postgresql82Dialect
|
||||
return PostgisTestSupport.class;
|
||||
}
|
||||
if ( "org.hibernate.spatial.dialect.h2geodb.GeoDBDialect".equals( canonicalName ) ) {
|
||||
|
|
Loading…
Reference in New Issue