diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/SpatialFunctionsRegistry.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/SpatialFunctionsRegistry.java new file mode 100644 index 0000000000..97f107677a --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/SpatialFunctionsRegistry.java @@ -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 . + */ +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 Dialect + * + * Created by Karel Maesen, Geovise BVBA on 29/10/16. + */ +public abstract class SpatialFunctionsRegistry implements Iterable> { + protected final Map functionMap = new HashMap(); + + public void put(String name, StandardSQLFunction function ) { + this.functionMap.put( name, function ); + } + + @Override + public Iterator> iterator() { + return functionMap.entrySet().iterator(); + } + + public SQLFunction get(String functionName) { + return functionMap.get( functionName ); + } +} diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQLSpatialFunctions.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQLSpatialFunctions.java index b86e9ef45f..66d7383a5b 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQLSpatialFunctions.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/mysql/MySQLSpatialFunctions.java @@ -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> { - - private final Map functionsToRegister = new HashMap(); +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> iterator() { - return functionsToRegister.entrySet().iterator(); - } } diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/package.html b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/package.html new file mode 100644 index 0000000000..16843418e8 --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/package.html @@ -0,0 +1,16 @@ + + + + + + +

+ This package contains the Spatial Dialects supported by Hibnerate Spatial +

+ + diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisDialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisDialect.java index 5bec826161..8e439cf364 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisDialect.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisDialect.java @@ -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 { +@Deprecated +public class PostgisDialect extends PostgisPG82Dialect { - - /** - * 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" - ); - } - - } - - @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"; - } - } } diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisFunctions.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisFunctions.java new file mode 100644 index 0000000000..b0ae2d4b6e --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisFunctions.java @@ -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 . + */ +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"; + } + } +} diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisNoSQLMM.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisNoSQLMM.java index 9a7ce31ff9..2074c046b4 100644 --- a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisNoSQLMM.java +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisNoSQLMM.java @@ -20,8 +20,7 @@ import org.hibernate.type.StandardBasicTypes; */ public class PostgisNoSQLMM extends PostgisDialect { - @Override - protected void registerTypesAndFunctions() { + public PostgisNoSQLMM() { registerColumnType( PGGeometryTypeDescriptor.INSTANCE.getSqlType(), diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG82Dialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG82Dialect.java new file mode 100644 index 0000000000..d948ad5378 --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG82Dialect.java @@ -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 . + */ +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 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 ); + } +} diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG91Dialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG91Dialect.java new file mode 100644 index 0000000000..8c4b1270a0 --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG91Dialect.java @@ -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 . + */ +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 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 + * org.hibernatespatial.criterion.SpatialRelateExpressions + * into prepared statements. + *

+ * + * @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 + * SpatialRelation). + * + * @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 + * org.hibernate.spatial.criterion.SpatialFilterExpressions + * 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 SpatialAggregate + * + * @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 DWithinExpression. + * + * @param columnName The geometry column to test against + * + * @return The SQL fragment when parsing a DWithinExpression. + */ + @Override + public String getDWithinSQL(String columnName) { + return support.getDWithinSQL( columnName ); + } + + /** + * Returns the SQL fragment when parsing an HavingSridExpression. + * + * @param columnName The geometry column to test against + * + * @return The SQL fragment for an HavingSridExpression. + */ + @Override + public String getHavingSridSQL(String columnName) { + return support.getHavingSridSQL( columnName ); + } + + /** + * Returns the SQL fragment when parsing a IsEmptyExpression or + * IsNotEmpty 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 SpatialDialect supports a specific filtering function. + *

This is intended to signal DB-support for fast window queries, or MBR-overlap queries.

+ * + * @return True if filtering is supported + */ + @Override + public boolean supportsFiltering() { + return support.supportsFiltering(); + } + + /** + * Does this dialect supports the specified SpatialFunction. + * + * @param function SpatialFunction + * + * @return True if this SpatialDialect supports the spatial function specified by the function parameter. + */ + @Override + public boolean supports(SpatialFunction function) { + return support.supports( function ); + } +} diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG92Dialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG92Dialect.java new file mode 100644 index 0000000000..fb73e2d75e --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG92Dialect.java @@ -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 . + */ +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 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 + * org.hibernatespatial.criterion.SpatialRelateExpressions + * into prepared statements. + *

+ * + * @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 + * SpatialRelation). + * + * @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 + * org.hibernate.spatial.criterion.SpatialFilterExpressions + * 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 SpatialAggregate + * + * @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 DWithinExpression. + * + * @param columnName The geometry column to test against + * + * @return The SQL fragment when parsing a DWithinExpression. + */ + @Override + public String getDWithinSQL(String columnName) { + return support.getDWithinSQL( columnName ); + } + + /** + * Returns the SQL fragment when parsing an HavingSridExpression. + * + * @param columnName The geometry column to test against + * + * @return The SQL fragment for an HavingSridExpression. + */ + @Override + public String getHavingSridSQL(String columnName) { + return support.getHavingSridSQL( columnName ); + } + + /** + * Returns the SQL fragment when parsing a IsEmptyExpression or + * IsNotEmpty 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 SpatialDialect supports a specific filtering function. + *

This is intended to signal DB-support for fast window queries, or MBR-overlap queries.

+ * + * @return True if filtering is supported + */ + @Override + public boolean supportsFiltering() { + return support.supportsFiltering(); + } + + /** + * Does this dialect supports the specified SpatialFunction. + * + * @param function SpatialFunction + * + * @return True if this SpatialDialect supports the spatial function specified by the function parameter. + */ + @Override + public boolean supports(SpatialFunction function) { + return support.supports( function ); + } +} diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG93Dialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG93Dialect.java new file mode 100644 index 0000000000..8c3524ee55 --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG93Dialect.java @@ -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 . + */ +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 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 + * org.hibernatespatial.criterion.SpatialRelateExpressions + * into prepared statements. + *

+ * + * @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 + * SpatialRelation). + * + * @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 + * org.hibernate.spatial.criterion.SpatialFilterExpressions + * 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 SpatialAggregate + * + * @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 DWithinExpression. + * + * @param columnName The geometry column to test against + * + * @return The SQL fragment when parsing a DWithinExpression. + */ + @Override + public String getDWithinSQL(String columnName) { + return support.getDWithinSQL( columnName ); + } + + /** + * Returns the SQL fragment when parsing an HavingSridExpression. + * + * @param columnName The geometry column to test against + * + * @return The SQL fragment for an HavingSridExpression. + */ + @Override + public String getHavingSridSQL(String columnName) { + return support.getHavingSridSQL( columnName ); + } + + /** + * Returns the SQL fragment when parsing a IsEmptyExpression or + * IsNotEmpty 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 SpatialDialect supports a specific filtering function. + *

This is intended to signal DB-support for fast window queries, or MBR-overlap queries.

+ * + * @return True if filtering is supported + */ + @Override + public boolean supportsFiltering() { + return support.supportsFiltering(); + } + + /** + * Does this dialect supports the specified SpatialFunction. + * + * @param function SpatialFunction + * + * @return True if this SpatialDialect supports the spatial function specified by the function parameter. + */ + @Override + public boolean supports(SpatialFunction function) { + return support.supports( function ); + } +} diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG94Dialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG94Dialect.java new file mode 100644 index 0000000000..d1efbce72f --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG94Dialect.java @@ -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 . + */ +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 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 + * org.hibernatespatial.criterion.SpatialRelateExpressions + * into prepared statements. + *

+ * + * @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 + * SpatialRelation). + * + * @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 + * org.hibernate.spatial.criterion.SpatialFilterExpressions + * 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 SpatialAggregate + * + * @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 DWithinExpression. + * + * @param columnName The geometry column to test against + * + * @return The SQL fragment when parsing a DWithinExpression. + */ + @Override + public String getDWithinSQL(String columnName) { + return support.getDWithinSQL( columnName ); + } + + /** + * Returns the SQL fragment when parsing an HavingSridExpression. + * + * @param columnName The geometry column to test against + * + * @return The SQL fragment for an HavingSridExpression. + */ + @Override + public String getHavingSridSQL(String columnName) { + return support.getHavingSridSQL( columnName ); + } + + /** + * Returns the SQL fragment when parsing a IsEmptyExpression or + * IsNotEmpty 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 SpatialDialect supports a specific filtering function. + *

This is intended to signal DB-support for fast window queries, or MBR-overlap queries.

+ * + * @return True if filtering is supported + */ + @Override + public boolean supportsFiltering() { + return support.supportsFiltering(); + } + + /** + * Does this dialect supports the specified SpatialFunction. + * + * @param function SpatialFunction + * + * @return True if this SpatialDialect supports the spatial function specified by the function parameter. + */ + @Override + public boolean supports(SpatialFunction function) { + return support.supports( function ); + } +} diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG95Dialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG95Dialect.java new file mode 100644 index 0000000000..1d858a49d1 --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG95Dialect.java @@ -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 . + */ +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 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 + * org.hibernatespatial.criterion.SpatialRelateExpressions + * into prepared statements. + *

+ * + * @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 + * SpatialRelation). + * + * @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 + * org.hibernate.spatial.criterion.SpatialFilterExpressions + * 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 SpatialAggregate + * + * @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 DWithinExpression. + * + * @param columnName The geometry column to test against + * + * @return The SQL fragment when parsing a DWithinExpression. + */ + @Override + public String getDWithinSQL(String columnName) { + return support.getDWithinSQL( columnName ); + } + + /** + * Returns the SQL fragment when parsing an HavingSridExpression. + * + * @param columnName The geometry column to test against + * + * @return The SQL fragment for an HavingSridExpression. + */ + @Override + public String getHavingSridSQL(String columnName) { + return support.getHavingSridSQL( columnName ); + } + + /** + * Returns the SQL fragment when parsing a IsEmptyExpression or + * IsNotEmpty 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 SpatialDialect supports a specific filtering function. + *

This is intended to signal DB-support for fast window queries, or MBR-overlap queries.

+ * + * @return True if filtering is supported + */ + @Override + public boolean supportsFiltering() { + return support.supportsFiltering(); + } + + /** + * Does this dialect supports the specified SpatialFunction. + * + * @param function SpatialFunction + * + * @return True if this SpatialDialect supports the spatial function specified by the function parameter. + */ + @Override + public boolean supports(SpatialFunction function) { + return support.supports( function ); + } +} diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG9Dialect.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG9Dialect.java new file mode 100644 index 0000000000..dc2c4d55f6 --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisPG9Dialect.java @@ -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 . + */ +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 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 + * org.hibernatespatial.criterion.SpatialRelateExpressions + * into prepared statements. + *

+ * + * @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 + * SpatialRelation). + * + * @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 + * org.hibernate.spatial.criterion.SpatialFilterExpressions + * 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 SpatialAggregate + * + * @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 DWithinExpression. + * + * @param columnName The geometry column to test against + * + * @return The SQL fragment when parsing a DWithinExpression. + */ + @Override + public String getDWithinSQL(String columnName) { + return support.getDWithinSQL( columnName ); + } + + /** + * Returns the SQL fragment when parsing an HavingSridExpression. + * + * @param columnName The geometry column to test against + * + * @return The SQL fragment for an HavingSridExpression. + */ + @Override + public String getHavingSridSQL(String columnName) { + return support.getHavingSridSQL( columnName ); + } + + /** + * Returns the SQL fragment when parsing a IsEmptyExpression or + * IsNotEmpty 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 SpatialDialect supports a specific filtering function. + *

This is intended to signal DB-support for fast window queries, or MBR-overlap queries.

+ * + * @return True if filtering is supported + */ + @Override + public boolean supportsFiltering() { + return support.supportsFiltering(); + } + + /** + * Does this dialect supports the specified SpatialFunction. + * + * @param function SpatialFunction + * + * @return True if this SpatialDialect supports the spatial function specified by the function parameter. + */ + @Override + public boolean supports(SpatialFunction function) { + return support.supports( function ); + } +} diff --git a/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisSupport.java b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisSupport.java new file mode 100644 index 0000000000..e0f14ad136 --- /dev/null +++ b/hibernate-spatial/src/main/java/org/hibernate/spatial/dialect/postgis/PostgisSupport.java @@ -0,0 +1,174 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.spatial.dialect.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 + * org.hibernatespatial.criterion.SpatialRelateExpressions + * into prepared statements. + *

+ * + * @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 + * SpatialRelation). + * + * @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 + * org.hibernate.spatial.criterion.SpatialFilterExpressions + * 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 SpatialAggregate + * + * @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 DWithinExpression. + * + * @param columnName The geometry column to test against + * + * @return The SQL fragment when parsing a DWithinExpression. + */ + @Override + public String getDWithinSQL(String columnName) { + return "ST_DWithin(" + columnName + ",?,?)"; + } + + /** + * Returns the SQL fragment when parsing an HavingSridExpression. + * + * @param columnName The geometry column to test against + * + * @return The SQL fragment for an HavingSridExpression. + */ + @Override + public String getHavingSridSQL(String columnName) { + return "( ST_srid(" + columnName + ") = ?)"; + } + + /** + * Returns the SQL fragment when parsing a IsEmptyExpression or + * IsNotEmpty 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 SpatialDialect supports a specific filtering function. + *

This is intended to signal DB-support for fast window queries, or MBR-overlap queries.

+ * + * @return True if filtering is supported + */ + @Override + public boolean supportsFiltering() { + return true; + } + + /** + * Does this dialect supports the specified SpatialFunction. + * + * @param function SpatialFunction + * + * @return True if this SpatialDialect supports the spatial function specified by the function parameter. + */ + @Override + public boolean supports( SpatialFunction function) { + return (postgisFunctions.get( function.toString() ) != null); + } +} diff --git a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/TestSupportFactories.java b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/TestSupportFactories.java index 3776f7aa50..103991e502 100644 --- a/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/TestSupportFactories.java +++ b/hibernate-spatial/src/test/java/org/hibernate/spatial/testing/TestSupportFactories.java @@ -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 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 ) ) {