HHH-14800 Prepare refactoring hibernate-spatial
In preparation for the design as discussed in #4111: - Fixex compile errors - Deprecates the SpatialDialects - Removes the matrix test configuration (obsolete) - Removes support for Criteria
This commit is contained in:
parent
61d1891f55
commit
dcf2a85d20
|
@ -1,12 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
repositories {
|
||||
mavenLocal( )
|
||||
}
|
||||
|
||||
jdbcDependency "com.ibm.db2:db2jcc:11.1"
|
|
@ -1,27 +0,0 @@
|
|||
#
|
||||
# Hibernate, Relational Persistence for Idiomatic Java
|
||||
#
|
||||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
#
|
||||
|
||||
hibernate.test.new_metadata_mappings = true
|
||||
hibernate.dialect org.hibernate.spatial.dialect.db2.DB2SpatialDialect
|
||||
hibernate.connection.driver_class com.ibm.db2.jcc.DB2Driver
|
||||
hibernate.connection.url jdbc:db2://localhost:50000/hibern8
|
||||
hibernate.connection.username db2inst1
|
||||
hibernate.connection.password oPucroAsMAgL
|
||||
|
||||
|
||||
hibernate.connection.pool_size 5
|
||||
|
||||
hibernate.show_sql true
|
||||
hibernate.format_sql true
|
||||
|
||||
hibernate.max_fetch_depth 5
|
||||
|
||||
hibernate.cache.region_prefix hibernate.test
|
||||
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
|
||||
|
||||
## Ensures that all geometries that are retrieved are in WGS84
|
||||
hibernate.spatial.db2.srid 4326
|
|
@ -1,7 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
jdbcDependency "org.opengeo:geodb:0.7"
|
|
@ -1,24 +0,0 @@
|
|||
#
|
||||
# Hibernate, Relational Persistence for Idiomatic Java
|
||||
#
|
||||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
#
|
||||
|
||||
hibernate.dialect org.hibernate.spatial.dialect.h2geodb.GeoDBDialect
|
||||
hibernate.connection.driver_class org.h2.Driver
|
||||
hibernate.connection.url jdbc:h2:mem:testhbs;DB_CLOSE_DELAY=-1;MVCC=true
|
||||
hibernate.connection.username sa
|
||||
hibernate.connection.password sa
|
||||
|
||||
|
||||
hibernate.connection.pool_size 5
|
||||
|
||||
hibernate.show_sql true
|
||||
hibernate.format_sql true
|
||||
|
||||
hibernate.max_fetch_depth 5
|
||||
|
||||
hibernate.cache.region_prefix hibernate.test
|
||||
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
jdbcDependency "com.sap.cloud.db.jdbc:ngdbc:2.2.16"
|
|
@ -1,26 +0,0 @@
|
|||
#
|
||||
# Hibernate, Relational Persistence for Idiomatic Java
|
||||
#
|
||||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
#
|
||||
|
||||
hibernate.test.new_metadata_mappings = true
|
||||
|
||||
hibernate.dialect org.hibernate.spatial.dialect.hana.HANASpatialDialect
|
||||
hibernate.connection.driver_class com.sap.db.jdbc.Driver
|
||||
hibernate.connection.url jdbc:sap://localhost:30015
|
||||
hibernate.connection.username hibernate
|
||||
hibernate.connection.password hibernate
|
||||
|
||||
hibernate.connection.pool_size 5
|
||||
|
||||
hibernate.show_sql true
|
||||
hibernate.format_sql true
|
||||
|
||||
hibernate.max_fetch_depth 5
|
||||
|
||||
hibernate.cache.region_prefix hibernate.test
|
||||
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
|
||||
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
jdbcDependency "mysql:mysql-connector-java:8.0.17"
|
|
@ -1,25 +0,0 @@
|
|||
#
|
||||
# Hibernate, Relational Persistence for Idiomatic Java
|
||||
#
|
||||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
#
|
||||
|
||||
hibernate.dialect org.hibernate.spatial.dialect.mysql.MySQL56SpatialDialect
|
||||
hibernate.connection.driver_class com.mysql.jdbc.Driver
|
||||
hibernate.connection.url jdbc:mysql://localhost:3306/hibern8
|
||||
hibernate.connection.username hibernateormtest
|
||||
hibernate.connection.password hibernateormtest
|
||||
|
||||
|
||||
hibernate.connection.pool_size 5
|
||||
|
||||
hibernate.show_sql true
|
||||
hibernate.format_sql true
|
||||
|
||||
hibernate.max_fetch_depth 5
|
||||
|
||||
hibernate.cache.region_prefix hibernate.test
|
||||
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
|
||||
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
jdbcDependency "mysql:mysql-connector-java:8.0.17"
|
|
@ -1,25 +0,0 @@
|
|||
#
|
||||
# Hibernate, Relational Persistence for Idiomatic Java
|
||||
#
|
||||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
#
|
||||
|
||||
hibernate.dialect org.hibernate.spatial.dialect.mysql.MySQL8SpatialDialect
|
||||
hibernate.connection.driver_class com.mysql.jdbc.Driver
|
||||
hibernate.connection.url jdbc:mysql://localhost:3306/hibern8
|
||||
hibernate.connection.username hibernateormtest
|
||||
hibernate.connection.password hibernateormtest
|
||||
|
||||
|
||||
hibernate.connection.pool_size 5
|
||||
|
||||
hibernate.show_sql true
|
||||
hibernate.format_sql true
|
||||
|
||||
hibernate.max_fetch_depth 5
|
||||
|
||||
hibernate.cache.region_prefix hibernate.test
|
||||
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
|
||||
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
jdbcDependency "com.oracle:ojdbc7:12.1.0.2.0"
|
|
@ -1,25 +0,0 @@
|
|||
#
|
||||
# Hibernate, Relational Persistence for Idiomatic Java
|
||||
#
|
||||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
#
|
||||
|
||||
hibernate.dialect org.hibernate.spatial.dialect.oracle.OracleSpatial10gDialect
|
||||
hibernate.connection.driver_class oracle.jdbc.OracleDriver
|
||||
hibernate.connection.url jdbc:oracle:thin:@localhost:1521:ORCL
|
||||
hibernate.connection.username C##hibernate
|
||||
hibernate.connection.password hibernate
|
||||
|
||||
## uncommenting this will fail a unit test!!
|
||||
hibernate.spatial.connection_finder org.hibernate.spatial.dialect.oracle.TestConnectionFinder
|
||||
|
||||
hibernate.connection.pool_size 5
|
||||
|
||||
hibernate.show_sql true
|
||||
hibernate.format_sql true
|
||||
|
||||
hibernate.max_fetch_depth 5
|
||||
|
||||
hibernate.cache.region_prefix hibernate.test
|
||||
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
|
|
@ -1,7 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
jdbcDependency "com.oracle:ojdbc7:12.1.0.2.0"
|
|
@ -1,25 +0,0 @@
|
|||
#
|
||||
# Hibernate, Relational Persistence for Idiomatic Java
|
||||
#
|
||||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
#
|
||||
|
||||
hibernate.dialect org.hibernate.spatial.dialect.oracle.OracleSpatial10gDialect
|
||||
hibernate.connection.driver_class oracle.jdbc.OracleDriver
|
||||
hibernate.connection.url jdbc:oracle:thin:@localhost:1521:ORCL
|
||||
hibernate.connection.username C##hibernate
|
||||
hibernate.connection.password hibernate
|
||||
|
||||
## uncommenting this will fail a unit test!!
|
||||
#hibernate.spatial.ogc_strict false
|
||||
|
||||
hibernate.connection.pool_size 5
|
||||
|
||||
hibernate.show_sql true
|
||||
hibernate.format_sql true
|
||||
|
||||
hibernate.max_fetch_depth 5
|
||||
|
||||
hibernate.cache.region_prefix hibernate.test
|
||||
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
|
|
@ -1,8 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
jdbcDependency "com.oracle:ojdbc7:12.1.0.2.0"
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
#
|
||||
# Hibernate, Relational Persistence for Idiomatic Java
|
||||
#
|
||||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
#
|
||||
|
||||
hibernate.dialect org.hibernate.spatial.dialect.oracle.OracleSpatialSDO10gDialect
|
||||
hibernate.connection.driver_class oracle.jdbc.OracleDriver
|
||||
hibernate.connection.url jdbc:oracle:thin:@localhost:1521:ORCL
|
||||
hibernate.connection.username C##hibernate
|
||||
hibernate.connection.password hibernate
|
||||
|
||||
## uncommenting this will fail a unit test!!
|
||||
#hibernate.spatial.ogc_strict false
|
||||
|
||||
hibernate.connection.pool_size 5
|
||||
|
||||
hibernate.show_sql true
|
||||
hibernate.format_sql true
|
||||
|
||||
hibernate.max_fetch_depth 5
|
||||
|
||||
hibernate.cache.region_prefix hibernate.test
|
||||
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
|
|
@ -1,7 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
jdbcDependency 'org.postgresql:postgresql:42.2.16'
|
|
@ -1,21 +0,0 @@
|
|||
#
|
||||
# Hibernate, Relational Persistence for Idiomatic Java
|
||||
#
|
||||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
#
|
||||
|
||||
|
||||
hibernate.dialect org.hibernate.spatial.dialect.postgis.PostgisPG95Dialect
|
||||
hibernate.connection.driver_class org.postgresql.Driver
|
||||
hibernate.connection.url jdbc:postgresql://localhost/hibernate_orm_test
|
||||
hibernate.connection.username hibernate_orm_test
|
||||
hibernate.connection.password hibernate_orm_test
|
||||
|
||||
hibernate.show_sql true
|
||||
hibernate.format_sql true
|
||||
|
||||
hibernate.max_fetch_depth 5
|
||||
|
||||
hibernate.cache.region_prefix hibernate.test
|
||||
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
|
|
@ -1,11 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
repositories {
|
||||
mavenLocal( )
|
||||
}
|
||||
|
||||
jdbcDependency 'com.microsoft.sqlserver:mssql-jdbc:6.4.0.jre8'
|
|
@ -1,23 +0,0 @@
|
|||
#
|
||||
# Hibernate, Relational Persistence for Idiomatic Java
|
||||
#
|
||||
# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
#
|
||||
|
||||
hibernate.dialect org.hibernate.spatial.dialect.sqlserver.SqlServer2012SpatialDialect
|
||||
hibernate.connection.driver_class com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
hibernate.connection.url jdbc:sqlserver://localhost:1433;databaseName=TestDb
|
||||
hibernate.connection.username hibern8
|
||||
hibernate.connection.password langpaswoord123A%1
|
||||
|
||||
|
||||
hibernate.connection.pool_size 5
|
||||
|
||||
hibernate.show_sql true
|
||||
hibernate.format_sql true
|
||||
|
||||
hibernate.max_fetch_depth 5
|
||||
|
||||
hibernate.cache.region_prefix hibernate.test
|
||||
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
|
|
@ -22,7 +22,6 @@ dependencies {
|
|||
testCompile(libraries.junit)
|
||||
testCompile(project(':hibernate-testing'))
|
||||
testCompile( project( path: ':hibernate-core', configuration: 'tests' ) )
|
||||
testCompile([group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.8.0'])
|
||||
testCompile(libraries.validation)
|
||||
testCompile(libraries.jandex)
|
||||
testCompile(libraries.classmate)
|
||||
|
@ -44,6 +43,10 @@ sourceSets.test.resources {
|
|||
setSrcDirs(['src/test/java', 'src/test/resources'])
|
||||
}
|
||||
|
||||
|
||||
tasks.test {
|
||||
enabled = project.db == 'pgsql'
|
||||
}
|
||||
|
||||
//tasks.test.include '**/*'
|
||||
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
|
||||
package org.hibernate.spatial;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.type.descriptor.WrapperOptions;
|
||||
import org.hibernate.type.descriptor.java.AbstractTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptorIndicators;
|
||||
import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor;
|
||||
|
||||
import org.geolatte.geom.Geometry;
|
||||
import org.geolatte.geom.codec.Wkt;
|
||||
|
@ -38,10 +34,10 @@ public class GeolatteGeometryJavaTypeDescriptor extends AbstractTypeDescriptor<G
|
|||
super( Geometry.class );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlTypeDescriptor getJdbcRecommendedSqlType(SqlTypeDescriptorIndicators context) {
|
||||
return context.getTypeConfiguration().getSqlTypeDescriptorRegistry().getDescriptor( Types.ARRAY );
|
||||
}
|
||||
|
||||
// public JdbcTypeDescriptor getJdbcRecommendedSqlType(JdbcTypeDescriptorIndicators context) {
|
||||
// return context.getTypeConfiguration().getJdbcTypeDescriptorRegistry().getDescriptor( Types.ARRAY );
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String toString(Geometry value) {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
package org.hibernate.spatial;
|
||||
|
||||
import org.hibernate.type.AbstractSingleColumnStandardBasicType;
|
||||
import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
|
||||
import org.geolatte.geom.Geometry;
|
||||
import org.geolatte.geom.GeometryCollection;
|
||||
|
@ -44,7 +44,7 @@ public class GeolatteGeometryType extends AbstractSingleColumnStandardBasicType<
|
|||
*
|
||||
* @param sqlTypeDescriptor The Descriptor for the type used by the database for geometries.
|
||||
*/
|
||||
public GeolatteGeometryType(SqlTypeDescriptor sqlTypeDescriptor) {
|
||||
public GeolatteGeometryType(JdbcTypeDescriptor sqlTypeDescriptor) {
|
||||
super( sqlTypeDescriptor, GeolatteGeometryJavaTypeDescriptor.INSTANCE );
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ public class HibernateSpatialConfigurationSettings implements Serializable {
|
|||
*/
|
||||
|
||||
public static final String CONNECTION_FINDER = "hibernate.spatial.connection_finder";
|
||||
|
||||
/**
|
||||
* SRID to use for the DB2 Spatial Dialects.
|
||||
*/
|
||||
|
@ -31,5 +32,4 @@ public class HibernateSpatialConfigurationSettings implements Serializable {
|
|||
//prevent this object from being instantiated
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
package org.hibernate.spatial;
|
||||
|
||||
import org.hibernate.type.AbstractSingleColumnStandardBasicType;
|
||||
import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
|
||||
|
@ -21,10 +21,10 @@ public class JTSGeometryType extends AbstractSingleColumnStandardBasicType<Geome
|
|||
/**
|
||||
* Constructs an instance with the specified {@code SqlTypeDescriptor}
|
||||
*
|
||||
* @param sqlTypeDescriptor The descriptor for the type used by the database for geometries.
|
||||
* @param jdbcTypeDescriptor The descriptor for the type used by the database for geometries.
|
||||
*/
|
||||
public JTSGeometryType(SqlTypeDescriptor sqlTypeDescriptor) {
|
||||
super( sqlTypeDescriptor, JTSGeometryJavaTypeDescriptor.INSTANCE );
|
||||
public JTSGeometryType(JdbcTypeDescriptor jdbcTypeDescriptor) {
|
||||
super( jdbcTypeDescriptor, JTSGeometryJavaTypeDescriptor.INSTANCE );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,88 +15,88 @@ import java.io.Serializable;
|
|||
*/
|
||||
public interface SpatialDialect extends Serializable {
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
String getSpatialRelateSQL(String columnName, int 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}
|
||||
*/
|
||||
String getSpatialFilterExpression(String 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
|
||||
*/
|
||||
String getSpatialAggregateSQL(String columnName, int 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>.
|
||||
*/
|
||||
String getDWithinSQL(String columnName);
|
||||
|
||||
/**
|
||||
* Returns the SQL fragment when parsing a <code>HavingSridExpression</code>.
|
||||
*
|
||||
* @param columnName The geometry column to test against
|
||||
*
|
||||
* @return The SQL fragment for a <code>HavingSridExpression</code>.
|
||||
*/
|
||||
String getHavingSridSQL(String 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
|
||||
*/
|
||||
String getIsEmptySQL(String columnName, boolean 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
|
||||
*/
|
||||
boolean 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.
|
||||
*/
|
||||
boolean supports(SpatialFunction function);
|
||||
// /**
|
||||
// * 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}
|
||||
// */
|
||||
// String getSpatialRelateSQL(String columnName, int 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}
|
||||
// */
|
||||
// String getSpatialFilterExpression(String 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
|
||||
// */
|
||||
// String getSpatialAggregateSQL(String columnName, int 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>.
|
||||
// */
|
||||
// String getDWithinSQL(String columnName);
|
||||
//
|
||||
// /**
|
||||
// * Returns the SQL fragment when parsing a <code>HavingSridExpression</code>.
|
||||
// *
|
||||
// * @param columnName The geometry column to test against
|
||||
// *
|
||||
// * @return The SQL fragment for a <code>HavingSridExpression</code>.
|
||||
// */
|
||||
// String getHavingSridSQL(String 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
|
||||
// */
|
||||
// String getIsEmptySQL(String columnName, boolean 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
|
||||
// */
|
||||
// boolean 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.
|
||||
// */
|
||||
// boolean supports(SpatialFunction function);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.criterion;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.criterion.CriteriaQuery;
|
||||
import org.hibernate.criterion.Criterion;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.dialect.oracle.OracleSpatial10gDialect;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
|
||||
/**
|
||||
* A {@code Criterion} constraining a geometry property to be within a specified distance of a search geometry.
|
||||
*
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
* creation-date: 2/1/11
|
||||
*/
|
||||
public class DWithinExpression implements Criterion {
|
||||
|
||||
|
||||
private final String propertyName;
|
||||
private final Geometry geometry;
|
||||
private final double distance;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
*
|
||||
* @param propertyName The name of the property being constrained
|
||||
* @param geometry The search geometry
|
||||
* @param distance The search distance (in units of the spatial reference system of the search geometry)
|
||||
*/
|
||||
public DWithinExpression(String propertyName, Geometry geometry, double distance) {
|
||||
this.propertyName = propertyName;
|
||||
this.geometry = geometry;
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final String column = ExpressionUtil.findColumn( propertyName, criteria, criteriaQuery );
|
||||
final SpatialDialect spatialDialect = ExpressionUtil.getSpatialDialect(
|
||||
criteriaQuery,
|
||||
SpatialFunction.dwithin
|
||||
);
|
||||
return spatialDialect.getDWithinSQL( column );
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final SpatialDialect spatialDialect = ExpressionUtil.getSpatialDialect(
|
||||
criteriaQuery,
|
||||
SpatialFunction.dwithin
|
||||
);
|
||||
TypedValue typedDistanceValue = new TypedValue( StandardBasicTypes.DOUBLE, distance );
|
||||
if ( spatialDialect instanceof OracleSpatial10gDialect ) {
|
||||
typedDistanceValue = new TypedValue( StandardBasicTypes.STRING, "distance=" + distance );
|
||||
}
|
||||
return new TypedValue[] {
|
||||
criteriaQuery.getTypedValue( criteria, propertyName, geometry ),
|
||||
typedDistanceValue
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.criterion;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.criterion.CriteriaQuery;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
|
||||
/**
|
||||
* This class assists in the formation of a SQL-fragment in the various spatial query expressions.
|
||||
*
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
* creation-date: 2/15/11
|
||||
*/
|
||||
public class ExpressionUtil {
|
||||
|
||||
/**
|
||||
* private constructor prevents instantiation of this utility class
|
||||
*/
|
||||
private ExpressionUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the {@code SpatialDialect} for the specified {@code CriteriaQuery}, and checks if the
|
||||
* specified function is supported.
|
||||
*
|
||||
* @param criteriaQuery The {@code CriteriaQuery} for which the dialect is sought
|
||||
* @param function The function for which to check support
|
||||
*
|
||||
* @return The {@code SpatialDialect} associated with the specified {@code CriteriaQuery}
|
||||
*
|
||||
* @throws HibernateException If the dialect for the specified {@code CriteriaQuery} is not a {@code SpatialDialect}.
|
||||
* or the specified {@code SpatialFunction} is not supported by the dialect.
|
||||
*/
|
||||
public static SpatialDialect getSpatialDialect(CriteriaQuery criteriaQuery, SpatialFunction function) {
|
||||
final Dialect dialect = criteriaQuery.getFactory().getDialect();
|
||||
if ( !( dialect instanceof SpatialDialect ) ) {
|
||||
throw new HibernateException( "A spatial expression requires a spatial dialect." );
|
||||
}
|
||||
final SpatialDialect spatialDialect = (SpatialDialect) dialect;
|
||||
if ( !spatialDialect.supports( function ) ) {
|
||||
throw new HibernateException( function + " function not supported by this dialect" );
|
||||
}
|
||||
return spatialDialect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the column name corresponding to the specified property path.
|
||||
*
|
||||
* @param propertyName The property path
|
||||
* @param criteria The criteria
|
||||
* @param criteriaQuery The criteria query
|
||||
*
|
||||
* @return The column name
|
||||
*
|
||||
* @throws HibernateException If the property could not be resolved, or more than one column is mapped by the property path.
|
||||
*/
|
||||
public static String findColumn(String propertyName, Criteria criteria, CriteriaQuery criteriaQuery) {
|
||||
final String[] columns = criteriaQuery.findColumns( propertyName, criteria );
|
||||
if ( columns.length != 1 ) {
|
||||
throw new HibernateException( "Spatial Expression may only be used with single-column properties" );
|
||||
}
|
||||
return columns[0];
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.criterion;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.criterion.CriteriaQuery;
|
||||
import org.hibernate.criterion.Criterion;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
||||
/**
|
||||
* A {@code Criterion} constraining a geometry property to have a specified SRID.
|
||||
*
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
*/
|
||||
public class HavingSridExpression implements Criterion {
|
||||
|
||||
private final String propertyName;
|
||||
private final int srid;
|
||||
|
||||
/**
|
||||
* Constructs an instance for the specified property and srid
|
||||
*
|
||||
* @param propertyName The name of the property being constrained
|
||||
* @param srid The srid
|
||||
*/
|
||||
public HavingSridExpression(String propertyName, int srid) {
|
||||
this.propertyName = propertyName;
|
||||
this.srid = srid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final String column = ExpressionUtil.findColumn( propertyName, criteria, criteriaQuery );
|
||||
final SpatialDialect spatialDialect = ExpressionUtil.getSpatialDialect( criteriaQuery, SpatialFunction.srid );
|
||||
return spatialDialect.getHavingSridSQL( column );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return new TypedValue[] {
|
||||
new TypedValue( StandardBasicTypes.INTEGER, srid )
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.criterion;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.criterion.CriteriaQuery;
|
||||
import org.hibernate.criterion.Criterion;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
|
||||
/**
|
||||
* A {@code Criterion} constraining a geometry property to be (non-)empty.
|
||||
*
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
*/
|
||||
public class IsEmptyExpression implements Criterion {
|
||||
|
||||
private static final TypedValue[] NO_VALUES = new TypedValue[0];
|
||||
|
||||
private final String propertyName;
|
||||
private final boolean isEmpty;
|
||||
|
||||
/**
|
||||
* Constructs an instance for the specified property
|
||||
*
|
||||
* @param propertyName The name of the property being constrained
|
||||
* @param isEmpty Whether to constrain the property to be empty or non-empty
|
||||
*/
|
||||
public IsEmptyExpression(String propertyName, boolean isEmpty) {
|
||||
this.propertyName = propertyName;
|
||||
this.isEmpty = isEmpty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final String column = ExpressionUtil.findColumn( propertyName, criteria, criteriaQuery );
|
||||
final SpatialDialect spatialDialect = ExpressionUtil.getSpatialDialect(
|
||||
criteriaQuery,
|
||||
SpatialFunction.isempty
|
||||
);
|
||||
return spatialDialect.getIsEmptySQL( column, isEmpty );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return NO_VALUES;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.criterion;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.criterion.CriteriaQuery;
|
||||
import org.hibernate.criterion.Criterion;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.jts.EnvelopeAdapter;
|
||||
|
||||
import org.locationtech.jts.geom.Envelope;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
|
||||
/**
|
||||
* A <code>Criterion</code> constraining a geometry property to have a bounding box that overlaps with
|
||||
* a specified bounding box.
|
||||
*
|
||||
* @author Karel Maesen
|
||||
*/
|
||||
public class SpatialFilter implements Criterion {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String propertyName;
|
||||
private Geometry filter;
|
||||
|
||||
/**
|
||||
* Constructs an instance with the specified property and the bounding box of the specified geometry.
|
||||
*
|
||||
* @param propertyName The name of the propety being constrained
|
||||
* @param filter The geometry whose bounding box is used as search geometry
|
||||
*/
|
||||
public SpatialFilter(String propertyName, Geometry filter) {
|
||||
this.propertyName = propertyName;
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance with the specified property and the bounding box of the specified geometry.
|
||||
*
|
||||
* @param propertyName The name of the propety being constrained
|
||||
* @param envelope The bounding box is used as search geometry
|
||||
* @param srid The SRID of the specified bounding box
|
||||
*/
|
||||
public SpatialFilter(String propertyName, Envelope envelope, int srid) {
|
||||
this.propertyName = propertyName;
|
||||
this.filter = EnvelopeAdapter.toPolygon( envelope, srid );
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return new TypedValue[] {
|
||||
criteriaQuery.getTypedValue( criteria, propertyName, filter )
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final SessionFactoryImplementor factory = criteriaQuery.getFactory();
|
||||
final String[] columns = criteriaQuery.getColumnsUsingProjection( criteria, this.propertyName );
|
||||
final Dialect dialect = factory.getDialect();
|
||||
if ( dialect instanceof SpatialDialect ) {
|
||||
final SpatialDialect seDialect = (SpatialDialect) dialect;
|
||||
return seDialect.getSpatialFilterExpression( columns[0] );
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException( "Dialect must be spatially enabled dialect" );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.criterion;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.criterion.CriteriaQuery;
|
||||
import org.hibernate.criterion.Projection;
|
||||
import org.hibernate.criterion.SimpleProjection;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.spatial.SpatialAggregate;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* A factory for spatial projections.
|
||||
*
|
||||
* @author Karel Maesen
|
||||
*/
|
||||
public class SpatialProjections {
|
||||
|
||||
private SpatialProjections() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies an extent projection to the specified geometry function
|
||||
* <p>
|
||||
* <p>The extent of a set of {@code Geometry}s is the union of their bounding boxes.</p>
|
||||
*
|
||||
* @param propertyName The property to use for calculating the extent
|
||||
*
|
||||
* @return an extent-projection for the specified property.
|
||||
*/
|
||||
public static Projection extent(final String propertyName) {
|
||||
return new SimpleProjection() {
|
||||
|
||||
public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return new Type[] {
|
||||
criteriaQuery.getType( criteria, propertyName )
|
||||
};
|
||||
}
|
||||
|
||||
public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery)
|
||||
throws HibernateException {
|
||||
final StringBuilder stbuf = new StringBuilder();
|
||||
|
||||
final SessionFactoryImplementor factory = criteriaQuery.getFactory();
|
||||
final String[] columns = criteriaQuery.getColumnsUsingProjection( criteria, propertyName );
|
||||
final Dialect dialect = factory.getDialect();
|
||||
if ( dialect instanceof SpatialDialect ) {
|
||||
final SpatialDialect seDialect = (SpatialDialect) dialect;
|
||||
stbuf.append(
|
||||
seDialect.getSpatialAggregateSQL( columns[0], SpatialAggregate.EXTENT )
|
||||
);
|
||||
stbuf.append( " as y" ).append( position ).append( '_' );
|
||||
return stbuf.toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.criterion;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.criterion.CriteriaQuery;
|
||||
import org.hibernate.criterion.Criterion;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
|
||||
/**
|
||||
* A {@code Criterion} constraining a {@code Geometry} property to have specific spatial relation
|
||||
* to a search {@code Geometry}.
|
||||
*
|
||||
* @author Karel Maesen
|
||||
*/
|
||||
public class SpatialRelateExpression implements Criterion {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
* The geometry property
|
||||
*/
|
||||
private String propertyName;
|
||||
/**
|
||||
* The test geometry
|
||||
*/
|
||||
private Geometry value;
|
||||
/**
|
||||
* The spatial relation that is queried for.
|
||||
*/
|
||||
private int spatialRelation = -1;
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
*
|
||||
* @param propertyName The name of the property being constrained
|
||||
* @param value The search {@code Geometry}
|
||||
* @param spatialRelation The type of {@code SpatialRelation} to use in the comparison
|
||||
*/
|
||||
public SpatialRelateExpression(String propertyName, Geometry value, int spatialRelation) {
|
||||
this.propertyName = propertyName;
|
||||
this.spatialRelation = spatialRelation;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return new TypedValue[] { criteriaQuery.getTypedValue( criteria, propertyName, value ) };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final SessionFactoryImplementor factory = criteriaQuery.getFactory();
|
||||
final String[] columns = criteriaQuery.getColumnsUsingProjection( criteria, this.propertyName );
|
||||
final Dialect dialect = factory.getDialect();
|
||||
if ( dialect instanceof SpatialDialect ) {
|
||||
final SpatialDialect seDialect = (SpatialDialect) dialect;
|
||||
return seDialect.getSpatialRelateSQL( columns[0], spatialRelation );
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException( "Dialect must be spatially enabled dialect" );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,288 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.criterion;
|
||||
|
||||
import org.hibernate.criterion.Criterion;
|
||||
import org.hibernate.spatial.SpatialRelation;
|
||||
|
||||
import org.locationtech.jts.geom.Envelope;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
|
||||
/**
|
||||
* A factory for spatial criteria.
|
||||
* <p>
|
||||
* The criterion types created by this class implement the spatial query
|
||||
* expressions of the OpenGIS Simple Features Specification for SQL, Revision
|
||||
* 1.1. In addition, it provides for a simple spatial <code>filter</code> that
|
||||
* works mostly using the spatial index. This corresponds to the Oracle
|
||||
* Spatial's "SDO_FILTER" function, or the "&&" operator of PostGIS.
|
||||
*
|
||||
* @author Karel Maesen
|
||||
*/
|
||||
public class SpatialRestrictions {
|
||||
|
||||
private SpatialRestrictions() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "spatially equal" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The geometry value to use in comparison
|
||||
*
|
||||
* @return SpatialRelateExpression
|
||||
*
|
||||
* @see SpatialRelateExpression
|
||||
*/
|
||||
public static SpatialRelateExpression eq(String propertyName, Geometry value) {
|
||||
return new SpatialRelateExpression(
|
||||
propertyName, value,
|
||||
SpatialRelation.EQUALS
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "spatially within" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The geometry value to use in comparison
|
||||
*
|
||||
* @return SpatialRelateExpression
|
||||
*
|
||||
* @see SpatialRelateExpression
|
||||
*/
|
||||
public static SpatialRelateExpression within(String propertyName, Geometry value) {
|
||||
return new SpatialRelateExpression(
|
||||
propertyName, value,
|
||||
SpatialRelation.WITHIN
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "spatially contains" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The geometry value to use in comparison
|
||||
*
|
||||
* @return SpatialRelateExpression
|
||||
*
|
||||
* @see SpatialRelateExpression
|
||||
*/
|
||||
public static SpatialRelateExpression contains(String propertyName, Geometry value) {
|
||||
return new SpatialRelateExpression(
|
||||
propertyName, value,
|
||||
SpatialRelation.CONTAINS
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "spatially crosses" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The geometry value to use in comparison
|
||||
*
|
||||
* @return SpatialRelateExpression
|
||||
*
|
||||
* @see SpatialRelateExpression
|
||||
*/
|
||||
public static SpatialRelateExpression crosses(String propertyName, Geometry value) {
|
||||
return new SpatialRelateExpression(
|
||||
propertyName, value,
|
||||
SpatialRelation.CROSSES
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "spatially disjoint" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The geometry value to use in comparison
|
||||
*
|
||||
* @return SpatialRelateExpression
|
||||
*
|
||||
* @see SpatialRelateExpression
|
||||
*/
|
||||
public static SpatialRelateExpression disjoint(String propertyName, Geometry value) {
|
||||
return new SpatialRelateExpression(
|
||||
propertyName, value,
|
||||
SpatialRelation.DISJOINT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "spatially intersects" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The geometry value to use in comparison
|
||||
*
|
||||
* @return SpatialRelateExpression
|
||||
*
|
||||
* @see SpatialRelateExpression
|
||||
*/
|
||||
public static SpatialRelateExpression intersects(String propertyName, Geometry value) {
|
||||
return new SpatialRelateExpression(
|
||||
propertyName, value,
|
||||
SpatialRelation.INTERSECTS
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "spatially overlaps" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The geometry value to use in comparison
|
||||
*
|
||||
* @return SpatialRelateExpression
|
||||
*
|
||||
* @see SpatialRelateExpression
|
||||
*/
|
||||
public static SpatialRelateExpression overlaps(String propertyName, Geometry value) {
|
||||
return new SpatialRelateExpression(
|
||||
propertyName, value,
|
||||
SpatialRelation.OVERLAPS
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "spatially touches" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The geometry value to use in comparison
|
||||
*
|
||||
* @return SpatialRelateExpression
|
||||
*
|
||||
* @see SpatialRelateExpression
|
||||
*/
|
||||
public static SpatialRelateExpression touches(String propertyName, Geometry value) {
|
||||
return new SpatialRelateExpression(
|
||||
propertyName, value,
|
||||
SpatialRelation.TOUCHES
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a bounding box overlap constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param value The geometry value whose bounding box to use in the comparison
|
||||
*
|
||||
* @return SpatialFilter
|
||||
*
|
||||
* @see SpatialFilter
|
||||
*/
|
||||
public static SpatialFilter filter(String propertyName, Geometry value) {
|
||||
return new SpatialFilter( propertyName, value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a bounding box overlap constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param envelope The envelope or bounding box to use in the comparison
|
||||
* @param srid the SRID of the bounding box
|
||||
*
|
||||
* @return SpatialFilter
|
||||
*
|
||||
* @see SpatialFilter
|
||||
*/
|
||||
public static SpatialFilter filter(String propertyName, Envelope envelope, int srid) {
|
||||
return new SpatialFilter( propertyName, envelope, srid );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "distance within" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param geometry The geometry value to use in the comparison
|
||||
* @param distance The distance
|
||||
*
|
||||
* @return DWithinExpression
|
||||
*
|
||||
* @see DWithinExpression
|
||||
*/
|
||||
public static Criterion distanceWithin(String propertyName, Geometry geometry, double distance) {
|
||||
return new DWithinExpression( propertyName, geometry, distance );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "having srid" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param srid The SRID value to use in the comparison
|
||||
*
|
||||
* @return A HavingSridExpression
|
||||
*
|
||||
* @see HavingSridExpression
|
||||
*/
|
||||
public static Criterion havingSRID(String propertyName, int srid) {
|
||||
return new HavingSridExpression( propertyName, srid );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "is empty" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
*
|
||||
* @return A IsEmptyExpression
|
||||
*
|
||||
* @see IsEmptyExpression
|
||||
*/
|
||||
public static Criterion isEmpty(String propertyName) {
|
||||
return new IsEmptyExpression( propertyName, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "is not empty" constraint to the named property
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
*
|
||||
* @return A IsEmptyExpression
|
||||
*
|
||||
* @see IsEmptyExpression
|
||||
*/
|
||||
public static Criterion isNotEmpty(String propertyName) {
|
||||
return new IsEmptyExpression( propertyName, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the specified spatial relation constraint to the named property.
|
||||
*
|
||||
* @param relation The spatial relation to apply
|
||||
* @param propertyName The name of the property
|
||||
* @param value The geometry value to use in the comparison
|
||||
*
|
||||
* @return SpatialFilter
|
||||
*
|
||||
* @see SpatialFilter
|
||||
*/
|
||||
public static Criterion spatialRestriction(int relation, String propertyName, Geometry value) {
|
||||
switch ( relation ) {
|
||||
case SpatialRelation.CONTAINS:
|
||||
return contains( propertyName, value );
|
||||
case SpatialRelation.CROSSES:
|
||||
return crosses( propertyName, value );
|
||||
case SpatialRelation.DISJOINT:
|
||||
return disjoint( propertyName, value );
|
||||
case SpatialRelation.INTERSECTS:
|
||||
return intersects( propertyName, value );
|
||||
case SpatialRelation.EQUALS:
|
||||
return eq( propertyName, value );
|
||||
case SpatialRelation.FILTER:
|
||||
return filter( propertyName, value );
|
||||
case SpatialRelation.OVERLAPS:
|
||||
return overlaps( propertyName, value );
|
||||
case SpatialRelation.TOUCHES:
|
||||
return touches( propertyName, value );
|
||||
case SpatialRelation.WITHIN:
|
||||
return within( propertyName, value );
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
"Non-existant spatial relation passed."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
<!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 extends the criterion API with spatial query expressions.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
|
@ -11,26 +11,26 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
|
||||
|
||||
/**
|
||||
* Registers all available spatial functions for a <code>Dialect</code>
|
||||
* <p>
|
||||
* Created by Karel Maesen, Geovise BVBA on 29/10/16.
|
||||
*/
|
||||
public abstract class SpatialFunctionsRegistry implements Iterable<Map.Entry<String, SQLFunction>>, Serializable {
|
||||
protected final Map<String, SQLFunction> functionMap = new HashMap<String, SQLFunction>();
|
||||
public abstract class SpatialFunctionsRegistry implements Iterable<Map.Entry<String, SqmFunctionDescriptor>>, Serializable {
|
||||
protected final Map<String, SqmFunctionDescriptor> functionMap = new HashMap<String, SqmFunctionDescriptor>();
|
||||
|
||||
public void put(String name, SQLFunction function) {
|
||||
public void put(String name, SqmFunctionDescriptor function) {
|
||||
this.functionMap.put( name, function );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Map.Entry<String, SQLFunction>> iterator() {
|
||||
public Iterator<Map.Entry<String, SqmFunctionDescriptor>> iterator() {
|
||||
return functionMap.entrySet().iterator();
|
||||
}
|
||||
|
||||
public SQLFunction get(String functionName) {
|
||||
public SqmFunctionDescriptor get(String functionName) {
|
||||
return functionMap.get( functionName );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,44 +7,13 @@
|
|||
|
||||
package org.hibernate.spatial.dialect.cockroachdb;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.CockroachDB201Dialect;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.dialect.postgis.PGGeometryTypeDescriptor;
|
||||
import org.hibernate.dialect.CockroachDialect;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
|
||||
/**
|
||||
* An @{code SpatialDialect} for CockroachDB 20.2 and later. CockroachDB's spatial features where introduced in
|
||||
* that version.
|
||||
*/
|
||||
public class CockroachDB202SpatialDialect extends CockroachDB201Dialect implements CockroachSpatialDialectTrait {
|
||||
|
||||
|
||||
public CockroachDB202SpatialDialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
PGGeometryTypeDescriptor.INSTANCE_WKB_2.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, SQLFunction> entry : functionsToRegister() ) {
|
||||
registerFunction( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
super.contributeTypes(
|
||||
typeContributions,
|
||||
serviceRegistry
|
||||
);
|
||||
delegateContributeTypes( typeContributions, serviceRegistry );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equivalentTypes(int typeCode1, int typeCode2) {
|
||||
return super.equivalentTypes( typeCode1, typeCode2 ) ||
|
||||
( isSpatial( typeCode1 ) && isSpatial( typeCode2 ) );
|
||||
}
|
||||
@Deprecated
|
||||
public class CockroachDB202SpatialDialect extends CockroachDialect implements SpatialDialect {
|
||||
}
|
||||
|
|
|
@ -44,32 +44,32 @@ public interface CockroachSpatialDialectTrait extends SpatialDialect {
|
|||
return DELEGATE.getSpatialFilterExpression( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
default String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
return DELEGATE.getSpatialAggregateSQL( columnName, aggregation );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
default String getDWithinSQL(String columnName) {
|
||||
return DELEGATE.getDWithinSQL( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
default String getHavingSridSQL(String columnName) {
|
||||
return DELEGATE.getHavingSridSQL( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
default String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
return DELEGATE.getIsEmptySQL( columnName, isEmpty );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
default boolean supportsFiltering() {
|
||||
return DELEGATE.supportsFiltering();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
default boolean supports(SpatialFunction function) {
|
||||
return DELEGATE.supports( function );
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import org.hibernate.type.descriptor.WrapperOptions;
|
|||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.BasicBinder;
|
||||
import org.hibernate.type.descriptor.jdbc.BasicExtractor;
|
||||
import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
|
||||
import org.geolatte.geom.Geometry;
|
||||
import org.geolatte.geom.codec.db.db2.Db2ClobDecoder;
|
||||
|
@ -30,7 +30,7 @@ import org.geolatte.geom.codec.db.db2.Db2ClobEncoder;
|
|||
* <p>
|
||||
* Created by Karel Maesen, Geovise BVBA, and David Adler, Adtech Geospatial
|
||||
*/
|
||||
public class DB2GeometryTypeDescriptor implements SqlTypeDescriptor {
|
||||
public class DB2GeometryTypeDescriptor implements JdbcTypeDescriptor {
|
||||
|
||||
|
||||
private final Integer srid;
|
||||
|
@ -40,7 +40,7 @@ public class DB2GeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getSqlType() {
|
||||
public int getJdbcType() {
|
||||
return Types.CLOB;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ public class DB2GeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
}
|
||||
|
||||
private String toText(X value, WrapperOptions options) {
|
||||
final Geometry<?> geometry = getJavaDescriptor().unwrap( value, Geometry.class, options );
|
||||
final Geometry<?> geometry = getJavaTypeDescriptor().unwrap( value, Geometry.class, options );
|
||||
final Db2ClobEncoder encoder = new Db2ClobEncoder();
|
||||
String encoded = encoder.encode( geometry );
|
||||
return encoded;
|
||||
|
@ -81,18 +81,18 @@ public class DB2GeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
|
||||
@Override
|
||||
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
|
||||
return getJavaDescriptor().wrap( toGeometry( rs.getObject( paramIndex ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( toGeometry( rs.getObject( paramIndex ) ), options );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
|
||||
return getJavaDescriptor().wrap( toGeometry( statement.getObject( index ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( toGeometry( statement.getObject( index ) ), options );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
|
||||
throws SQLException {
|
||||
return getJavaDescriptor().wrap( toGeometry( statement.getObject( name ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( toGeometry( statement.getObject( name ) ), options );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -35,298 +35,4 @@ import org.hibernate.type.Type;
|
|||
*/
|
||||
public class DB2SpatialDialect extends DB2Dialect implements SpatialDialect {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Map<Integer, String> spatialRelationNames = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Construct a DB2Spatial dialect. Register the geometry type and spatial
|
||||
* functions supported.
|
||||
*/
|
||||
public DB2SpatialDialect() {
|
||||
super();
|
||||
registerSpatialType();
|
||||
registerSpatialFunctions();
|
||||
initializeRelationNames();
|
||||
}
|
||||
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
final DB2GeometryTypeDescriptor typeDescriptor = mkDescriptor( serviceRegistry );
|
||||
typeContributions.contributeType( new GeolatteGeometryType( typeDescriptor ) );
|
||||
typeContributions.contributeType( new JTSGeometryType( typeDescriptor ) );
|
||||
|
||||
typeContributions.contributeJavaTypeDescriptor( GeolatteGeometryJavaTypeDescriptor.INSTANCE );
|
||||
typeContributions.contributeJavaTypeDescriptor( JTSGeometryJavaTypeDescriptor.INSTANCE );
|
||||
}
|
||||
|
||||
private DB2GeometryTypeDescriptor mkDescriptor(ServiceRegistry serviceRegistry) {
|
||||
ConfigurationService configurationService = serviceRegistry.getService( ConfigurationService.class );
|
||||
Integer srid = retrieveSridFromConfiguration( configurationService );
|
||||
return new DB2GeometryTypeDescriptor( srid );
|
||||
}
|
||||
|
||||
private Integer retrieveSridFromConfiguration(ConfigurationService configurationService) {
|
||||
Integer srid = 0;
|
||||
try {
|
||||
srid = Integer.parseInt( configurationService.getSetting(
|
||||
HibernateSpatialConfigurationSettings.DB2_DEFAULT_SRID,
|
||||
String.class,
|
||||
"0"
|
||||
) );
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
throw new HibernateException(
|
||||
"Invalid format for configuration parameter (Integer expected): " + HibernateSpatialConfigurationSettings.DB2_DEFAULT_SRID,
|
||||
e
|
||||
);
|
||||
}
|
||||
return srid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the map relating Hibernate Spatial relation constants to DB2 function names.
|
||||
*/
|
||||
private void initializeRelationNames() {
|
||||
|
||||
spatialRelationNames.put( SpatialRelation.EQUALS, "ST_EQUALS" );
|
||||
spatialRelationNames.put( SpatialRelation.DISJOINT, "ST_DISJOINT" );
|
||||
spatialRelationNames.put( SpatialRelation.TOUCHES, "ST_TOUCHES" );
|
||||
spatialRelationNames.put( SpatialRelation.CROSSES, "ST_CROSSES" );
|
||||
spatialRelationNames.put( SpatialRelation.WITHIN, "ST_WITHIN" );
|
||||
spatialRelationNames.put( SpatialRelation.OVERLAPS, "ST_OVERLAPS" );
|
||||
spatialRelationNames.put( SpatialRelation.CONTAINS, "ST_CONTAINS" );
|
||||
spatialRelationNames.put( SpatialRelation.INTERSECTS, "ST_INTERSECTS" );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register the spatial type.
|
||||
* The type, CLOB or BLOB is defined in DB2GeometryTypeDescriptor and must match
|
||||
* the type specified in the DB2_PROGRAM transform function.
|
||||
*/
|
||||
private void registerSpatialType() {
|
||||
|
||||
// Register Geometry column type
|
||||
registerColumnType( java.sql.Types.CLOB, " db2gse.ST_Geometry" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the spatial functions supported.
|
||||
*/
|
||||
private void registerSpatialFunctions() {
|
||||
|
||||
// Register functions used as spatial predicates
|
||||
// The first parameter of registerFunction is the name that Hibernate looks for in the HQL.
|
||||
// The first parameter of StandardSQLFunction is the DB2 spatial function name that will replace it.
|
||||
// The second parameter of StandardSQLFunction is the return type of the function, always integer for functions used as predicates.
|
||||
// This is used by Hibernate independent of Hibernate Spatial.
|
||||
//
|
||||
// Note that this somewhat duplicates the information in spatialRelationNames used by getSpatialRelateSQL which
|
||||
// is invoked by Hibernate Spatial to handle SpatialRelateExpression when this is used in a Criteria.
|
||||
|
||||
registerFunction( "equals", new StandardSQLFunction(
|
||||
"db2gse.ST_Equals",
|
||||
StandardBasicTypes.NUMERIC_BOOLEAN
|
||||
) );
|
||||
registerFunction( "disjoint", new StandardSQLFunction(
|
||||
"db2gse.ST_Disjoint",
|
||||
StandardBasicTypes.NUMERIC_BOOLEAN
|
||||
) );
|
||||
registerFunction( "touches", new StandardSQLFunction(
|
||||
"db2gse.ST_Touches",
|
||||
StandardBasicTypes.NUMERIC_BOOLEAN
|
||||
) );
|
||||
registerFunction( "crosses", new StandardSQLFunction(
|
||||
"db2gse.ST_Crosses",
|
||||
StandardBasicTypes.NUMERIC_BOOLEAN
|
||||
) );
|
||||
|
||||
registerFunction( "within", new StandardSQLFunction(
|
||||
"db2gse.ST_Within",
|
||||
StandardBasicTypes.NUMERIC_BOOLEAN
|
||||
) );
|
||||
registerFunction( "overlaps", new StandardSQLFunction(
|
||||
"db2gse.ST_Overlaps",
|
||||
StandardBasicTypes.NUMERIC_BOOLEAN
|
||||
) );
|
||||
registerFunction( "contains", new StandardSQLFunction(
|
||||
"db2gse.ST_Contains",
|
||||
StandardBasicTypes.NUMERIC_BOOLEAN
|
||||
) );
|
||||
registerFunction( "intersects", new StandardSQLFunction(
|
||||
"db2gse.ST_Intersects",
|
||||
StandardBasicTypes.NUMERIC_BOOLEAN
|
||||
) );
|
||||
registerFunction( "relate", new StandardSQLFunction(
|
||||
"db2gse.ST_Relate",
|
||||
StandardBasicTypes.NUMERIC_BOOLEAN
|
||||
) );
|
||||
|
||||
// Register functions on Geometry
|
||||
registerFunction( "dimension", new StandardSQLFunction(
|
||||
"db2gse.ST_Dimension",
|
||||
StandardBasicTypes.INTEGER
|
||||
) );
|
||||
registerFunction( "geometrytype", new StandardSQLFunction(
|
||||
"db2gse.ST_GeometryType",
|
||||
StandardBasicTypes.STRING
|
||||
) );
|
||||
registerFunction( "srid", new StandardSQLFunction(
|
||||
"db2gse.ST_Srsid",
|
||||
StandardBasicTypes.INTEGER
|
||||
) );
|
||||
registerFunction( "envelope", new StandardSQLFunction(
|
||||
"db2gse.ST_Envelope"
|
||||
) );
|
||||
registerFunction( "astext", new StandardSQLFunction(
|
||||
"db2gse.ST_AsText",
|
||||
StandardBasicTypes.STRING
|
||||
) );
|
||||
registerFunction( "asbinary", new StandardSQLFunction(
|
||||
"db2gse.ST_AsBinary",
|
||||
StandardBasicTypes.BINARY
|
||||
) );
|
||||
registerFunction( "isempty", new StandardSQLFunction(
|
||||
"db2gse.ST_IsEmpty",
|
||||
StandardBasicTypes.NUMERIC_BOOLEAN
|
||||
) );
|
||||
registerFunction( "issimple", new StandardSQLFunction(
|
||||
"db2gse.ST_IsSimple",
|
||||
StandardBasicTypes.NUMERIC_BOOLEAN
|
||||
) );
|
||||
registerFunction( "boundary", new StandardSQLFunction(
|
||||
"db2gse.ST_Boundary"
|
||||
) );
|
||||
|
||||
// Register functions that support spatial analysis
|
||||
registerFunction( "distance", new StandardSQLFunction(
|
||||
"db2gse.ST_Distance",
|
||||
StandardBasicTypes.DOUBLE
|
||||
) );
|
||||
registerFunction( "buffer", new StandardSQLFunction(
|
||||
"db2gse.ST_Buffer"
|
||||
) );
|
||||
registerFunction( "convexhull", new StandardSQLFunction(
|
||||
"db2gse.ST_ConvexHull"
|
||||
) );
|
||||
registerFunction( "intersection", new StandardSQLFunction(
|
||||
"db2gse.ST_Intersection"
|
||||
) );
|
||||
registerFunction( "geomunion", new StandardSQLFunction(
|
||||
"db2gse.ST_Union"
|
||||
) );
|
||||
registerFunction( "difference", new StandardSQLFunction(
|
||||
"db2gse.ST_Difference"
|
||||
) );
|
||||
registerFunction( "symdifference", new StandardSQLFunction(
|
||||
"db2gse.ST_SymDifference"
|
||||
) );
|
||||
|
||||
// Register non-SFS functions listed in Hibernate Spatial
|
||||
registerFunction( "dwithin", new DWithinFunction() );
|
||||
|
||||
registerFunction( "geomFromText", new StandardSQLFunction(
|
||||
"DB2GSE.ST_GeomFromText"
|
||||
) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDWithinSQL(String columnName) {
|
||||
return "db2gse.ST_Intersects(" + columnName + ", db2gse.ST_Buffer(?, ?, 'METER')) = 1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHavingSridSQL(String columnName) {
|
||||
return "( db2gse.ST_srsid(" + columnName + ") = ?)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
if ( isEmpty ) {
|
||||
return "( db2gse.ST_IsEmpty(" + columnName + ") = 1)";
|
||||
}
|
||||
else {
|
||||
return "( db2gse.ST_IsEmpty(" + columnName + ") = 0)";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialAggregateSQL(String columnName, int type) {
|
||||
switch ( type ) {
|
||||
case SpatialAggregate.EXTENT:
|
||||
return "db2gse.ST_GetAggrResult(MAX(db2gse.st_BuildMBRAggr(" + columnName + ")))";
|
||||
case SpatialAggregate.UNION:
|
||||
return "db2gse.ST_GetAggrResult(MAX(db2gse.st_BuildUnionAggr(" + columnName + ")))";
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
"Aggregation of type "
|
||||
+ type + " are not supported by this dialect"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialFilterExpression(String arg0) {
|
||||
throw new UnsupportedOperationException( "DB2 Dialect doesn't support spatial filtering" );
|
||||
}
|
||||
|
||||
//Temporary Fix for HHH-6074
|
||||
@Override
|
||||
public String getTypeName(int code, long length, int precision, int scale) throws HibernateException {
|
||||
if ( code == 3000 ) {
|
||||
return "DB2GSE.ST_GEOMETRY";
|
||||
}
|
||||
return super.getTypeName( code, length, precision, scale );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
String relationName = spatialRelationNames.get( spatialRelation );
|
||||
if ( relationName != null ) {
|
||||
if ( spatialRelation != SpatialRelation.DISJOINT ) {
|
||||
return " db2gse." + relationName + "(" + columnName + ", ?) = 1 SELECTIVITY .0001";
|
||||
}
|
||||
else {
|
||||
// SELECTIVITY not supported for ST_Disjoint UDF
|
||||
return " db2gse." + relationName + "(" + columnName + ", ?) = 1";
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"Spatial relation " + spatialRelation + " not implemented" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return ( getFunctions().get( function.toString() ) != null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsFiltering() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static class DWithinFunction extends StandardSQLFunction {
|
||||
|
||||
public DWithinFunction() {
|
||||
super( "db2gse.ST_Dwithin", StandardBasicTypes.NUMERIC_BOOLEAN );
|
||||
}
|
||||
|
||||
public String render(Type firstArgumentType, final List args, final SessionFactoryImplementor factory) {
|
||||
StringBuilder sb = new StringBuilder( "db2gse.ST_Intersects( " );
|
||||
sb.append( (String) args.get( 0 ) )
|
||||
.append( ", db2gse.ST_Buffer(" )
|
||||
.append( (String) args.get( 1 ) )
|
||||
.append( ", " )
|
||||
.append( (String) args.get( 2 ) )
|
||||
.append( ", 'METER'))" );
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,158 +35,4 @@ import org.hibernate.type.Type;
|
|||
*/
|
||||
public class GeoDBDialect extends H2Dialect implements SpatialDialect {
|
||||
|
||||
|
||||
/**
|
||||
* Constructor. Registers OGC simple feature functions (see
|
||||
* http://portal.opengeospatial.org/files/?artifact_id=829 for details).
|
||||
* <p/>
|
||||
* Note for the registerfunction method: it registers non-standard database
|
||||
* functions: first argument is the internal (OGC standard) function name,
|
||||
* second the name as it occurs in the spatial dialect
|
||||
*/
|
||||
public GeoDBDialect() {
|
||||
super();
|
||||
|
||||
// Register Geometry column type
|
||||
registerColumnType( GeoDBGeometryTypeDescriptor.INSTANCE.getSqlType(), "GEOMETRY" );
|
||||
|
||||
// Register functions that operate on spatial types
|
||||
registerFunction( "dimension", new StandardSQLFunction( "ST_Dimension", StandardBasicTypes.INTEGER ) );
|
||||
registerFunction( "geometrytype", new StandardSQLFunction( "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_AsEWKB", 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" ) );
|
||||
|
||||
registerFunction( "dwithin", new StandardSQLFunction( "ST_DWithin", StandardBasicTypes.BOOLEAN ) );
|
||||
|
||||
// Register Spatial Filter function
|
||||
registerFunction( SpatialFunction.filter.name(), new FilterFunction() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
super.contributeTypes( typeContributions, serviceRegistry );
|
||||
typeContributions.contributeType( new GeolatteGeometryType( GeoDBGeometryTypeDescriptor.INSTANCE ) );
|
||||
typeContributions.contributeType( new JTSGeometryType( GeoDBGeometryTypeDescriptor.INSTANCE ) );
|
||||
|
||||
typeContributions.contributeJavaTypeDescriptor( GeolatteGeometryJavaTypeDescriptor.INSTANCE );
|
||||
typeContributions.contributeJavaTypeDescriptor( JTSGeometryJavaTypeDescriptor.INSTANCE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
switch ( aggregation ) {
|
||||
// NOT YET AVAILABLE IN GEODB
|
||||
// case SpatialAggregate.EXTENT:
|
||||
// StringBuilder stbuf = new StringBuilder();
|
||||
// stbuf.append("extent(").append(columnName).append(")");
|
||||
// return stbuf.toString();
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
"Aggregations of type " + aggregation + " are not supported 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 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 boolean supportsFiltering() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return function != SpatialFunction.difference && ( getFunctions().get( function.toString() ) != null );
|
||||
}
|
||||
|
||||
private static class FilterFunction extends StandardSQLFunction {
|
||||
|
||||
public FilterFunction() {
|
||||
super( "&&" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String render(
|
||||
Type firstArgumentType, List arguments, SessionFactoryImplementor sessionFactory) {
|
||||
int argumentCount = arguments.size();
|
||||
if ( argumentCount != 2 ) {
|
||||
throw new QueryException( String.format( Locale.ENGLISH,"2 arguments expected, received %d", argumentCount ) );
|
||||
}
|
||||
|
||||
return Stream.of(
|
||||
String.valueOf( arguments.get( 0 ) ),
|
||||
getRenderedName( arguments ),
|
||||
String.valueOf( arguments.get( 1 ) )
|
||||
).collect( Collectors.joining( " ", "(", ")" ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import org.hibernate.type.descriptor.WrapperOptions;
|
|||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.BasicBinder;
|
||||
import org.hibernate.type.descriptor.jdbc.BasicExtractor;
|
||||
import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
|
||||
import org.geolatte.geom.Geometry;
|
||||
|
||||
|
@ -28,7 +28,7 @@ import org.geolatte.geom.Geometry;
|
|||
*
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
*/
|
||||
public class GeoDBGeometryTypeDescriptor implements SqlTypeDescriptor {
|
||||
public class GeoDBGeometryTypeDescriptor implements JdbcTypeDescriptor {
|
||||
|
||||
/**
|
||||
* An instance of this Descriptor
|
||||
|
@ -36,7 +36,7 @@ public class GeoDBGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
public static final GeoDBGeometryTypeDescriptor INSTANCE = new GeoDBGeometryTypeDescriptor();
|
||||
|
||||
@Override
|
||||
public int getSqlType() {
|
||||
public int getJdbcType() {
|
||||
return Types.ARRAY;
|
||||
}
|
||||
|
||||
|
@ -51,14 +51,14 @@ public class GeoDBGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
@Override
|
||||
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
|
||||
throws SQLException {
|
||||
final Geometry geometry = getJavaDescriptor().unwrap( value, Geometry.class, options );
|
||||
final Geometry geometry = getJavaTypeDescriptor().unwrap( value, Geometry.class, options );
|
||||
st.setBytes( index, GeoDbWkb.to( geometry ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
|
||||
throws SQLException {
|
||||
final Geometry geometry = getJavaDescriptor().unwrap( value, Geometry.class, options );
|
||||
final Geometry geometry = getJavaTypeDescriptor().unwrap( value, Geometry.class, options );
|
||||
st.setBytes( name, GeoDbWkb.to( geometry ) );
|
||||
}
|
||||
};
|
||||
|
@ -70,18 +70,18 @@ public class GeoDBGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
|
||||
@Override
|
||||
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
|
||||
return getJavaDescriptor().wrap( GeoDbWkb.from( rs.getObject( paramIndex ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( GeoDbWkb.from( rs.getObject( paramIndex ) ), options );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
|
||||
return getJavaDescriptor().wrap( GeoDbWkb.from( statement.getObject( index ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( GeoDbWkb.from( statement.getObject( index ) ), options );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
|
||||
throws SQLException {
|
||||
return getJavaDescriptor().wrap( GeoDbWkb.from( statement.getObject( name ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( GeoDbWkb.from( statement.getObject( name ) ), options );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -18,11 +18,11 @@ import org.hibernate.type.descriptor.WrapperOptions;
|
|||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.BasicBinder;
|
||||
import org.hibernate.type.descriptor.jdbc.BasicExtractor;
|
||||
import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
|
||||
import org.geolatte.geom.Geometry;
|
||||
|
||||
public class HANAGeometryTypeDescriptor implements SqlTypeDescriptor {
|
||||
public class HANAGeometryTypeDescriptor implements JdbcTypeDescriptor {
|
||||
|
||||
public static final HANAGeometryTypeDescriptor CRS_LOADING_INSTANCE = new HANAGeometryTypeDescriptor( true );
|
||||
public static final HANAGeometryTypeDescriptor INSTANCE = new HANAGeometryTypeDescriptor( false );
|
||||
|
@ -34,7 +34,7 @@ public class HANAGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getSqlType() {
|
||||
public int getJdbcType() {
|
||||
return Types.OTHER;
|
||||
}
|
||||
|
||||
|
@ -50,14 +50,14 @@ public class HANAGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
@Override
|
||||
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
|
||||
throws SQLException {
|
||||
final Geometry<?> geometry = getJavaDescriptor().unwrap( value, Geometry.class, options );
|
||||
final Geometry<?> geometry = getJavaTypeDescriptor().unwrap( value, Geometry.class, options );
|
||||
st.setObject( index, HANASpatialUtils.toEWKB( geometry ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
|
||||
throws SQLException {
|
||||
final Geometry<?> geometry = getJavaDescriptor().unwrap( value, Geometry.class, options );
|
||||
final Geometry<?> geometry = getJavaTypeDescriptor().unwrap( value, Geometry.class, options );
|
||||
st.setObject( name, HANASpatialUtils.toEWKB( geometry ) );
|
||||
}
|
||||
|
||||
|
@ -71,22 +71,23 @@ public class HANAGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
@Override
|
||||
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
|
||||
if ( HANAGeometryTypeDescriptor.this.determineCrsIdFromDatabase ) {
|
||||
return getJavaDescriptor().wrap( HANASpatialUtils.toGeometry( rs, paramIndex ), options );
|
||||
throw new UnsupportedOperationException( "First need to refactor HANASpatialUtils" );
|
||||
//return getJavaTypeDescriptor().wrap( HANASpatialUtils.toGeometry( rs, paramIndex ), options );
|
||||
}
|
||||
else {
|
||||
return getJavaDescriptor().wrap( HANASpatialUtils.toGeometry( rs.getObject( paramIndex ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( HANASpatialUtils.toGeometry( rs.getObject( paramIndex ) ), options );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
|
||||
return getJavaDescriptor().wrap( HANASpatialUtils.toGeometry( statement.getObject( index ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( HANASpatialUtils.toGeometry( statement.getObject( index ) ), options );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
|
||||
throws SQLException {
|
||||
return getJavaDescriptor().wrap( HANASpatialUtils.toGeometry( statement.getObject( name ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( HANASpatialUtils.toGeometry( statement.getObject( name ) ), options );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -18,11 +18,11 @@ import org.hibernate.type.descriptor.WrapperOptions;
|
|||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.BasicBinder;
|
||||
import org.hibernate.type.descriptor.jdbc.BasicExtractor;
|
||||
import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
|
||||
import org.geolatte.geom.Point;
|
||||
|
||||
public class HANAPointTypeDescriptor implements SqlTypeDescriptor {
|
||||
public class HANAPointTypeDescriptor implements JdbcTypeDescriptor {
|
||||
|
||||
/**
|
||||
* An instance of the descrtiptor
|
||||
|
@ -31,7 +31,7 @@ public class HANAPointTypeDescriptor implements SqlTypeDescriptor {
|
|||
private static final long serialVersionUID = -6978798264716544804L;
|
||||
|
||||
@Override
|
||||
public int getSqlType() {
|
||||
public int getJdbcType() {
|
||||
return Types.STRUCT;
|
||||
}
|
||||
|
||||
|
@ -47,14 +47,14 @@ public class HANAPointTypeDescriptor implements SqlTypeDescriptor {
|
|||
@Override
|
||||
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
|
||||
throws SQLException {
|
||||
final Point<?> geometry = getJavaDescriptor().unwrap( value, Point.class, options );
|
||||
final Point<?> geometry = getJavaTypeDescriptor().unwrap( value, Point.class, options );
|
||||
st.setObject( index, HANASpatialUtils.toEWKB( geometry ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
|
||||
throws SQLException {
|
||||
final Point<?> geometry = getJavaDescriptor().unwrap( value, Point.class, options );
|
||||
final Point<?> geometry = getJavaTypeDescriptor().unwrap( value, Point.class, options );
|
||||
st.setObject( name, HANASpatialUtils.toEWKB( geometry ) );
|
||||
}
|
||||
|
||||
|
@ -67,18 +67,18 @@ public class HANAPointTypeDescriptor implements SqlTypeDescriptor {
|
|||
|
||||
@Override
|
||||
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
|
||||
return getJavaDescriptor().wrap( HANASpatialUtils.toGeometry( rs.getObject( paramIndex ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( HANASpatialUtils.toGeometry( rs.getObject( paramIndex ) ), options );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
|
||||
return getJavaDescriptor().wrap( HANASpatialUtils.toGeometry( statement.getObject( index ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( HANASpatialUtils.toGeometry( statement.getObject( index ) ), options );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
|
||||
throws SQLException {
|
||||
return getJavaDescriptor().wrap( HANASpatialUtils.toGeometry( statement.getObject( name ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( HANASpatialUtils.toGeometry( statement.getObject( name ) ), options );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package org.hibernate.spatial.dialect.hana;
|
||||
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
public class HANASpatialAggregate extends StandardSQLFunction {
|
||||
|
@ -15,7 +16,7 @@ public class HANASpatialAggregate extends StandardSQLFunction {
|
|||
super( name );
|
||||
}
|
||||
|
||||
public HANASpatialAggregate(String name, Type registeredType) {
|
||||
public HANASpatialAggregate(String name, AllowableFunctionReturnType registeredType) {
|
||||
super( name, registeredType );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,404 +27,4 @@ import org.hibernate.type.StandardBasicTypes;
|
|||
import org.hibernate.type.Type;
|
||||
|
||||
public class HANASpatialDialect extends HANAColumnStoreDialect implements SpatialDialect {
|
||||
|
||||
private static final long serialVersionUID = -432631517465714911L;
|
||||
|
||||
private static final String DETERMINE_CRS_ID_FROM_DATABASE_PARAMETER_NAME = "hibernate.spatial.dialect.hana.determine_crs_id_from_database";
|
||||
|
||||
public HANASpatialDialect() {
|
||||
registerColumnType( HANAGeometryTypeDescriptor.INSTANCE.getSqlType(), "ST_GEOMETRY" );
|
||||
registerColumnType( HANAPointTypeDescriptor.INSTANCE.getSqlType(), "ST_POINT" );
|
||||
|
||||
registerHibernateType( Types.OTHER, new GeolatteGeometryType( HANAGeometryTypeDescriptor.INSTANCE ).getName() );
|
||||
|
||||
/*
|
||||
* Hibernate Spatial functions
|
||||
*/
|
||||
registerFunction(
|
||||
SpatialFunction.asbinary.name(),
|
||||
new HANASpatialFunction( "ST_AsBinary", StandardBasicTypes.MATERIALIZED_BLOB, false ) );
|
||||
registerFunction(
|
||||
SpatialFunction.astext.name(),
|
||||
new HANASpatialFunction( "ST_AsText", StandardBasicTypes.MATERIALIZED_CLOB, false ) );
|
||||
registerFunction( SpatialFunction.boundary.name(), new HANASpatialFunction( "ST_Boundary", false ) );
|
||||
registerFunction( SpatialFunction.buffer.name(), new HANASpatialFunction( "ST_Buffer", false ) );
|
||||
registerFunction(
|
||||
SpatialFunction.contains.name(),
|
||||
new HANASpatialFunction( "ST_Contains", StandardBasicTypes.NUMERIC_BOOLEAN, true ) );
|
||||
registerFunction( SpatialFunction.convexhull.name(), new HANASpatialFunction( "ST_ConvexHull", false ) );
|
||||
registerFunction(
|
||||
SpatialFunction.crosses.name(),
|
||||
new HANASpatialFunction( "ST_Crosses", StandardBasicTypes.NUMERIC_BOOLEAN, true ) );
|
||||
registerFunction( SpatialFunction.difference.name(), new HANASpatialFunction( "ST_Difference", true ) );
|
||||
registerFunction(
|
||||
SpatialFunction.dimension.name(),
|
||||
new HANASpatialFunction( "ST_Dimension", StandardBasicTypes.INTEGER, false ) );
|
||||
registerFunction(
|
||||
SpatialFunction.disjoint.name(),
|
||||
new HANASpatialFunction( "ST_Disjoint", StandardBasicTypes.NUMERIC_BOOLEAN, true ) );
|
||||
registerFunction(
|
||||
SpatialFunction.distance.name(),
|
||||
new HANASpatialFunction( "ST_Distance", StandardBasicTypes.DOUBLE, true ) );
|
||||
registerFunction(
|
||||
SpatialFunction.dwithin.name(),
|
||||
new HANASpatialFunction( "ST_WithinDistance", StandardBasicTypes.NUMERIC_BOOLEAN, true ) );
|
||||
registerFunction( SpatialFunction.envelope.name(), new HANASpatialFunction( "ST_Envelope", true ) );
|
||||
registerFunction(
|
||||
SpatialFunction.equals.name(),
|
||||
new HANASpatialFunction( "ST_Equals", StandardBasicTypes.NUMERIC_BOOLEAN, true ) );
|
||||
registerFunction( SpatialFunction.extent.name(), new HANASpatialAggregate( "ST_EnvelopeAggr" ) );
|
||||
registerFunction(
|
||||
SpatialFunction.geometrytype.name(),
|
||||
new HANASpatialFunction( "ST_GeometryType", StandardBasicTypes.STRING, false ) );
|
||||
registerFunction( SpatialFunction.geomunion.name(), new HANASpatialFunction( "ST_Union", true ) );
|
||||
registerFunction( SpatialFunction.intersection.name(), new HANASpatialFunction( "ST_Intersection", true ) );
|
||||
registerFunction(
|
||||
SpatialFunction.intersects.name(),
|
||||
new HANASpatialFunction( "ST_Intersects", StandardBasicTypes.NUMERIC_BOOLEAN, true ) );
|
||||
registerFunction(
|
||||
SpatialFunction.isempty.name(),
|
||||
new HANASpatialFunction( "ST_IsEmpty", StandardBasicTypes.NUMERIC_BOOLEAN, false ) );
|
||||
registerFunction(
|
||||
SpatialFunction.issimple.name(),
|
||||
new HANASpatialFunction( "ST_IsSimple", StandardBasicTypes.NUMERIC_BOOLEAN, false ) );
|
||||
registerFunction(
|
||||
SpatialFunction.overlaps.name(),
|
||||
new HANASpatialFunction( "ST_Overlaps", StandardBasicTypes.NUMERIC_BOOLEAN, true ) );
|
||||
registerFunction(
|
||||
SpatialFunction.relate.name(),
|
||||
new HANASpatialFunction( "ST_Relate", StandardBasicTypes.NUMERIC_BOOLEAN, true ) );
|
||||
registerFunction(
|
||||
SpatialFunction.srid.name(),
|
||||
new HANASpatialFunction( "ST_SRID", StandardBasicTypes.INTEGER, false ) );
|
||||
registerFunction( SpatialFunction.symdifference.name(), new HANASpatialFunction( "ST_SymDifference", true ) );
|
||||
registerFunction(
|
||||
SpatialFunction.touches.name(),
|
||||
new HANASpatialFunction( "ST_Touches", StandardBasicTypes.NUMERIC_BOOLEAN, true ) );
|
||||
registerFunction( SpatialFunction.transform.name(), new HANASpatialFunction( "ST_Transform", false ) );
|
||||
registerFunction(
|
||||
SpatialFunction.within.name(),
|
||||
new HANASpatialFunction( "ST_Within", StandardBasicTypes.NUMERIC_BOOLEAN, true ) );
|
||||
registerFunction(
|
||||
SpatialFunction.filter.name(),
|
||||
new FilterFunction() );
|
||||
|
||||
/*
|
||||
* Additional HANA functions
|
||||
*/
|
||||
registerFunction( HANASpatialFunctions.alphashape.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.alphashape.getFunctionName(), false ) );
|
||||
registerFunction( HANASpatialFunctions.area.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.area.getFunctionName(), StandardBasicTypes.DOUBLE, false ) );
|
||||
registerFunction( HANASpatialFunctions.asewkb.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.asewkb.getFunctionName(), StandardBasicTypes.MATERIALIZED_BLOB, false ) );
|
||||
registerFunction( HANASpatialFunctions.asewkt.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.asewkt.getFunctionName(), StandardBasicTypes.MATERIALIZED_CLOB, false ) );
|
||||
registerFunction( HANASpatialFunctions.asgeojson.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.asgeojson.getFunctionName(), StandardBasicTypes.MATERIALIZED_CLOB, false ) );
|
||||
registerFunction( HANASpatialFunctions.assvg.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.assvg.getFunctionName(), StandardBasicTypes.MATERIALIZED_CLOB, false ) );
|
||||
registerFunction( HANASpatialFunctions.assvgaggr.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.assvgaggr.getFunctionName(), StandardBasicTypes.MATERIALIZED_CLOB, false, true ) );
|
||||
registerFunction( HANASpatialFunctions.aswkb.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.aswkb.getFunctionName(), StandardBasicTypes.MATERIALIZED_BLOB, false ) );
|
||||
registerFunction( HANASpatialFunctions.aswkt.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.aswkt.getFunctionName(), StandardBasicTypes.MATERIALIZED_CLOB, false ) );
|
||||
registerFunction( HANASpatialFunctions.centroid.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.centroid.getFunctionName(), false ) );
|
||||
registerFunction( HANASpatialFunctions.convexhullaggr.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.convexhullaggr.getFunctionName(), true, true ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.coorddim.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.coorddim.getFunctionName(), StandardBasicTypes.INTEGER, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.coveredby.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.coveredby.getFunctionName(), StandardBasicTypes.NUMERIC_BOOLEAN, true ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.covers.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.covers.getFunctionName(), StandardBasicTypes.NUMERIC_BOOLEAN, true ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.endpoint.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.endpoint.getFunctionName(), false ) );
|
||||
registerFunction( HANASpatialFunctions.envelopeaggr.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.envelopeaggr.getFunctionName(), true, true ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.exteriorring.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.exteriorring.getFunctionName(), false ) );
|
||||
registerFunction( HANASpatialFunctions.geomfromewkb.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.geomfromewkb.getFunctionName(), false, true ) );
|
||||
registerFunction( HANASpatialFunctions.geomfromewkt.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.geomfromewkt.getFunctionName(), false, true ) );
|
||||
registerFunction( HANASpatialFunctions.geomfromtext.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.geomfromtext.getFunctionName(), false, true ) );
|
||||
registerFunction( HANASpatialFunctions.geomfromwkb.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.geomfromwkb.getFunctionName(), false, true ) );
|
||||
registerFunction( HANASpatialFunctions.geomfromwkt.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.geomfromwkt.getFunctionName(), false, true ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.geometryn.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.geometryn.getFunctionName(), false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.interiorringn.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.interiorringn.getFunctionName(), false ) );
|
||||
registerFunction( HANASpatialFunctions.intersectionaggr.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.intersectionaggr.getFunctionName(), true, true ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.intersectsrect.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.intersectsrect.getFunctionName(), StandardBasicTypes.NUMERIC_BOOLEAN,
|
||||
new boolean[]{ true, true } ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.is3d.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.is3d.getFunctionName(), StandardBasicTypes.NUMERIC_BOOLEAN, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.isclosed.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.isclosed.getFunctionName(), StandardBasicTypes.NUMERIC_BOOLEAN, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.ismeasured.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.ismeasured.getFunctionName(), StandardBasicTypes.NUMERIC_BOOLEAN, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.isring.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.isring.getFunctionName(), StandardBasicTypes.NUMERIC_BOOLEAN, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.isvalid.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.isvalid.getFunctionName(), StandardBasicTypes.NUMERIC_BOOLEAN, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.length.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.length.getFunctionName(), StandardBasicTypes.DOUBLE, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.m.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.m.getFunctionName(), StandardBasicTypes.DOUBLE, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.mmax.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.mmax.getFunctionName(), StandardBasicTypes.DOUBLE, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.mmin.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.mmin.getFunctionName(), StandardBasicTypes.DOUBLE, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.numgeometries.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.numgeometries.getFunctionName(), StandardBasicTypes.INTEGER, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.numinteriorring.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.numinteriorring.getFunctionName(), StandardBasicTypes.INTEGER, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.numinteriorrings.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.numinteriorrings.getFunctionName(), StandardBasicTypes.INTEGER, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.numpoints.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.numpoints.getFunctionName(), StandardBasicTypes.INTEGER, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.orderingequals.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.orderingequals.getFunctionName(), StandardBasicTypes.NUMERIC_BOOLEAN, true ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.perimeter.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.perimeter.getFunctionName(), StandardBasicTypes.DOUBLE, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.pointonsurface.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.pointonsurface.getFunctionName(), false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.pointn.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.pointn.getFunctionName(), false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.snaptogrid.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.snaptogrid.getFunctionName(), false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.startpoint.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.startpoint.getFunctionName(), false ) );
|
||||
registerFunction( HANASpatialFunctions.unionaggr.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.unionaggr.getFunctionName(), true, true ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.x.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.x.getFunctionName(), StandardBasicTypes.DOUBLE, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.xmax.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.xmax.getFunctionName(), StandardBasicTypes.DOUBLE, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.xmin.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.xmin.getFunctionName(), StandardBasicTypes.DOUBLE, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.y.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.y.getFunctionName(), StandardBasicTypes.DOUBLE, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.ymax.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.ymax.getFunctionName(), StandardBasicTypes.DOUBLE, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.ymin.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.ymin.getFunctionName(), StandardBasicTypes.DOUBLE, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.z.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.z.getFunctionName(), StandardBasicTypes.DOUBLE, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.zmax.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.zmax.getFunctionName(), StandardBasicTypes.DOUBLE, false ) );
|
||||
registerFunction(
|
||||
HANASpatialFunctions.zmin.name(),
|
||||
new HANASpatialFunction( HANASpatialFunctions.zmin.getFunctionName(), StandardBasicTypes.DOUBLE, false ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
switch ( spatialRelation ) {
|
||||
case SpatialRelation.WITHIN:
|
||||
return columnName + ".ST_Within(ST_GeomFromEWKB(?)) = 1";
|
||||
case SpatialRelation.CONTAINS:
|
||||
return columnName + ".ST_Contains(ST_GeomFromEWKB(?)) = 1";
|
||||
case SpatialRelation.CROSSES:
|
||||
return columnName + ".ST_Crosses(ST_GeomFromEWKB(?)) = 1";
|
||||
case SpatialRelation.OVERLAPS:
|
||||
return columnName + ".ST_Overlaps(ST_GeomFromEWKB(?)) = 1";
|
||||
case SpatialRelation.DISJOINT:
|
||||
return columnName + ".ST_Disjoint(ST_GeomFromEWKB(?)) = 1";
|
||||
case SpatialRelation.INTERSECTS:
|
||||
return columnName + ".ST_Intersects(ST_GeomFromEWKB(?)) = 1";
|
||||
case SpatialRelation.TOUCHES:
|
||||
return columnName + ".ST_Touches(ST_GeomFromEWKB(?)) = 1";
|
||||
case SpatialRelation.EQUALS:
|
||||
return columnName + ".ST_Equals(ST_GeomFromEWKB(?)) = 1";
|
||||
case SpatialRelation.FILTER:
|
||||
return columnName + ".ST_IntersectsFilter(ST_GeomFromEWKB(?)) = 1";
|
||||
default:
|
||||
throw new IllegalArgumentException( "Spatial relation is not known by this dialect" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
super.contributeTypes( typeContributions, serviceRegistry );
|
||||
|
||||
final ConfigurationService configurationService = serviceRegistry.getService( ConfigurationService.class );
|
||||
boolean determineCrsIdFromDatabase = configurationService.getSetting(
|
||||
DETERMINE_CRS_ID_FROM_DATABASE_PARAMETER_NAME,
|
||||
new Converter<Boolean>() {
|
||||
|
||||
@Override
|
||||
public Boolean convert(Object value) {
|
||||
return Boolean.valueOf( value.toString() );
|
||||
}
|
||||
|
||||
},
|
||||
Boolean.FALSE ).booleanValue();
|
||||
|
||||
if ( determineCrsIdFromDatabase ) {
|
||||
typeContributions.contributeType( new GeolatteGeometryType( HANAGeometryTypeDescriptor.CRS_LOADING_INSTANCE ) );
|
||||
typeContributions.contributeType( new JTSGeometryType( HANAGeometryTypeDescriptor.CRS_LOADING_INSTANCE ) );
|
||||
}
|
||||
else {
|
||||
typeContributions.contributeType( new GeolatteGeometryType( HANAGeometryTypeDescriptor.INSTANCE ) );
|
||||
typeContributions.contributeType( new JTSGeometryType( HANAGeometryTypeDescriptor.INSTANCE ) );
|
||||
}
|
||||
|
||||
typeContributions.contributeJavaTypeDescriptor( GeolatteGeometryJavaTypeDescriptor.INSTANCE );
|
||||
typeContributions.contributeJavaTypeDescriptor( JTSGeometryJavaTypeDescriptor.INSTANCE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialFilterExpression(String columnName) {
|
||||
return columnName + ".ST_IntersectsFilter(ST_GeomFromEWKB(?)) = 1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
switch ( aggregation ) {
|
||||
case SpatialAggregate.EXTENT:
|
||||
return "ST_EnvelopeAggr(" + columnName + ")";
|
||||
default:
|
||||
throw new IllegalArgumentException( "The aggregate type [" + aggregation + "] is not known by this dialect" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDWithinSQL(String columnName) {
|
||||
return columnName + ".ST_WithinDistance(ST_GeomFromEWKB(?), ?) = 1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHavingSridSQL(String columnName) {
|
||||
return columnName + ".ST_SRID() = ?";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
return columnName + ".ST_IsEmpty() = " + ( isEmpty ? 1 : 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsFiltering() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
switch ( function ) {
|
||||
case asbinary:
|
||||
return true;
|
||||
case astext:
|
||||
return true;
|
||||
case boundary:
|
||||
return true;
|
||||
case buffer:
|
||||
return true;
|
||||
case contains:
|
||||
return true;
|
||||
case convexhull:
|
||||
return true;
|
||||
case crosses:
|
||||
return true;
|
||||
case difference:
|
||||
return true;
|
||||
case dimension:
|
||||
return true;
|
||||
case disjoint:
|
||||
return true;
|
||||
case distance:
|
||||
return true;
|
||||
case dwithin:
|
||||
return true;
|
||||
case envelope:
|
||||
return true;
|
||||
case equals:
|
||||
return true;
|
||||
case extent:
|
||||
return true;
|
||||
case geometrytype:
|
||||
return true;
|
||||
case geomunion:
|
||||
return true;
|
||||
case intersection:
|
||||
return true;
|
||||
case intersects:
|
||||
return true;
|
||||
case isempty:
|
||||
return true;
|
||||
case issimple:
|
||||
return true;
|
||||
case overlaps:
|
||||
return true;
|
||||
case relate:
|
||||
return true;
|
||||
case srid:
|
||||
return true;
|
||||
case symdifference:
|
||||
return true;
|
||||
case touches:
|
||||
return true;
|
||||
case transform:
|
||||
return true;
|
||||
case within:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static class FilterFunction extends HANASpatialFunction {
|
||||
|
||||
public FilterFunction() {
|
||||
super( "ST_IntersectsFilter", StandardBasicTypes.NUMERIC_BOOLEAN, true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String render(
|
||||
Type firstArgumentType, List arguments, SessionFactoryImplementor sessionFactory) {
|
||||
return super.render( firstArgumentType, arguments, sessionFactory ) + " = 1";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.util.List;
|
|||
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
public class HANASpatialFunction extends StandardSQLFunction {
|
||||
|
@ -32,13 +33,13 @@ public class HANASpatialFunction extends StandardSQLFunction {
|
|||
this.staticFunction = staticFunction;
|
||||
}
|
||||
|
||||
public HANASpatialFunction(String name, Type registeredType, boolean firstArgumentIsGeometryType) {
|
||||
public HANASpatialFunction(String name, AllowableFunctionReturnType registeredType, boolean firstArgumentIsGeometryType) {
|
||||
super( name, registeredType );
|
||||
this.argumentIsGeometryTypeMask.set( 1, firstArgumentIsGeometryType );
|
||||
this.staticFunction = false;
|
||||
}
|
||||
|
||||
public HANASpatialFunction(String name, Type registeredType, boolean[] argumentIsGeometryTypeMask) {
|
||||
public HANASpatialFunction(String name, AllowableFunctionReturnType registeredType, boolean[] argumentIsGeometryTypeMask) {
|
||||
super( name, registeredType );
|
||||
for ( int i = 0; i < argumentIsGeometryTypeMask.length; i++ ) {
|
||||
this.argumentIsGeometryTypeMask.set( i + 1, argumentIsGeometryTypeMask[i] );
|
||||
|
@ -46,13 +47,13 @@ public class HANASpatialFunction extends StandardSQLFunction {
|
|||
this.staticFunction = false;
|
||||
}
|
||||
|
||||
public HANASpatialFunction(String name, Type registeredType, boolean firstArgumentIsGeometryType, boolean staticFunction) {
|
||||
public HANASpatialFunction(String name, AllowableFunctionReturnType registeredType, boolean firstArgumentIsGeometryType, boolean staticFunction) {
|
||||
super( name, registeredType );
|
||||
this.argumentIsGeometryTypeMask.set( staticFunction ? 0 : 1, firstArgumentIsGeometryType );
|
||||
this.staticFunction = staticFunction;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public String render(Type firstArgumentType, List arguments, SessionFactoryImplementor sessionFactory) {
|
||||
if ( arguments.size() == 0 ) {
|
||||
return getName() + "()";
|
||||
|
|
|
@ -7,36 +7,9 @@
|
|||
|
||||
package org.hibernate.spatial.dialect.mariadb;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.MariaDB103Dialect;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.dialect.SpatialFunctionsRegistry;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
|
||||
public class MariaDB103SpatialDialect extends MariaDB103Dialect implements MariaDBSpatialDialectTrait {
|
||||
public class MariaDB103SpatialDialect extends MariaDB103Dialect implements SpatialDialect {
|
||||
|
||||
final private SpatialFunctionsRegistry spatialFunctions = new MariaDB103SpatialFunctions();
|
||||
|
||||
public MariaDB103SpatialDialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
MariaDBGeometryTypeDescriptor.INSTANCE.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, SQLFunction> entry : spatialFunctions ) {
|
||||
registerFunction( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
delegateContributeTypes( typeContributions, serviceRegistry );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpatialFunctionsRegistry spatialFunctions() {
|
||||
return spatialFunctions;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@ import org.hibernate.type.descriptor.ValueBinder;
|
|||
import org.hibernate.type.descriptor.ValueExtractor;
|
||||
import org.hibernate.type.descriptor.WrapperOptions;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.sql.BasicBinder;
|
||||
import org.hibernate.type.descriptor.sql.BasicExtractor;
|
||||
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.BasicBinder;
|
||||
import org.hibernate.type.descriptor.jdbc.BasicExtractor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
|
||||
import org.geolatte.geom.ByteBuffer;
|
||||
import org.geolatte.geom.ByteOrder;
|
||||
|
@ -28,14 +28,14 @@ import org.geolatte.geom.codec.Wkb;
|
|||
import org.geolatte.geom.codec.WkbDecoder;
|
||||
import org.geolatte.geom.codec.WkbEncoder;
|
||||
|
||||
public class MariaDBGeometryTypeDescriptor implements SqlTypeDescriptor {
|
||||
public class MariaDBGeometryTypeDescriptor implements JdbcTypeDescriptor {
|
||||
|
||||
public static final MariaDBGeometryTypeDescriptor INSTANCE = new MariaDBGeometryTypeDescriptor();
|
||||
final WkbEncoder encoder = Wkb.newEncoder( Wkb.Dialect.MYSQL_WKB );
|
||||
final WkbDecoder decoder = Wkb.newDecoder( Wkb.Dialect.MYSQL_WKB );
|
||||
|
||||
@Override
|
||||
public int getSqlType() {
|
||||
public int getJdbcType() {
|
||||
return Types.ARRAY;
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ public class MariaDBGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
}
|
||||
|
||||
private byte[] valueToByteArray(X value, WrapperOptions options) {
|
||||
final Geometry<?> geometry = getJavaDescriptor().unwrap( value, Geometry.class, options );
|
||||
final Geometry<?> geometry = getJavaTypeDescriptor().unwrap( value, Geometry.class, options );
|
||||
final ByteBuffer buffer = encoder.encode( geometry, ByteOrder.NDR );
|
||||
return buffer == null ? null : buffer.toByteArray();
|
||||
}
|
||||
|
@ -74,20 +74,21 @@ public class MariaDBGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
public <X> ValueExtractor<X> getExtractor(JavaTypeDescriptor<X> javaTypeDescriptor) {
|
||||
return new BasicExtractor<X>( javaTypeDescriptor, this ) {
|
||||
|
||||
|
||||
@Override
|
||||
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
|
||||
return getJavaDescriptor().wrap( toGeometry( rs.getBytes( name ) ), options );
|
||||
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
|
||||
return getJavaTypeDescriptor().wrap( toGeometry( rs.getBytes( paramIndex ) ), options );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
|
||||
return getJavaDescriptor().wrap( toGeometry( statement.getBytes( index ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( toGeometry( statement.getBytes( index ) ), options );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
|
||||
throws SQLException {
|
||||
return getJavaDescriptor().wrap( toGeometry( statement.getBytes( name ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( toGeometry( statement.getBytes( name ) ), options );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public interface MariaDBSpatialDialectTrait extends SpatialDialect {
|
|||
|
||||
SpatialFunctionsRegistry spatialFunctions();
|
||||
|
||||
@Override
|
||||
|
||||
default String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
switch ( spatialRelation ) {
|
||||
case SpatialRelation.WITHIN:
|
||||
|
@ -61,39 +61,37 @@ public interface MariaDBSpatialDialectTrait extends SpatialDialect {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
default String getSpatialFilterExpression(String columnName) {
|
||||
return String.format( Locale.ENGLISH, "MBRIntersects(%s,?)", columnName
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
default String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
throw new UnsupportedOperationException( "MariaDB has no spatial aggregate functions." );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
default String getDWithinSQL(String columnName) {
|
||||
throw new UnsupportedOperationException( "MariaDB doesn't support the DWithin function." );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
default String getHavingSridSQL(String columnName) {
|
||||
return " (ST_SRID(" + columnName + ") = ?) ";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
default String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
final String emptyExpr = " ST_IsEmpty(" + columnName + ") ";
|
||||
return isEmpty ? emptyExpr : "( NOT " + emptyExpr + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean supportsFiltering() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean supports(SpatialFunction function) {
|
||||
return spatialFunctions().get( function.toString() ) != null;
|
||||
}
|
||||
|
|
|
@ -11,19 +11,8 @@ package org.hibernate.spatial.dialect.mysql;
|
|||
* creation-date: 10/9/13
|
||||
*/
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.MySQL55Dialect;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.SpatialRelation;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor;
|
||||
|
||||
/**
|
||||
* Extends the MySQL5Dialect by including support for the spatial operators.
|
||||
|
@ -36,117 +25,4 @@ import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor;
|
|||
*/
|
||||
public class MySQL56SpatialDialect extends MySQL55Dialect implements SpatialDialect {
|
||||
|
||||
|
||||
private MySQLSpatialDialect dialectDelegate = new MySQLSpatialDialect();
|
||||
|
||||
/**
|
||||
* Constructs the dialect
|
||||
*/
|
||||
public MySQL56SpatialDialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
MySQLGeometryTypeDescriptor.INSTANCE.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
final MySQL5SpatialFunctions functionsToRegister = overrideObjectShapeFunctions( new MySQL5SpatialFunctions() );
|
||||
for ( Map.Entry<String, SQLFunction> entry : functionsToRegister ) {
|
||||
registerFunction( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
private MySQL5SpatialFunctions overrideObjectShapeFunctions(MySQL5SpatialFunctions mysqlFunctions) {
|
||||
mysqlFunctions.put( "contains", new StandardSQLFunction( "ST_Contains", StandardBasicTypes.BOOLEAN ) );
|
||||
mysqlFunctions.put( "crosses", new StandardSQLFunction( "ST_Crosses", StandardBasicTypes.BOOLEAN ) );
|
||||
mysqlFunctions.put( "disjoint", new StandardSQLFunction( "ST_Disjoint", StandardBasicTypes.BOOLEAN ) );
|
||||
mysqlFunctions.put( "equals", new StandardSQLFunction( "ST_Equals", StandardBasicTypes.BOOLEAN ) );
|
||||
mysqlFunctions.put( "intersects", new StandardSQLFunction( "ST_Intersects", StandardBasicTypes.BOOLEAN ) );
|
||||
mysqlFunctions.put( "overlaps", new StandardSQLFunction( "ST_Overlaps", StandardBasicTypes.BOOLEAN ) );
|
||||
mysqlFunctions.put( "touches", new StandardSQLFunction( "ST_Touches", StandardBasicTypes.BOOLEAN ) );
|
||||
mysqlFunctions.put( "within", new StandardSQLFunction( "ST_Within", StandardBasicTypes.BOOLEAN ) );
|
||||
return mysqlFunctions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
|
||||
return dialectDelegate.remapSqlTypeDescriptor( sqlTypeDescriptor );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName(int code, long length, int precision, int scale) throws HibernateException {
|
||||
return dialectDelegate.getTypeName( code, length, precision, scale );
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the Dialect to contribute additional types
|
||||
*
|
||||
* @param typeContributions Callback to contribute the types
|
||||
* @param serviceRegistry The service registry
|
||||
*/
|
||||
@Override
|
||||
public void contributeTypes(
|
||||
TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
super.contributeTypes( typeContributions, serviceRegistry );
|
||||
dialectDelegate.contributeTypes( typeContributions, serviceRegistry );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
switch ( spatialRelation ) {
|
||||
case SpatialRelation.WITHIN:
|
||||
return " ST_Within(" + columnName + ",?)";
|
||||
case SpatialRelation.CONTAINS:
|
||||
return " ST_Contains(" + columnName + ", ?)";
|
||||
case SpatialRelation.CROSSES:
|
||||
return " ST_Crosses(" + columnName + ", ?)";
|
||||
case SpatialRelation.OVERLAPS:
|
||||
return " ST_Overlaps(" + columnName + ", ?)";
|
||||
case SpatialRelation.DISJOINT:
|
||||
return " ST_Disjoint(" + columnName + ", ?)";
|
||||
case SpatialRelation.INTERSECTS:
|
||||
return " ST_Intersects(" + columnName + ", ?)";
|
||||
case SpatialRelation.TOUCHES:
|
||||
return " ST_Touches(" + columnName + ", ?)";
|
||||
case SpatialRelation.EQUALS:
|
||||
return " ST_Equals(" + columnName + ", ?)";
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
"Spatial relation is not known by this dialect"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialFilterExpression(String columnName) {
|
||||
return dialectDelegate.getSpatialFilterExpression( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
return dialectDelegate.getSpatialAggregateSQL( columnName, aggregation );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDWithinSQL(String columnName) {
|
||||
return dialectDelegate.getDWithinSQL( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHavingSridSQL(String columnName) {
|
||||
return dialectDelegate.getHavingSridSQL( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
return dialectDelegate.getIsEmptySQL( columnName, isEmpty );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsFiltering() {
|
||||
return dialectDelegate.supportsFiltering();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return dialectDelegate.supports( function );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,4 @@ import org.hibernate.dialect.MySQLStorageEngine;
|
|||
*/
|
||||
@Deprecated
|
||||
public class MySQL5InnoDBSpatialDialect extends MySQL5SpatialDialect {
|
||||
|
||||
@Override
|
||||
protected MySQLStorageEngine getDefaultMySQLStorageEngine() {
|
||||
return InnoDBStorageEngine.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,18 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.spatial.dialect.mysql;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.InnoDBStorageEngine;
|
||||
import org.hibernate.dialect.MySQL5Dialect;
|
||||
import org.hibernate.dialect.MySQLStorageEngine;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor;
|
||||
|
||||
/**
|
||||
* A Dialect for MySQL 5 using InnoDB engine, with support for its spatial features
|
||||
|
@ -25,80 +15,4 @@ import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor;
|
|||
* @author Karel Maesen, Geovise BVBA
|
||||
*/
|
||||
public class MySQL5SpatialDialect extends MySQL5Dialect implements SpatialDialect {
|
||||
|
||||
private MySQLSpatialDialect dialectDelegate = new MySQLSpatialDialect();
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
*/
|
||||
public MySQL5SpatialDialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
MySQLGeometryTypeDescriptor.INSTANCE.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, SQLFunction> entry : new MySQL5SpatialFunctions() ) {
|
||||
registerFunction( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
dialectDelegate.contributeTypes( typeContributions, serviceRegistry );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName(int code, long length, int precision, int scale) throws HibernateException {
|
||||
return dialectDelegate.getTypeName( code, length, precision, scale );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
|
||||
return dialectDelegate.remapSqlTypeDescriptor( sqlTypeDescriptor );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
return dialectDelegate.getSpatialRelateSQL( columnName, spatialRelation );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialFilterExpression(String columnName) {
|
||||
return dialectDelegate.getSpatialFilterExpression( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
return dialectDelegate.getSpatialAggregateSQL( columnName, aggregation );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDWithinSQL(String columnName) {
|
||||
return dialectDelegate.getDWithinSQL( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHavingSridSQL(String columnName) {
|
||||
return dialectDelegate.getHavingSridSQL( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
return dialectDelegate.getIsEmptySQL( columnName, isEmpty );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsFiltering() {
|
||||
return dialectDelegate.supportsFiltering();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return dialectDelegate.supports( function );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MySQLStorageEngine getDefaultMySQLStorageEngine() {
|
||||
return InnoDBStorageEngine.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,119 +6,11 @@
|
|||
*/
|
||||
package org.hibernate.spatial.dialect.mysql;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.MySQL8Dialect;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.GeolatteGeometryJavaTypeDescriptor;
|
||||
import org.hibernate.spatial.GeolatteGeometryType;
|
||||
import org.hibernate.spatial.JTSGeometryJavaTypeDescriptor;
|
||||
import org.hibernate.spatial.JTSGeometryType;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.SpatialRelation;
|
||||
import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor;
|
||||
|
||||
/**
|
||||
* Created by Karel Maesen, Geovise BVBA on 2019-03-07.
|
||||
*/
|
||||
public class MySQL8SpatialDialect extends MySQL8Dialect implements SpatialDialect {
|
||||
|
||||
private MySQLSpatialDialect dialectDelegate = new MySQLSpatialDialect();
|
||||
private MySQL8SpatialFunctions spatialFunctions = new MySQL8SpatialFunctions();
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
*/
|
||||
public MySQL8SpatialDialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
MySQLGeometryTypeDescriptor.INSTANCE.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, SQLFunction> entry : spatialFunctions ) {
|
||||
registerFunction( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
dialectDelegate.contributeTypes( typeContributions, serviceRegistry );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
switch ( spatialRelation ) {
|
||||
case SpatialRelation.WITHIN:
|
||||
return " ST_within(" + columnName + ",?)";
|
||||
case SpatialRelation.CONTAINS:
|
||||
return " ST_contains(" + columnName + ", ?)";
|
||||
case SpatialRelation.CROSSES:
|
||||
return " ST_crosses(" + columnName + ", ?)";
|
||||
case SpatialRelation.OVERLAPS:
|
||||
return " ST_overlaps(" + columnName + ", ?)";
|
||||
case SpatialRelation.DISJOINT:
|
||||
return " ST_disjoint(" + columnName + ", ?)";
|
||||
case SpatialRelation.INTERSECTS:
|
||||
return " ST_intersects(" + columnName
|
||||
+ ", ?)";
|
||||
case SpatialRelation.TOUCHES:
|
||||
return " ST_touches(" + columnName + ", ?)";
|
||||
case SpatialRelation.EQUALS:
|
||||
return " ST_equals(" + columnName + ", ?)";
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
"Spatial relation is not known by this dialect"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName(int code, long length, int precision, int scale) throws HibernateException {
|
||||
return dialectDelegate.getTypeName( code, length, precision, scale );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
|
||||
return dialectDelegate.remapSqlTypeDescriptor( sqlTypeDescriptor );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialFilterExpression(String columnName) {
|
||||
return dialectDelegate.getSpatialFilterExpression( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
return dialectDelegate.getSpatialAggregateSQL( columnName, aggregation );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDWithinSQL(String columnName) {
|
||||
return dialectDelegate.getDWithinSQL( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHavingSridSQL(String columnName) {
|
||||
return " (ST_SRID(" + columnName + ") = ?) ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
final String emptyExpr = " ST_IsEmpty(" + columnName + ") ";
|
||||
return isEmpty ? emptyExpr : "( NOT " + emptyExpr + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsFiltering() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return spatialFunctions.get( function.toString() ) != null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import org.hibernate.type.descriptor.WrapperOptions;
|
|||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.BasicBinder;
|
||||
import org.hibernate.type.descriptor.jdbc.BasicExtractor;
|
||||
import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
|
||||
import org.geolatte.geom.ByteBuffer;
|
||||
import org.geolatte.geom.ByteOrder;
|
||||
|
@ -33,7 +33,7 @@ import org.geolatte.geom.codec.WkbEncoder;
|
|||
*
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
*/
|
||||
public class MySQLGeometryTypeDescriptor implements SqlTypeDescriptor {
|
||||
public class MySQLGeometryTypeDescriptor implements JdbcTypeDescriptor {
|
||||
|
||||
/**
|
||||
* An instance of this Descriptor
|
||||
|
@ -41,7 +41,7 @@ public class MySQLGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
public static final MySQLGeometryTypeDescriptor INSTANCE = new MySQLGeometryTypeDescriptor();
|
||||
|
||||
@Override
|
||||
public int getSqlType() {
|
||||
public int getJdbcType() {
|
||||
return Types.ARRAY;
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class MySQLGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
|
||||
throws SQLException {
|
||||
final WkbEncoder encoder = Wkb.newEncoder( Wkb.Dialect.MYSQL_WKB );
|
||||
final Geometry geometry = getJavaDescriptor().unwrap( value, Geometry.class, options );
|
||||
final Geometry geometry = getJavaTypeDescriptor().unwrap( value, Geometry.class, options );
|
||||
final ByteBuffer buffer = encoder.encode( geometry, ByteOrder.NDR );
|
||||
final byte[] bytes = ( buffer == null ? null : buffer.toByteArray() );
|
||||
st.setBytes( index, bytes );
|
||||
|
@ -67,7 +67,7 @@ public class MySQLGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
|
||||
throws SQLException {
|
||||
final WkbEncoder encoder = Wkb.newEncoder( Wkb.Dialect.MYSQL_WKB );
|
||||
final Geometry geometry = getJavaDescriptor().unwrap( value, Geometry.class, options );
|
||||
final Geometry geometry = getJavaTypeDescriptor().unwrap( value, Geometry.class, options );
|
||||
final ByteBuffer buffer = encoder.encode( geometry, ByteOrder.NDR );
|
||||
final byte[] bytes = ( buffer == null ? null : buffer.toByteArray() );
|
||||
st.setBytes( name, bytes );
|
||||
|
@ -81,18 +81,18 @@ public class MySQLGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
|
||||
@Override
|
||||
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
|
||||
return getJavaDescriptor().wrap( toGeometry( rs.getBytes( paramIndex ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( toGeometry( rs.getBytes( paramIndex ) ), options );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
|
||||
return getJavaDescriptor().wrap( toGeometry( statement.getBytes( index ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( toGeometry( statement.getBytes( index ) ), options );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
|
||||
throws SQLException {
|
||||
return getJavaDescriptor().wrap( toGeometry( statement.getBytes( name ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( toGeometry( statement.getBytes( name ) ), options );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -6,20 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.spatial.dialect.mysql;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.MySQLDialect;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.GeolatteGeometryJavaTypeDescriptor;
|
||||
import org.hibernate.spatial.GeolatteGeometryType;
|
||||
import org.hibernate.spatial.JTSGeometryJavaTypeDescriptor;
|
||||
import org.hibernate.spatial.JTSGeometryType;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.SpatialRelation;
|
||||
|
||||
/**
|
||||
* A Dialect for MySQL with support for its spatial features
|
||||
|
@ -28,113 +16,4 @@ import org.hibernate.spatial.SpatialRelation;
|
|||
*/
|
||||
public class MySQLSpatialDialect extends MySQLDialect implements SpatialDialect {
|
||||
|
||||
/**
|
||||
* Constructs an instance
|
||||
*/
|
||||
public MySQLSpatialDialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
MySQLGeometryTypeDescriptor.INSTANCE.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, SQLFunction> entry : new MySQL5SpatialFunctions() ) {
|
||||
registerFunction( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
super.contributeTypes(
|
||||
typeContributions,
|
||||
serviceRegistry
|
||||
);
|
||||
typeContributions.contributeType( new GeolatteGeometryType( MySQLGeometryTypeDescriptor.INSTANCE ) );
|
||||
typeContributions.contributeType( new JTSGeometryType( MySQLGeometryTypeDescriptor.INSTANCE ) );
|
||||
|
||||
typeContributions.contributeJavaTypeDescriptor( GeolatteGeometryJavaTypeDescriptor.INSTANCE );
|
||||
typeContributions.contributeJavaTypeDescriptor( JTSGeometryJavaTypeDescriptor.INSTANCE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
switch ( spatialRelation ) {
|
||||
case SpatialRelation.WITHIN:
|
||||
return " within(" + columnName + ",?)";
|
||||
case SpatialRelation.CONTAINS:
|
||||
return " contains(" + columnName + ", ?)";
|
||||
case SpatialRelation.CROSSES:
|
||||
return " crosses(" + columnName + ", ?)";
|
||||
case SpatialRelation.OVERLAPS:
|
||||
return " overlaps(" + columnName + ", ?)";
|
||||
case SpatialRelation.DISJOINT:
|
||||
return " disjoint(" + columnName + ", ?)";
|
||||
case SpatialRelation.INTERSECTS:
|
||||
return " intersects(" + columnName + ", ?)";
|
||||
case SpatialRelation.TOUCHES:
|
||||
return " touches(" + columnName + ", ?)";
|
||||
case SpatialRelation.EQUALS:
|
||||
return " equals(" + columnName + ", ?)";
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
"Spatial relation is not known by this dialect"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialFilterExpression(String columnName) {
|
||||
return "MBRIntersects(" + columnName + ", ? ) ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
throw new UnsupportedOperationException( "Mysql has no spatial aggregate SQL functions." );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDWithinSQL(String columnName) {
|
||||
throw new UnsupportedOperationException( String.format(
|
||||
Locale.ENGLISH,
|
||||
"Mysql doesn't support the Dwithin function"
|
||||
) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHavingSridSQL(String columnName) {
|
||||
return " (srid(" + columnName + ") = ?) ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
final String emptyExpr = " IsEmpty(" + columnName + ") ";
|
||||
return isEmpty ? emptyExpr : "( NOT " + emptyExpr + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsFiltering() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
switch ( function ) {
|
||||
case boundary:
|
||||
case relate:
|
||||
case distance:
|
||||
case buffer:
|
||||
case convexhull:
|
||||
case difference:
|
||||
case symdifference:
|
||||
case intersection:
|
||||
case geomunion:
|
||||
case dwithin:
|
||||
case transform:
|
||||
case extent:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ class OracleSDOSupport implements SpatialDialect, Serializable, WithCustomJPAFil
|
|||
*
|
||||
* @return SQL fragment {@code SpatialRelateExpression}
|
||||
*/
|
||||
@Override
|
||||
|
||||
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
String sql = getOGCSpatialRelateSQL( columnName, "?", spatialRelation ) + " = 1";
|
||||
sql += " and " + columnName + " is not null";
|
||||
|
@ -226,7 +226,7 @@ class OracleSDOSupport implements SpatialDialect, Serializable, WithCustomJPAFil
|
|||
*
|
||||
* @return Rhe SQL fragment for the {@code SpatialFilterExpression}
|
||||
*/
|
||||
@Override
|
||||
|
||||
public String getSpatialFilterExpression(String columnName) {
|
||||
final StringBuilder buffer = new StringBuilder( "SDO_FILTER(" );
|
||||
buffer.append( columnName );
|
||||
|
@ -242,10 +242,10 @@ class OracleSDOSupport implements SpatialDialect, Serializable, WithCustomJPAFil
|
|||
*
|
||||
* @return The SQL fragment for the projection
|
||||
*/
|
||||
@Override
|
||||
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
final StringBuilder aggregateFunction = new StringBuilder();
|
||||
final SpatialAggregate sa = new SpatialAggregate( aggregation );
|
||||
final SpatialAggregateImpl sa = new SpatialAggregateImpl( aggregation );
|
||||
|
||||
if ( sa.getAggregateSyntax() == null ) {
|
||||
throw new IllegalArgumentException(
|
||||
|
@ -277,7 +277,6 @@ class OracleSDOSupport implements SpatialDialect, Serializable, WithCustomJPAFil
|
|||
*
|
||||
* @return The SQL fragment when parsing a <code>DWithinExpression</code>.
|
||||
*/
|
||||
@Override
|
||||
public String getDWithinSQL(String columnName) {
|
||||
return "SDO_WITHIN_DISTANCE (" + columnName + ",?, ?) = 'TRUE' ";
|
||||
}
|
||||
|
@ -289,7 +288,7 @@ class OracleSDOSupport implements SpatialDialect, Serializable, WithCustomJPAFil
|
|||
*
|
||||
* @return The SQL fragment for a <code>HavingSridExpression</code>.
|
||||
*/
|
||||
@Override
|
||||
|
||||
public String getHavingSridSQL(String columnName) {
|
||||
return String.format( Locale.ENGLISH, " (MDSYS.ST_GEOMETRY(%s).ST_SRID() = ?)", columnName );
|
||||
}
|
||||
|
@ -303,7 +302,6 @@ class OracleSDOSupport implements SpatialDialect, Serializable, WithCustomJPAFil
|
|||
*
|
||||
* @return The SQL fragment for the isempty function
|
||||
*/
|
||||
@Override
|
||||
public String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
return String.format(
|
||||
Locale.ENGLISH,
|
||||
|
@ -319,7 +317,6 @@ class OracleSDOSupport implements SpatialDialect, Serializable, WithCustomJPAFil
|
|||
*
|
||||
* @return True if filtering is supported
|
||||
*/
|
||||
@Override
|
||||
public boolean supportsFiltering() {
|
||||
return true;
|
||||
}
|
||||
|
@ -331,7 +328,6 @@ class OracleSDOSupport implements SpatialDialect, Serializable, WithCustomJPAFil
|
|||
*
|
||||
* @return True if this <code>SpatialDialect</code> supports the spatial function specified by the function parameter.
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -7,103 +7,14 @@
|
|||
package org.hibernate.spatial.dialect.oracle;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Types;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.Oracle10gDialect;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.HSMessageLogger;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.dialect.WithCustomJPAFilter;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Spatial Dialect for Oracle10g databases.
|
||||
*
|
||||
* @author Karel Maesen
|
||||
*/
|
||||
public class OracleSpatial10gDialect extends Oracle10gDialect implements SpatialDialect, WithCustomJPAFilter, Serializable {
|
||||
public class OracleSpatial10gDialect extends Oracle10gDialect implements SpatialDialect {
|
||||
|
||||
private static final HSMessageLogger log = Logger.getMessageLogger(
|
||||
HSMessageLogger.class,
|
||||
OracleSpatial10gDialect.class.getName()
|
||||
);
|
||||
|
||||
|
||||
transient private OracleSDOSupport sdoSupport = new OracleSDOSupport( true );
|
||||
|
||||
/**
|
||||
* Constructs the dialect with
|
||||
*/
|
||||
public OracleSpatial10gDialect() {
|
||||
super();
|
||||
|
||||
// register geometry type
|
||||
registerColumnType( Types.STRUCT, "MDSYS.SDO_GEOMETRY" );
|
||||
for ( Map.Entry<String, SQLFunction> entry : sdoSupport.functionsToRegister() ) {
|
||||
registerFunction( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
super.contributeTypes(
|
||||
typeContributions,
|
||||
serviceRegistry
|
||||
);
|
||||
sdoSupport.contributeTypes( typeContributions, serviceRegistry );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getSpatialFilterExpression(String columnName) {
|
||||
return sdoSupport.getSpatialFilterExpression( columnName );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
return sdoSupport.getSpatialRelateSQL( columnName, spatialRelation );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
return sdoSupport.getSpatialAggregateSQL( columnName, aggregation );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDWithinSQL(String columnName) {
|
||||
return sdoSupport.getDWithinSQL( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHavingSridSQL(String columnName) {
|
||||
return sdoSupport.getHavingSridSQL( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
return sdoSupport.getIsEmptySQL( columnName, isEmpty );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsFiltering() {
|
||||
return sdoSupport.supportsFiltering();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return ( getFunctions().get( function.toString() ) != null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String filterExpression(String geometryParam, String filterParam) {
|
||||
return sdoSupport.filterExpression( geometryParam, filterParam );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,17 +4,15 @@
|
|||
* 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.oracle.criterion;
|
||||
|
||||
|
||||
import org.hibernate.spatial.SpatialAggregate;
|
||||
package org.hibernate.spatial.dialect.oracle;
|
||||
|
||||
/**
|
||||
* Defines types of Oracle Spatial aggregate functions
|
||||
*
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
*/
|
||||
public interface OracleSpatialAggregate extends SpatialAggregate {
|
||||
public interface OracleSpatialAggregate extends org.hibernate.spatial.SpatialAggregate {
|
||||
|
||||
/**
|
||||
* LRS_CONCAT aggregate function
|
|
@ -11,11 +11,11 @@ import java.util.List;
|
|||
import org.hibernate.QueryException;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType;
|
||||
import org.hibernate.spatial.SpatialAnalysis;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.SpatialRelation;
|
||||
import org.hibernate.spatial.dialect.SpatialFunctionsRegistry;
|
||||
import org.hibernate.spatial.dialect.oracle.criterion.OracleSpatialAggregate;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
|
@ -317,7 +317,7 @@ class OracleSpatialFunctions extends SpatialFunctionsRegistry {
|
|||
private final int analysis;
|
||||
private final boolean isOGCStrict;
|
||||
|
||||
private SpatialAnalysisFunction(String name, Type returnType, int analysis, boolean isOGCStrict) {
|
||||
private SpatialAnalysisFunction(String name, AllowableFunctionReturnType returnType, int analysis, boolean isOGCStrict) {
|
||||
super( name, returnType );
|
||||
this.analysis = analysis;
|
||||
this.isOGCStrict = isOGCStrict;
|
||||
|
|
|
@ -6,20 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.spatial.dialect.oracle;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Types;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.Oracle10gDialect;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.HSMessageLogger;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.dialect.WithCustomJPAFilter;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* A Spatial Dialect for Oracle 10g/11g that uses the "native" SDO spatial operators.
|
||||
|
@ -27,83 +15,5 @@ import org.jboss.logging.Logger;
|
|||
* Created by Karel Maesen, Geovise BVBA on 11/02/17.
|
||||
*/
|
||||
public class OracleSpatialSDO10gDialect extends Oracle10gDialect
|
||||
implements SpatialDialect, WithCustomJPAFilter, Serializable {
|
||||
|
||||
private static final HSMessageLogger log = Logger.getMessageLogger(
|
||||
HSMessageLogger.class,
|
||||
OracleSpatial10gDialect.class.getName()
|
||||
);
|
||||
|
||||
|
||||
transient private OracleSDOSupport sdoSupport = new OracleSDOSupport( false );
|
||||
|
||||
/**
|
||||
* Constructs the dialect
|
||||
*/
|
||||
public OracleSpatialSDO10gDialect() {
|
||||
super();
|
||||
|
||||
// register geometry type
|
||||
registerColumnType( Types.STRUCT, "MDSYS.SDO_GEOMETRY" );
|
||||
for ( Map.Entry<String, SQLFunction> entry : sdoSupport.functionsToRegister() ) {
|
||||
registerFunction( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
super.contributeTypes(
|
||||
typeContributions,
|
||||
serviceRegistry
|
||||
);
|
||||
sdoSupport.contributeTypes( typeContributions, serviceRegistry );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getSpatialFilterExpression(String columnName) {
|
||||
return sdoSupport.getSpatialFilterExpression( columnName );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
return sdoSupport.getSDOSpatialRelateSQL( columnName, spatialRelation );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
return sdoSupport.getSpatialAggregateSQL( columnName, aggregation );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDWithinSQL(String columnName) {
|
||||
return sdoSupport.getDWithinSQL( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHavingSridSQL(String columnName) {
|
||||
return sdoSupport.getHavingSridSQL( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
return sdoSupport.getIsEmptySQL( columnName, isEmpty );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsFiltering() {
|
||||
return sdoSupport.supportsFiltering();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return !function.equals( SpatialFunction.crosses ) && ( getFunctions().get( function.toString() ) != null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String filterExpression(String geometryParam, String filterParam) {
|
||||
return sdoSupport.filterExpression( geometryParam, filterParam );
|
||||
}
|
||||
implements SpatialDialect {
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.sql.Types;
|
|||
import org.hibernate.type.descriptor.ValueBinder;
|
||||
import org.hibernate.type.descriptor.ValueExtractor;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
|
||||
import org.geolatte.geom.codec.db.oracle.OracleJDBCTypeFactory;
|
||||
|
||||
|
@ -21,7 +21,7 @@ import org.geolatte.geom.codec.db.oracle.OracleJDBCTypeFactory;
|
|||
*
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
*/
|
||||
public class SDOGeometryTypeDescriptor implements SqlTypeDescriptor {
|
||||
public class SDOGeometryTypeDescriptor implements JdbcTypeDescriptor {
|
||||
|
||||
private final OracleJDBCTypeFactory typeFactory;
|
||||
|
||||
|
@ -35,7 +35,7 @@ public class SDOGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getSqlType() {
|
||||
public int getJdbcType() {
|
||||
return Types.STRUCT;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import org.hibernate.HibernateException;
|
|||
import org.hibernate.type.descriptor.ValueBinder;
|
||||
import org.hibernate.type.descriptor.WrapperOptions;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
|
||||
import org.geolatte.geom.Geometry;
|
||||
import org.geolatte.geom.codec.db.oracle.Encoders;
|
||||
|
@ -37,7 +37,7 @@ class SDOGeometryValueBinder<J> implements ValueBinder<J> {
|
|||
|
||||
public SDOGeometryValueBinder(
|
||||
JavaTypeDescriptor<J> javaTypeDescriptor,
|
||||
SqlTypeDescriptor sqlTypeDescriptor,
|
||||
JdbcTypeDescriptor sqlTypeDescriptor,
|
||||
OracleJDBCTypeFactory typeFactory) {
|
||||
this.javaTypeDescriptor = javaTypeDescriptor;
|
||||
this.typeFactory = typeFactory;
|
||||
|
|
|
@ -15,7 +15,7 @@ import java.sql.Struct;
|
|||
import org.hibernate.type.descriptor.WrapperOptions;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.BasicExtractor;
|
||||
import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
|
||||
import org.geolatte.geom.Geometry;
|
||||
import org.geolatte.geom.codec.db.oracle.Decoders;
|
||||
|
@ -38,26 +38,26 @@ public class SDOGeometryValueExtractor<X> extends BasicExtractor<X> {
|
|||
* @param javaDescriptor the {@code JavaTypeDescriptor} to use
|
||||
* @param sqlTypeDescriptor the {@code SqlTypeDescriptor} to use
|
||||
*/
|
||||
public SDOGeometryValueExtractor(JavaTypeDescriptor<X> javaDescriptor, SqlTypeDescriptor sqlTypeDescriptor) {
|
||||
public SDOGeometryValueExtractor(JavaTypeDescriptor<X> javaDescriptor, JdbcTypeDescriptor sqlTypeDescriptor) {
|
||||
super( javaDescriptor, sqlTypeDescriptor );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
|
||||
final Object geomObj = rs.getObject( paramIndex );
|
||||
return getJavaDescriptor().wrap( convert( geomObj ), options );
|
||||
return getJavaTypeDescriptor().wrap( convert( geomObj ), options );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
|
||||
final Object geomObj = statement.getObject( index );
|
||||
return getJavaDescriptor().wrap( convert( geomObj ), options );
|
||||
return getJavaTypeDescriptor().wrap( convert( geomObj ), options );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
|
||||
final Object geomObj = statement.getObject( name );
|
||||
return getJavaDescriptor().wrap( convert( geomObj ), options );
|
||||
return getJavaTypeDescriptor().wrap( convert( geomObj ), options );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,7 +9,7 @@ package org.hibernate.spatial.dialect.oracle;
|
|||
import java.util.List;
|
||||
|
||||
import org.hibernate.QueryException;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.engine.spi.Mapping;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.type.Type;
|
||||
|
@ -19,13 +19,14 @@ import org.hibernate.type.Type;
|
|||
*
|
||||
* @author Karel Maesen
|
||||
*/
|
||||
class SDOObjectMethod implements SQLFunction {
|
||||
class SDOObjectMethod extends StandardSQLFunction {
|
||||
|
||||
private final Type type;
|
||||
|
||||
private final String name;
|
||||
|
||||
public SDOObjectMethod(String name, Type type) {
|
||||
super(name);
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
}
|
||||
|
|
|
@ -8,18 +8,26 @@ package org.hibernate.spatial.dialect.oracle;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.NotYetImplementedFor6Exception;
|
||||
import org.hibernate.QueryException;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.cfg.NotYetImplementedException;
|
||||
import org.hibernate.engine.spi.Mapping;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType;
|
||||
import org.hibernate.query.spi.QueryEngine;
|
||||
import org.hibernate.query.sqm.function.SelfRenderingSqmFunction;
|
||||
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
|
||||
import org.hibernate.query.sqm.tree.SqmTypedNode;
|
||||
import org.hibernate.query.sqm.tree.predicate.SqmPredicate;
|
||||
import org.hibernate.type.Type;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
* Special function for accessing a member variable of an Oracle Object
|
||||
*
|
||||
* @author Karel Maesen
|
||||
*/
|
||||
class SDOObjectProperty implements SQLFunction {
|
||||
class SDOObjectProperty implements SqmFunctionDescriptor {
|
||||
|
||||
private final Type type;
|
||||
|
||||
|
@ -78,4 +86,60 @@ class SDOObjectProperty implements SQLFunction {
|
|||
return buf.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> SelfRenderingSqmFunction<T> generateSqmExpression(
|
||||
List<SqmTypedNode<?>> arguments,
|
||||
AllowableFunctionReturnType<T> impliedResultType,
|
||||
QueryEngine queryEngine,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
throw new NotYetImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> SelfRenderingSqmFunction<T> generateAggregateSqmExpression(
|
||||
List<SqmTypedNode<?>> arguments,
|
||||
SqmPredicate filter,
|
||||
AllowableFunctionReturnType<T> impliedResultType,
|
||||
QueryEngine queryEngine,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
return SqmFunctionDescriptor.super.generateAggregateSqmExpression(
|
||||
arguments,
|
||||
filter,
|
||||
impliedResultType,
|
||||
queryEngine,
|
||||
typeConfiguration
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> SelfRenderingSqmFunction<T> generateSqmExpression(
|
||||
SqmTypedNode<?> argument,
|
||||
AllowableFunctionReturnType<T> impliedResultType,
|
||||
QueryEngine queryEngine,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
return SqmFunctionDescriptor.super.generateSqmExpression(
|
||||
argument,
|
||||
impliedResultType,
|
||||
queryEngine,
|
||||
typeConfiguration
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> SelfRenderingSqmFunction<T> generateSqmExpression(
|
||||
AllowableFunctionReturnType<T> impliedResultType,
|
||||
QueryEngine queryEngine,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
return SqmFunctionDescriptor.super.generateSqmExpression( impliedResultType, queryEngine, typeConfiguration );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean alwaysIncludesParentheses() {
|
||||
return SqmFunctionDescriptor.super.alwaysIncludesParentheses();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSignature(String name) {
|
||||
return SqmFunctionDescriptor.super.getSignature( name );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,22 +7,19 @@
|
|||
|
||||
package org.hibernate.spatial.dialect.oracle;
|
||||
|
||||
|
||||
import org.hibernate.spatial.dialect.oracle.criterion.OracleSpatialAggregate;
|
||||
|
||||
/**
|
||||
* Provides Aggregate type spatial function interpretation
|
||||
*/
|
||||
class SpatialAggregate {
|
||||
class SpatialAggregateImpl {
|
||||
|
||||
private static final String SDO_AGGR = "SDO_AGGR_";
|
||||
private boolean aggregateType;
|
||||
private String aggregateSyntax;
|
||||
|
||||
SpatialAggregate() {
|
||||
SpatialAggregateImpl() {
|
||||
}
|
||||
|
||||
SpatialAggregate(int aggregation) {
|
||||
SpatialAggregateImpl(int aggregation) {
|
||||
|
||||
String specificAggrSyntax;
|
||||
|
|
@ -11,6 +11,7 @@ import java.util.List;
|
|||
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType;
|
||||
import org.hibernate.spatial.Spatial;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
|
@ -30,7 +31,7 @@ class WrappedOGCFunction extends StandardSQLFunction {
|
|||
* @param geomArrays indicates which argument places are occupied by
|
||||
* sdo_geometries
|
||||
*/
|
||||
WrappedOGCFunction(final String name, final Type type, final boolean[] geomArrays) {
|
||||
WrappedOGCFunction(final String name, final AllowableFunctionReturnType type, final boolean[] geomArrays) {
|
||||
super( name, type );
|
||||
if ( isSpatial( type ) ) {
|
||||
throw new IllegalArgumentException(
|
||||
|
@ -74,7 +75,7 @@ class WrappedOGCFunction extends StandardSQLFunction {
|
|||
.append( ".geom" ).toString() : buf.toString();
|
||||
}
|
||||
|
||||
private boolean isSpatial(Type type) {
|
||||
private boolean isSpatial(AllowableFunctionReturnType type) {
|
||||
return Spatial.class.isAssignableFrom( type.getClass() );
|
||||
}
|
||||
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.dialect.oracle.criterion;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.criterion.CriteriaQuery;
|
||||
import org.hibernate.criterion.SimpleProjection;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* Template class for Spatial Projections
|
||||
*
|
||||
* @author Tom Acree
|
||||
*/
|
||||
public class OracleSpatialProjection extends SimpleProjection {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final String propertyName;
|
||||
private final int aggregate;
|
||||
|
||||
/**
|
||||
* Constructs an instance for the specified aggregate function and property
|
||||
*
|
||||
* @param aggregate The aggregate function (a value of {@code OracleSpatialAggregate}
|
||||
* @param propertyName The name of the geometry property
|
||||
*/
|
||||
public OracleSpatialProjection(int aggregate, String propertyName) {
|
||||
this.propertyName = propertyName;
|
||||
this.aggregate = aggregate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
|
||||
final SessionFactoryImplementor factory = criteriaQuery.getFactory();
|
||||
final String[] columns = criteriaQuery.getColumnsUsingProjection(
|
||||
criteria,
|
||||
this.propertyName
|
||||
);
|
||||
final Dialect dialect = factory.getDialect();
|
||||
if ( dialect instanceof SpatialDialect ) {
|
||||
final SpatialDialect seDialect = (SpatialDialect) dialect;
|
||||
|
||||
return new StringBuilder(
|
||||
seDialect.getSpatialAggregateSQL(
|
||||
columns[0], this.aggregate
|
||||
)
|
||||
).append( " y" ).append( position )
|
||||
.append( "_" ).toString();
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException(
|
||||
"Dialect must be spatially enabled dialect"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery)
|
||||
throws HibernateException {
|
||||
return new Type[] { criteriaQuery.getType( criteria, this.propertyName ) };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return aggregate + "(" + propertyName + ")";
|
||||
}
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.dialect.oracle.criterion;
|
||||
|
||||
/**
|
||||
* Factory class for SpationProjection functions *
|
||||
*
|
||||
* @author Tom Acree
|
||||
*/
|
||||
public final class OracleSpatialProjections {
|
||||
|
||||
private OracleSpatialProjections() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a "CONCAT_LRS" projection to the named property.
|
||||
*
|
||||
* @param propertyName The name of the geometry property
|
||||
*
|
||||
* @return OracleSpatialProjection
|
||||
*
|
||||
* @see OracleSpatialProjection
|
||||
*/
|
||||
public static OracleSpatialProjection concatLrs(String propertyName) {
|
||||
return new OracleSpatialProjection(
|
||||
OracleSpatialAggregate.LRS_CONCAT,
|
||||
propertyName
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a "CENTROID" projection to the named property.
|
||||
*
|
||||
* @param propertyName The name of the geometry property
|
||||
*
|
||||
* @return OracleSpatialProjection
|
||||
*
|
||||
* @see OracleSpatialProjection
|
||||
*/
|
||||
public static OracleSpatialProjection centroid(String propertyName) {
|
||||
return new OracleSpatialProjection(
|
||||
OracleSpatialAggregate.CENTROID,
|
||||
propertyName
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a "CONCAT_LINES" projection to the named property.
|
||||
*
|
||||
* @param propertyName The name of the geometry property
|
||||
*
|
||||
* @return OracleSpatialProjection
|
||||
*
|
||||
* @see OracleSpatialProjection
|
||||
*/
|
||||
public static OracleSpatialProjection concatLines(String propertyName) {
|
||||
return new OracleSpatialProjection(
|
||||
OracleSpatialAggregate.CONCAT_LINES,
|
||||
propertyName
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the specified {@code OracleSpatialProjection} to the named property.
|
||||
*
|
||||
* @param projection The projection function
|
||||
* @param propertyName The name of the geometry property
|
||||
*
|
||||
* @return OracleSpatialProjection
|
||||
*
|
||||
* @see OracleSpatialProjection
|
||||
*/
|
||||
public static OracleSpatialProjection projection(int projection, String propertyName) {
|
||||
return new OracleSpatialProjection( projection, propertyName );
|
||||
}
|
||||
}
|
|
@ -1,259 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.dialect.oracle.criterion;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.criterion.CriteriaQuery;
|
||||
import org.hibernate.criterion.Criterion;
|
||||
import org.hibernate.engine.spi.TypedValue;
|
||||
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
|
||||
/**
|
||||
* A static factory class for spatial criteria using the Oracle Spatial native spatial operators
|
||||
* for the SDO_GEOMTRY type.
|
||||
*
|
||||
* @author Karel Maesen
|
||||
*/
|
||||
public class OracleSpatialRestrictions {
|
||||
|
||||
private OracleSpatialRestrictions() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the "SDO_FILTER" constraint to the specified property, using the specified parameters
|
||||
*
|
||||
* @param propertyName The name of the proerty
|
||||
* @param geom The search geometry to use in the constraint
|
||||
* @param param The function parameters for the SDO_FILTER
|
||||
*
|
||||
* @return The Criterion
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public static Criterion SDOFilter(String propertyName, Geometry geom, SDOParameterMap param) {
|
||||
return new OracleSpatialCriterion( propertyName, geom, param ) {
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final String[] columns = criteriaQuery.getColumnsUsingProjection( criteria, this.propertyName );
|
||||
final StringBuilder sql = new StringBuilder( "SDO_FILTER(" );
|
||||
sql.append( columns[0] ).append( "," ).append( "?" );
|
||||
if ( param != null && !param.isEmpty() ) {
|
||||
sql.append( "," ).append( param.toQuotedString() );
|
||||
}
|
||||
sql.append( ") = 'TRUE'" );
|
||||
return sql.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the "SDO_FILTER" constraint to the specified property, using the specified parameters
|
||||
*
|
||||
* @param propertyName The name of the proerty
|
||||
* @param geom The search geometry to use in the constraint
|
||||
* @param minResolution The min_resolution parameter
|
||||
* @param maxResolution The max_resolution parameter
|
||||
*
|
||||
* @return The Criterion
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public static Criterion SDOFilter(String propertyName, Geometry geom, Double minResolution, Double maxResolution) {
|
||||
if ( minResolution == null && maxResolution == null ) {
|
||||
return SDOFilter( propertyName, geom, null );
|
||||
}
|
||||
else {
|
||||
final SDOParameterMap param = new SDOParameterMap();
|
||||
param.setMinResolution( minResolution );
|
||||
param.setMaxResolution( maxResolution );
|
||||
return SDOFilter( propertyName, geom, param );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the "SDO_NN" constraint to the specified property, using the specified parameters
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param geom The search geometry to use in the constraint
|
||||
* @param distance The distance parameter
|
||||
* @param numResults The num_results parameter
|
||||
* @param unit The unit parameter
|
||||
*
|
||||
* @return The Criterion
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public static Criterion SDONN(
|
||||
String propertyName,
|
||||
Geometry geom,
|
||||
Double distance,
|
||||
Integer numResults,
|
||||
String unit) {
|
||||
if ( distance == null && numResults == null && unit == null ) {
|
||||
return SDONN( propertyName, geom, null );
|
||||
}
|
||||
else {
|
||||
final SDOParameterMap param = new SDOParameterMap();
|
||||
param.setDistance( distance );
|
||||
param.setSdoNumRes( numResults );
|
||||
param.setUnit( unit );
|
||||
return SDONN( propertyName, geom, param );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the "SDO_NN" constraint to the specified property, using the specified {@code SDOParameterMap}
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param geom The search geometry to use in the constraint
|
||||
* @param param The parameters for the constraint function
|
||||
*
|
||||
* @return The Criterion
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public static Criterion SDONN(String propertyName, Geometry geom, SDOParameterMap param) {
|
||||
return new OracleSpatialCriterion( propertyName, geom, param ) {
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final String[] columns = criteriaQuery.getColumnsUsingProjection( criteria, this.propertyName );
|
||||
final StringBuilder sql = new StringBuilder( "SDO_NN(" );
|
||||
sql.append( columns[0] ).append( "," ).append( "?" );
|
||||
if ( param != null && !param.isEmpty() ) {
|
||||
sql.append( "," ).append( param.toQuotedString() );
|
||||
}
|
||||
sql.append( ") = 'TRUE'" );
|
||||
return sql.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the "SDO_RELATE" constraint to the specified property, using the specified {@code SDOParameterMap}
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param geom The search geometry to use in the constraint
|
||||
* @param param The parameters for the constraint function
|
||||
*
|
||||
* @return The Criterion
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public static Criterion SDORelate(String propertyName, Geometry geom, SDOParameterMap param) {
|
||||
return new OracleSpatialCriterion( propertyName, geom, param ) {
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final String[] columns = criteriaQuery.getColumnsUsingProjection( criteria, this.propertyName );
|
||||
final StringBuilder sql = new StringBuilder( "SDO_RELATE(" );
|
||||
sql.append( columns[0] ).append( "," ).append( "?" );
|
||||
if ( param != null && !param.isEmpty() ) {
|
||||
sql.append( "," ).append( param.toQuotedString() );
|
||||
}
|
||||
sql.append( ") = 'TRUE'" );
|
||||
return sql.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the "SDO_RELATE" constraint to the specified property, using the specified parameters.
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param geom The search geometry to use in the constraint
|
||||
* @param mask The mask parameter
|
||||
* @param minResolution The min_resolution parameter
|
||||
* @param maxResolution The max_resolution parameter
|
||||
*
|
||||
* @return The Criterion
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public static Criterion SDORelate(
|
||||
String propertyName,
|
||||
Geometry geom,
|
||||
RelationshipMask[] mask,
|
||||
Double minResolution,
|
||||
Double maxResolution) {
|
||||
final SDOParameterMap param = new SDOParameterMap();
|
||||
param.setMask( RelationshipMask.booleanCombination( mask ) );
|
||||
param.setMinResolution( minResolution );
|
||||
param.setMaxResolution( maxResolution );
|
||||
return SDORelate( propertyName, geom, param );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the "SDO_WITHIN_DISTANCE" constraint to the specified property, using the specified {@code SDOParameterMap}.
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param geom The search geometry to use in the constraint
|
||||
* @param param The parameters for the constraint function
|
||||
*
|
||||
* @return The Criterion
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public static Criterion SDOWithinDistance(String propertyName, Geometry geom, SDOParameterMap param) {
|
||||
return new OracleSpatialCriterion( propertyName, geom, param ) {
|
||||
|
||||
@Override
|
||||
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
final String[] columns = criteriaQuery.getColumnsUsingProjection( criteria, this.propertyName );
|
||||
final StringBuilder sql = new StringBuilder( "SDO_WITHIN_DISTANCE(" );
|
||||
sql.append( columns[0] ).append( "," ).append( "?" );
|
||||
if ( param != null && !param.isEmpty() ) {
|
||||
sql.append( "," ).append( param.toQuotedString() );
|
||||
}
|
||||
sql.append( ") = 'TRUE'" );
|
||||
return sql.toString();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the "SDO_WITHIN_DISTANCE" constraint to the specified property, using the specified {@code SDOParameterMap}.
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param geom The search geometry to use in the constraint
|
||||
* @param distance The distance parameter for the constraint function
|
||||
* @param param The parameters for the constraint function
|
||||
*
|
||||
* @return The Criterion
|
||||
*/
|
||||
public static Criterion SDOWithinDistance(
|
||||
String propertyName,
|
||||
Geometry geom,
|
||||
Double distance,
|
||||
SDOParameterMap param) {
|
||||
if ( param == null ) {
|
||||
param = new SDOParameterMap();
|
||||
}
|
||||
param.setDistance( distance );
|
||||
return SDOWithinDistance( propertyName, geom, param );
|
||||
}
|
||||
}
|
||||
|
||||
abstract class OracleSpatialCriterion implements Criterion {
|
||||
protected String propertyName;
|
||||
protected Geometry value;
|
||||
protected SDOParameterMap param;
|
||||
|
||||
public OracleSpatialCriterion(String propertyName, Geometry value, SDOParameterMap param) {
|
||||
this.propertyName = propertyName;
|
||||
this.value = value;
|
||||
this.param = param;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.hibernate.criterion.Criterion#getTypedValues(org.hibernate.Criteria,
|
||||
* org.hibernate.criterion.CriteriaQuery)
|
||||
*/
|
||||
|
||||
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
|
||||
return new TypedValue[] {
|
||||
criteriaQuery.getTypedValue( criteria, propertyName, value )
|
||||
};
|
||||
}
|
||||
|
||||
public abstract String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException;
|
||||
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.dialect.oracle.criterion;
|
||||
|
||||
/**
|
||||
* Enumerates the types of spatial relationship masks supported by Oracle Spatial.
|
||||
*/
|
||||
public enum RelationshipMask {
|
||||
/**
|
||||
* The "touch" relationship
|
||||
*/
|
||||
TOUCH,
|
||||
|
||||
/**
|
||||
* The "overlapbydisjoint" relationship
|
||||
*/
|
||||
OVERLAPBYDISJOINT,
|
||||
|
||||
/**
|
||||
* The "overlapbyintersect" relationship
|
||||
*/
|
||||
OVERLAPBYINTERSECT,
|
||||
|
||||
/**
|
||||
* The "equal" relationship
|
||||
*/
|
||||
EQUAL,
|
||||
|
||||
/**
|
||||
* The "inside" relationship
|
||||
*/
|
||||
INSIDE,
|
||||
|
||||
/**
|
||||
* The "coveredby" relationship
|
||||
*/
|
||||
COVEREDBY,
|
||||
|
||||
/**
|
||||
* The "contains" relationship
|
||||
*/
|
||||
CONTAINS,
|
||||
|
||||
/**
|
||||
* The "covers" relationship
|
||||
*/
|
||||
COVERS,
|
||||
|
||||
/**
|
||||
* The "anyinteract" relationship
|
||||
*/
|
||||
ANYINTERACT,
|
||||
|
||||
/**
|
||||
* The "on" relationship
|
||||
*/
|
||||
ON;
|
||||
|
||||
/**
|
||||
* Combines the passed "{@code RelationshipMask}s
|
||||
*
|
||||
* @param masks The array of masks to combine
|
||||
*
|
||||
* @return A {@code String} representing the combined relationship mask
|
||||
*/
|
||||
public static String booleanCombination(RelationshipMask[] masks) {
|
||||
String strMask = null;
|
||||
for ( RelationshipMask relationshipMask : masks ) {
|
||||
if ( strMask == null ) {
|
||||
strMask = relationshipMask.toString();
|
||||
}
|
||||
else {
|
||||
strMask += "+" + relationshipMask.toString();
|
||||
}
|
||||
}
|
||||
return strMask;
|
||||
}
|
||||
}
|
|
@ -1,276 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.dialect.oracle.criterion;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents the parameters that can be passed into Oracle's Spatial operators
|
||||
*
|
||||
* @author Karel Maesen
|
||||
*/
|
||||
public class SDOParameterMap {
|
||||
|
||||
/**
|
||||
* The distance parameter
|
||||
*/
|
||||
public static final String DISTANCE = "distance";
|
||||
/**
|
||||
* The sdo_batch_size parameter
|
||||
*/
|
||||
public static final String SDO_BATCH_SIZE = "sdo_batch_size";
|
||||
/**
|
||||
* The sdo_num_res parameter
|
||||
*/
|
||||
public static final String SDO_NUM_RES = "sdo_num_res";
|
||||
/**
|
||||
* The unit parameter
|
||||
*/
|
||||
public static final String UNIT = "unit";
|
||||
/**
|
||||
* The min_resolution parameter
|
||||
*/
|
||||
public static final String MIN_RESOLUTION = "min_resolution";
|
||||
/**
|
||||
* The max_resolution parameter
|
||||
*/
|
||||
public static final String MAX_RESOLUTION = "max_resolution";
|
||||
/**
|
||||
* The mask parameter
|
||||
*/
|
||||
public static final String MASK = "mask";
|
||||
/**
|
||||
* The querytype parameter
|
||||
*/
|
||||
public static final String QUERYTYPE = "querytype";
|
||||
private Map<String, Object> params = new HashMap<String, Object>();
|
||||
|
||||
/**
|
||||
* Constructs an empty instance
|
||||
*/
|
||||
public SDOParameterMap() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this instance is empty
|
||||
*
|
||||
* @return true if empty, false otherwise
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return this.params.isEmpty();
|
||||
}
|
||||
|
||||
public Double getDistance() {
|
||||
return (Double) params.get( DISTANCE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the distance parameter with the specified value
|
||||
*
|
||||
* @param distance The value for the distance parameter
|
||||
*/
|
||||
public void setDistance(Double distance) {
|
||||
if ( distance != null ) {
|
||||
params.put( DISTANCE, distance );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the distance parameter
|
||||
*/
|
||||
public void removeDistance() {
|
||||
params.remove( DISTANCE );
|
||||
}
|
||||
|
||||
public Integer getSdoBatchSize() {
|
||||
return (Integer) params.get( SDO_BATCH_SIZE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the sdo_batch_size parameter with the specified value
|
||||
*
|
||||
* @param size The value for the sdo_batch_size parameter
|
||||
*/
|
||||
public void setSdoBatchSize(Integer size) {
|
||||
if ( size != null ) {
|
||||
params.put( SDO_BATCH_SIZE, size );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the sdo_batch_size parameter
|
||||
*/
|
||||
public void removeSdoBatchSize() {
|
||||
params.remove( SDO_BATCH_SIZE );
|
||||
}
|
||||
|
||||
public Integer getSdoNumRes() {
|
||||
return (Integer) params.get( SDO_NUM_RES );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the sdo_num_res parameter with the specified value
|
||||
*
|
||||
* @param res The value for the sdo_num_res parameter
|
||||
*/
|
||||
public void setSdoNumRes(Integer res) {
|
||||
if ( res != null ) {
|
||||
params.put( SDO_NUM_RES, res );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the sdo_num_res parameter
|
||||
*/
|
||||
public void removeSdoNumRes() {
|
||||
params.remove( SDO_NUM_RES );
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return (String) this.params.get( UNIT );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the unit parameter with the specified value
|
||||
*
|
||||
* @param unit The value for the unit parameter
|
||||
*/
|
||||
public void setUnit(String unit) {
|
||||
if ( unit != null ) {
|
||||
this.params.put( UNIT, unit );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the unit parameter
|
||||
*/
|
||||
public void removeUnit() {
|
||||
this.params.remove( UNIT );
|
||||
}
|
||||
|
||||
public Double getMaxResolution() {
|
||||
return (Double) params.get( MAX_RESOLUTION );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the max_resolution parameter with the specified value
|
||||
*
|
||||
* @param res The value for the max_resolution parameter
|
||||
*/
|
||||
public void setMaxResolution(Double res) {
|
||||
if ( res != null ) {
|
||||
params.put( MAX_RESOLUTION, res );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the max_resolution parameter
|
||||
*/
|
||||
public void removeMaxResolution() {
|
||||
params.remove( MAX_RESOLUTION );
|
||||
}
|
||||
|
||||
public Double getMinResolution() {
|
||||
return (Double) params.get( MIN_RESOLUTION );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the min_resolution parameter with the specified value
|
||||
*
|
||||
* @param res The value for the min_resolution parameter
|
||||
*/
|
||||
public void setMinResolution(Double res) {
|
||||
if ( res != null ) {
|
||||
params.put( MIN_RESOLUTION, res );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the min_resolution parameter
|
||||
*/
|
||||
public void removeMinResolution() {
|
||||
params.remove( MIN_RESOLUTION );
|
||||
}
|
||||
|
||||
public String getMask() {
|
||||
return (String) this.params.get( MASK );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the mask parameter with the specified value
|
||||
*
|
||||
* @param mask The value for the mask parameter
|
||||
*/
|
||||
public void setMask(String mask) {
|
||||
if ( mask != null ) {
|
||||
this.params.put( MASK, mask );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the mask parameter
|
||||
*/
|
||||
public void removeMask() {
|
||||
this.params.remove( MASK );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the querytype parameter with value "FILTER"
|
||||
*/
|
||||
public void setQueryTypeToFilter() {
|
||||
this.params.put( QUERYTYPE, "FILTER" );
|
||||
}
|
||||
|
||||
public String getQueryType() {
|
||||
return (String) this.params.get( QUERYTYPE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the querytype parameter with the specified value
|
||||
*
|
||||
* @param queryType The value for the quertype parameter
|
||||
*/
|
||||
public void setQueryType(String queryType) {
|
||||
if ( queryType != null ) {
|
||||
this.params.put( QUERYTYPE, queryType );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the querytype parameter
|
||||
*/
|
||||
public void removeQueryType() {
|
||||
this.params.remove( QUERYTYPE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all parameters contained in this instance as a quoted String containing
|
||||
* the {@code <parameter name>=<parameter value>} pairs separated by spaces.
|
||||
* <p>
|
||||
* The return format is as expected by the various SDO_GEOMETRY spatial functions.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String toQuotedString() {
|
||||
final StringBuilder stb = new StringBuilder();
|
||||
if ( params.isEmpty() ) {
|
||||
return "";
|
||||
}
|
||||
stb.append( '\'' );
|
||||
for ( Map.Entry<String, Object> kv : params.entrySet() ) {
|
||||
if ( kv.getValue() == null ) {
|
||||
continue;
|
||||
}
|
||||
stb.append( kv.getKey() ).append( "=" ).append( kv.getValue() ).append( " " );
|
||||
}
|
||||
stb.deleteCharAt( stb.length() - 1 );
|
||||
stb.append( '\'' );
|
||||
return stb.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
<!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>
|
||||
A criterion API for Oracle Spatial (10g and later) using SDOGeometry.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
|
@ -11,7 +11,6 @@ import java.sql.CallableStatement;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.type.descriptor.ValueBinder;
|
||||
import org.hibernate.type.descriptor.ValueExtractor;
|
||||
|
@ -19,9 +18,7 @@ import org.hibernate.type.descriptor.WrapperOptions;
|
|||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.BasicBinder;
|
||||
import org.hibernate.type.descriptor.jdbc.BasicExtractor;
|
||||
import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.sql.BasicExtractor;
|
||||
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
|
||||
import org.geolatte.geom.ByteBuffer;
|
||||
import org.geolatte.geom.ByteOrder;
|
||||
|
@ -38,7 +35,7 @@ import org.postgresql.util.PGobject;
|
|||
*
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
*/
|
||||
public class PGGeometryTypeDescriptor implements SqlTypeDescriptor {
|
||||
public class PGGeometryTypeDescriptor implements JdbcTypeDescriptor {
|
||||
|
||||
|
||||
private final Wkb.Dialect wkbDialect;
|
||||
|
@ -80,7 +77,7 @@ public class PGGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getSqlType() {
|
||||
public int getJdbcType() {
|
||||
return 5432;
|
||||
}
|
||||
|
||||
|
@ -108,7 +105,7 @@ public class PGGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
|
||||
private PGobject toPGobject(X value, WrapperOptions options) throws SQLException {
|
||||
final WkbEncoder encoder = Wkb.newEncoder( Wkb.Dialect.POSTGIS_EWKB_1 );
|
||||
final Geometry geometry = getJavaDescriptor().unwrap( value, Geometry.class, options );
|
||||
final Geometry geometry = getJavaTypeDescriptor().unwrap( value, Geometry.class, options );
|
||||
final String hexString = encoder.encode( geometry, ByteOrder.NDR ).toString();
|
||||
final PGobject obj = new PGobject();
|
||||
obj.setType( "geometry" );
|
||||
|
@ -123,20 +120,21 @@ public class PGGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
|
||||
return new BasicExtractor<X>( javaTypeDescriptor, this ) {
|
||||
|
||||
|
||||
@Override
|
||||
protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
|
||||
return getJavaDescriptor().wrap( toGeometry( rs.getObject( name ) ), options );
|
||||
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
|
||||
return getJavaTypeDescriptor().wrap( toGeometry( rs.getObject( paramIndex ) ), options );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
|
||||
return getJavaDescriptor().wrap( toGeometry( statement.getObject( index ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( toGeometry( statement.getObject( index ) ), options );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
|
||||
throws SQLException {
|
||||
return getJavaDescriptor().wrap( toGeometry( statement.getObject( name ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( toGeometry( statement.getObject( name ) ), options );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.hibernate.spatial.SpatialDialect;
|
|||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.dialect.SpatialFunctionsRegistry;
|
||||
|
||||
interface PGSpatialDialectTrait extends SpatialDialect {
|
||||
interface PGSpatialDialectTrait {
|
||||
|
||||
PostgisSupport support = new PostgisSupport();
|
||||
|
||||
|
@ -34,7 +34,7 @@ interface PGSpatialDialectTrait extends SpatialDialect {
|
|||
*
|
||||
* @return SQL fragment {@code SpatialRelateExpression}
|
||||
*/
|
||||
@Override
|
||||
|
||||
default String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
return support.getSpatialRelateSQL( columnName, spatialRelation );
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ interface PGSpatialDialectTrait extends SpatialDialect {
|
|||
*
|
||||
* @return Rhe SQL fragment for the {@code SpatialFilterExpression}
|
||||
*/
|
||||
@Override
|
||||
|
||||
default String getSpatialFilterExpression(String columnName) {
|
||||
return support.getSpatialFilterExpression( columnName );
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ interface PGSpatialDialectTrait extends SpatialDialect {
|
|||
*
|
||||
* @return The SQL fragment for the projection
|
||||
*/
|
||||
@Override
|
||||
|
||||
default String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
return support.getSpatialAggregateSQL( columnName, aggregation );
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ interface PGSpatialDialectTrait extends SpatialDialect {
|
|||
*
|
||||
* @return The SQL fragment when parsing a <code>DWithinExpression</code>.
|
||||
*/
|
||||
@Override
|
||||
|
||||
default String getDWithinSQL(String columnName) {
|
||||
return support.getDWithinSQL( columnName );
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ interface PGSpatialDialectTrait extends SpatialDialect {
|
|||
*
|
||||
* @return The SQL fragment for a <code>HavingSridExpression</code>.
|
||||
*/
|
||||
@Override
|
||||
|
||||
default String getHavingSridSQL(String columnName) {
|
||||
return support.getHavingSridSQL( columnName );
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ interface PGSpatialDialectTrait extends SpatialDialect {
|
|||
*
|
||||
* @return The SQL fragment for the isempty function
|
||||
*/
|
||||
@Override
|
||||
|
||||
default String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
return support.getIsEmptySQL( columnName, isEmpty );
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ interface PGSpatialDialectTrait extends SpatialDialect {
|
|||
*
|
||||
* @return True if filtering is supported
|
||||
*/
|
||||
@Override
|
||||
|
||||
default boolean supportsFiltering() {
|
||||
return support.supportsFiltering();
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ interface PGSpatialDialectTrait extends SpatialDialect {
|
|||
*
|
||||
* @return True if this <code>SpatialDialect</code> supports the spatial function specified by the function parameter.
|
||||
*/
|
||||
@Override
|
||||
|
||||
default boolean supports(SpatialFunction function) {
|
||||
return support.supports( function );
|
||||
}
|
||||
|
|
|
@ -16,6 +16,10 @@ import org.hibernate.dialect.function.StandardSQLFunction;
|
|||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.dialect.SpatialFunctionsRegistry;
|
||||
import org.hibernate.sql.ast.SqlAstTranslator;
|
||||
import org.hibernate.sql.ast.spi.SqlAppender;
|
||||
import org.hibernate.sql.ast.tree.SqlAstNode;
|
||||
import org.hibernate.sql.ast.tree.predicate.Predicate;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
|
@ -182,10 +186,10 @@ public class PostgisFunctions extends SpatialFunctionsRegistry {
|
|||
"extent", new ExtentFunction()
|
||||
);
|
||||
|
||||
//register Spatial Filter function
|
||||
put(
|
||||
SpatialFunction.filter.name(), new FilterFunction()
|
||||
);
|
||||
// //register Spatial Filter function
|
||||
// put(
|
||||
// SpatialFunction.filter.name(), new FilterFunction()
|
||||
// );
|
||||
|
||||
//other common functions
|
||||
put(
|
||||
|
@ -207,39 +211,43 @@ public class PostgisFunctions extends SpatialFunctionsRegistry {
|
|||
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";
|
||||
}
|
||||
}
|
||||
|
||||
private static class FilterFunction extends StandardSQLFunction {
|
||||
|
||||
public FilterFunction() {
|
||||
super( "&&" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String render(
|
||||
Type firstArgumentType, List arguments, SessionFactoryImplementor sessionFactory) {
|
||||
int argumentCount = arguments.size();
|
||||
if ( argumentCount != 2 ) {
|
||||
throw new QueryException( String.format(
|
||||
Locale.ENGLISH,
|
||||
"2 arguments expected, received %d",
|
||||
argumentCount
|
||||
) );
|
||||
public void render(
|
||||
SqlAppender sqlAppender,
|
||||
List<SqlAstNode> sqlAstArguments,
|
||||
Predicate filter,
|
||||
SqlAstTranslator<?> translator) {
|
||||
super.render( sqlAppender, sqlAstArguments, filter, translator ) ;
|
||||
sqlAppender.appendSql( "::geometry" );
|
||||
}
|
||||
}
|
||||
|
||||
return Stream.of(
|
||||
String.valueOf( arguments.get( 0 ) ),
|
||||
getRenderedName( arguments ),
|
||||
String.valueOf( arguments.get( 1 ) )
|
||||
).collect( Collectors.joining( " ", "(", ")" ) );
|
||||
}
|
||||
}
|
||||
// private static class FilterFunction extends StandardSQLFunction {
|
||||
//
|
||||
// public FilterFunction() {
|
||||
// super( "&&" );
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String render(
|
||||
// Type firstArgumentType, List arguments, SessionFactoryImplementor sessionFactory) {
|
||||
// int argumentCount = arguments.size();
|
||||
// if ( argumentCount != 2 ) {
|
||||
// throw new QueryException( String.format(
|
||||
// Locale.ENGLISH,
|
||||
// "2 arguments expected, received %d",
|
||||
// argumentCount
|
||||
// ) );
|
||||
// }
|
||||
//
|
||||
// return Stream.of(
|
||||
// String.valueOf( arguments.get( 0 ) ),
|
||||
// getRenderedName( arguments ),
|
||||
// String.valueOf( arguments.get( 1 ) )
|
||||
// ).collect( Collectors.joining( " ", "(", ")" ) );
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -7,11 +7,6 @@
|
|||
|
||||
package org.hibernate.spatial.dialect.postgis;
|
||||
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.SpatialRelation;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
||||
/**
|
||||
* A Dialect for Postgresql with support for the Postgis spatial types, functions and operators (release 1.x - 1.3)
|
||||
*
|
||||
|
@ -19,224 +14,4 @@ import org.hibernate.type.StandardBasicTypes;
|
|||
* creation-date: Dec 18, 2010
|
||||
*/
|
||||
public class PostgisNoSQLMM extends PostgisDialect {
|
||||
|
||||
public PostgisNoSQLMM() {
|
||||
|
||||
registerColumnType(
|
||||
PGGeometryTypeDescriptor.INSTANCE_WKB_1.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(
|
||||
"dimension",
|
||||
StandardBasicTypes.INTEGER
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"geometrytype", new StandardSQLFunction(
|
||||
"geometrytype", StandardBasicTypes.STRING
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"srid", new StandardSQLFunction(
|
||||
"srid",
|
||||
StandardBasicTypes.INTEGER
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"envelope", new StandardSQLFunction(
|
||||
"envelope"
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"astext", new StandardSQLFunction(
|
||||
"astext",
|
||||
StandardBasicTypes.STRING
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"asbinary", new StandardSQLFunction(
|
||||
"asbinary",
|
||||
StandardBasicTypes.BINARY
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"isempty", new StandardSQLFunction(
|
||||
"isempty",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"issimple", new StandardSQLFunction(
|
||||
"issimple",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"boundary", new StandardSQLFunction(
|
||||
"boundary"
|
||||
)
|
||||
);
|
||||
|
||||
// Register functions for spatial relation constructs
|
||||
registerFunction(
|
||||
"overlaps", new StandardSQLFunction(
|
||||
"overlaps",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"intersects", new StandardSQLFunction(
|
||||
"intersects",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"equals", new StandardSQLFunction(
|
||||
"equals",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"contains", new StandardSQLFunction(
|
||||
"contains",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"crosses", new StandardSQLFunction(
|
||||
"crosses",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"disjoint", new StandardSQLFunction(
|
||||
"disjoint",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"touches", new StandardSQLFunction(
|
||||
"touches",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"within", new StandardSQLFunction(
|
||||
"within",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"relate", new StandardSQLFunction(
|
||||
"relate",
|
||||
StandardBasicTypes.BOOLEAN
|
||||
)
|
||||
);
|
||||
|
||||
// register the spatial analysis functions
|
||||
registerFunction(
|
||||
"distance", new StandardSQLFunction(
|
||||
"distance",
|
||||
StandardBasicTypes.DOUBLE
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"buffer", new StandardSQLFunction(
|
||||
"buffer"
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"convexhull", new StandardSQLFunction(
|
||||
"convexhull"
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"difference", new StandardSQLFunction(
|
||||
"difference"
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"intersection", new StandardSQLFunction(
|
||||
"intersection"
|
||||
)
|
||||
);
|
||||
registerFunction(
|
||||
"symdifference",
|
||||
new StandardSQLFunction( "symdifference" )
|
||||
);
|
||||
registerFunction(
|
||||
"geomunion", new StandardSQLFunction(
|
||||
"geomunion"
|
||||
)
|
||||
);
|
||||
|
||||
//register Spatial Aggregate function
|
||||
registerFunction(
|
||||
"extent", new StandardSQLFunction(
|
||||
"extent"
|
||||
)
|
||||
);
|
||||
|
||||
//other common spatial functions
|
||||
registerFunction(
|
||||
"transform", new StandardSQLFunction(
|
||||
"transform"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDWithinSQL(String columnName) {
|
||||
return "( dwithin(" + columnName + ",?,?) )";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHavingSridSQL(String columnName) {
|
||||
return "( srid(" + columnName + ") = ?)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
final String emptyExpr = "( isempty(" + columnName + ")) ";
|
||||
return isEmpty ? emptyExpr : "not " + emptyExpr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
switch ( spatialRelation ) {
|
||||
case SpatialRelation.WITHIN:
|
||||
return "(" + columnName + " && ? AND within(" + columnName + ", ?))";
|
||||
case SpatialRelation.CONTAINS:
|
||||
return "(" + columnName + " && ? AND contains(" + columnName + ", ?))";
|
||||
case SpatialRelation.CROSSES:
|
||||
return "(" + columnName + " && ? AND crosses(" + columnName + ", ?))";
|
||||
case SpatialRelation.OVERLAPS:
|
||||
return "(" + columnName + " && ? AND overlaps(" + columnName + ", ?))";
|
||||
case SpatialRelation.DISJOINT:
|
||||
return "(" + columnName + " && ? AND disjoint(" + columnName + ", ?))";
|
||||
case SpatialRelation.INTERSECTS:
|
||||
return "(" + columnName + " && ? AND intersects(" + columnName + ", ?))";
|
||||
case SpatialRelation.TOUCHES:
|
||||
return "(" + columnName + " && ? AND touches(" + columnName + ", ?))";
|
||||
case SpatialRelation.EQUALS:
|
||||
return "(" + columnName + " && ? AND equals(" + columnName + ", ?))";
|
||||
default:
|
||||
throw new IllegalArgumentException( "Spatial relation is not known by this dialect" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return super.supports( function );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,41 +7,18 @@
|
|||
|
||||
package org.hibernate.spatial.dialect.postgis;
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.PostgreSQL10Dialect;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.dialect.PostgreSQLDialect;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
public class PostgisPG10Dialect extends PostgreSQL10Dialect implements PGSpatialDialectTrait {
|
||||
@Deprecated
|
||||
public class PostgisPG10Dialect extends PostgreSQLDialect {
|
||||
|
||||
public PostgisPG10Dialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, SQLFunction> entry : functionsToRegister() ) {
|
||||
registerFunction( entry.getKey(), entry.getValue() );
|
||||
super( 100 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
super.contributeTypes(
|
||||
typeContributions,
|
||||
serviceRegistry
|
||||
);
|
||||
support.contributeTypes( typeContributions, serviceRegistry );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equivalentTypes(int typeCode1, int typeCode2) {
|
||||
return super.equivalentTypes( typeCode1, typeCode2 ) ||
|
||||
( isSpatial( typeCode1 ) && isSpatial( typeCode2 ) );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -6,14 +6,8 @@
|
|||
*/
|
||||
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.SQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
|
||||
/**
|
||||
* Extends the {@code PostgreSQL82Dialect} to add support for the Postgis spatial types, functions and operators .
|
||||
|
@ -21,76 +15,4 @@ import org.hibernate.spatial.SpatialFunction;
|
|||
* Created by Karel Maesen, Geovise BVBA on 01/11/16.
|
||||
*/
|
||||
public class PostgisPG82Dialect extends PostgreSQL82Dialect implements SpatialDialect {
|
||||
|
||||
|
||||
transient private PostgisSupport support = new PostgisSupport();
|
||||
|
||||
/**
|
||||
* Creates an instance
|
||||
*/
|
||||
public PostgisPG82Dialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, SQLFunction> 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 boolean equivalentTypes(int typeCode1, int typeCode2) {
|
||||
return super.equivalentTypes( typeCode1, typeCode2 ) ||
|
||||
( support.isSpatial( typeCode1 ) && support.isSpatial( typeCode2 ) );
|
||||
}
|
||||
|
||||
@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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,14 +6,8 @@
|
|||
*/
|
||||
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.SQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
|
||||
/**
|
||||
* Extends the {@code PostgreSQL91Dialect} to add support for the Postgis spatial types, functions and operators .
|
||||
|
@ -21,143 +15,4 @@ import org.hibernate.spatial.SpatialFunction;
|
|||
* Created by Karel Maesen, Geovise BVBA on 01/11/16.
|
||||
*/
|
||||
public class PostgisPG91Dialect extends PostgreSQL91Dialect implements SpatialDialect {
|
||||
|
||||
|
||||
transient private PostgisSupport support = new PostgisSupport();
|
||||
|
||||
/**
|
||||
* Creates an instance
|
||||
*/
|
||||
public PostgisPG91Dialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, SQLFunction> 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 boolean equivalentTypes(int typeCode1, int typeCode2) {
|
||||
return super.equivalentTypes( typeCode1, typeCode2 ) ||
|
||||
( support.isSpatial( typeCode1 ) && support.isSpatial( typeCode2 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 a <code>HavingSridExpression</code>.
|
||||
*
|
||||
* @param columnName The geometry column to test against
|
||||
*
|
||||
* @return The SQL fragment for a <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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,14 +6,8 @@
|
|||
*/
|
||||
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.SQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
|
||||
/**
|
||||
* Extends the {@code PostgreSQL92Dialect} to add support for the Postgis spatial types, functions and operators .
|
||||
|
@ -21,143 +15,4 @@ import org.hibernate.spatial.SpatialFunction;
|
|||
* Created by Karel Maesen, Geovise BVBA on 01/11/16.
|
||||
*/
|
||||
public class PostgisPG92Dialect extends PostgreSQL92Dialect implements SpatialDialect {
|
||||
|
||||
|
||||
transient private PostgisSupport support = new PostgisSupport();
|
||||
|
||||
/**
|
||||
* Creates an instance
|
||||
*/
|
||||
public PostgisPG92Dialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, SQLFunction> 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 boolean equivalentTypes(int typeCode1, int typeCode2) {
|
||||
return super.equivalentTypes( typeCode1, typeCode2 ) ||
|
||||
( support.isSpatial( typeCode1 ) && support.isSpatial( typeCode2 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 a <code>HavingSridExpression</code>.
|
||||
*
|
||||
* @param columnName The geometry column to test against
|
||||
*
|
||||
* @return The SQL fragment for a <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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,14 +6,8 @@
|
|||
*/
|
||||
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.SQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
|
||||
/**
|
||||
* Extends the {@code PostgreSQL93Dialect} to add support for the Postgis spatial types, functions and operators .
|
||||
|
@ -21,143 +15,4 @@ import org.hibernate.spatial.SpatialFunction;
|
|||
* Created by Karel Maesen, Geovise BVBA on 01/11/16.
|
||||
*/
|
||||
public class PostgisPG93Dialect extends PostgreSQL93Dialect implements SpatialDialect {
|
||||
|
||||
|
||||
transient private PostgisSupport support = new PostgisSupport();
|
||||
|
||||
/**
|
||||
* Creates an instance
|
||||
*/
|
||||
public PostgisPG93Dialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, SQLFunction> 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 boolean equivalentTypes(int typeCode1, int typeCode2) {
|
||||
return super.equivalentTypes( typeCode1, typeCode2 ) ||
|
||||
( support.isSpatial( typeCode1 ) && support.isSpatial( typeCode2 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 a <code>HavingSridExpression</code>.
|
||||
*
|
||||
* @param columnName The geometry column to test against
|
||||
*
|
||||
* @return The SQL fragment for a <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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,14 +6,8 @@
|
|||
*/
|
||||
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.SQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
|
||||
/**
|
||||
* Extends the {@code PostgreSQL94Dialect} to add support for the Postgis spatial types, functions and operators .
|
||||
|
@ -21,143 +15,4 @@ import org.hibernate.spatial.SpatialFunction;
|
|||
* Created by Karel Maesen, Geovise BVBA on 01/11/16.
|
||||
*/
|
||||
public class PostgisPG94Dialect extends PostgreSQL94Dialect implements SpatialDialect {
|
||||
|
||||
|
||||
transient private PostgisSupport support = new PostgisSupport();
|
||||
|
||||
/**
|
||||
* Creates an instance
|
||||
*/
|
||||
public PostgisPG94Dialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, SQLFunction> 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 boolean equivalentTypes(int typeCode1, int typeCode2) {
|
||||
return super.equivalentTypes( typeCode1, typeCode2 ) ||
|
||||
( support.isSpatial( typeCode1 ) && support.isSpatial( typeCode2 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 a <code>HavingSridExpression</code>.
|
||||
*
|
||||
* @param columnName The geometry column to test against
|
||||
*
|
||||
* @return The SQL fragment for a <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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,45 +6,11 @@
|
|||
*/
|
||||
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.SQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
/**
|
||||
* Extends the {@code PostgreSQL95Dialect} to add support for the Postgis spatial types, functions and operators .
|
||||
* Created by Karel Maesen, Geovise BVBA on 01/11/16.
|
||||
*/
|
||||
public class PostgisPG95Dialect extends PostgreSQL95Dialect implements PGSpatialDialectTrait {
|
||||
|
||||
/**
|
||||
* Creates an instance
|
||||
*/
|
||||
public PostgisPG95Dialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, SQLFunction> entry : functionsToRegister() ) {
|
||||
registerFunction( entry.getKey(), entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
|
||||
super.contributeTypes(
|
||||
typeContributions,
|
||||
serviceRegistry
|
||||
);
|
||||
support.contributeTypes( typeContributions, serviceRegistry );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equivalentTypes(int typeCode1, int typeCode2) {
|
||||
return super.equivalentTypes( typeCode1, typeCode2 ) ||
|
||||
( isSpatial( typeCode1 ) && isSpatial( typeCode2 ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,14 +6,8 @@
|
|||
*/
|
||||
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.SQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
|
||||
/**
|
||||
* * Extends the {@code PostgreSQL9Dialect} to add support for the Postgis spatial types, functions and operators .
|
||||
|
@ -21,143 +15,4 @@ import org.hibernate.spatial.SpatialFunction;
|
|||
* Created by Karel Maesen, Geovise BVBA on 01/11/16.
|
||||
*/
|
||||
public class PostgisPG9Dialect extends PostgreSQL9Dialect implements SpatialDialect {
|
||||
|
||||
|
||||
transient private PostgisSupport support = new PostgisSupport();
|
||||
|
||||
/**
|
||||
* Creates an instance
|
||||
*/
|
||||
public PostgisPG9Dialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
for ( Map.Entry<String, SQLFunction> 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 boolean equivalentTypes(int typeCode1, int typeCode2) {
|
||||
return super.equivalentTypes( typeCode1, typeCode2 ) ||
|
||||
( support.isSpatial( typeCode1 ) && support.isSpatial( typeCode2 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 a <code>HavingSridExpression</code>.
|
||||
*
|
||||
* @param columnName The geometry column to test against
|
||||
*
|
||||
* @return The SQL fragment for a <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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class PostgisSupport implements SpatialDialect, Serializable {
|
|||
}
|
||||
|
||||
public boolean isSpatial(int typeCode){
|
||||
return typeCode == Types.OTHER || typeCode == PGGeometryTypeDescriptor.INSTANCE_WKB_1.getSqlType();
|
||||
return typeCode == Types.OTHER || typeCode == PGGeometryTypeDescriptor.INSTANCE_WKB_1.getJdbcType();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,7 +65,7 @@ public class PostgisSupport implements SpatialDialect, Serializable {
|
|||
*
|
||||
* @return SQL fragment {@code SpatialRelateExpression}
|
||||
*/
|
||||
@Override
|
||||
|
||||
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
switch ( spatialRelation ) {
|
||||
case SpatialRelation.WITHIN:
|
||||
|
@ -102,7 +102,7 @@ public class PostgisSupport implements SpatialDialect, Serializable {
|
|||
*
|
||||
* @return Rhe SQL fragment for the {@code SpatialFilterExpression}
|
||||
*/
|
||||
@Override
|
||||
|
||||
public String getSpatialFilterExpression(String columnName) {
|
||||
return "(" + columnName + " && ? ) ";
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ public class PostgisSupport implements SpatialDialect, Serializable {
|
|||
*
|
||||
* @return The SQL fragment for the projection
|
||||
*/
|
||||
@Override
|
||||
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
switch ( aggregation ) {
|
||||
case SpatialAggregate.EXTENT:
|
||||
|
@ -137,7 +137,7 @@ public class PostgisSupport implements SpatialDialect, Serializable {
|
|||
*
|
||||
* @return The SQL fragment when parsing a <code>DWithinExpression</code>.
|
||||
*/
|
||||
@Override
|
||||
|
||||
public String getDWithinSQL(String columnName) {
|
||||
return "ST_DWithin(" + columnName + ",?,?)";
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ public class PostgisSupport implements SpatialDialect, Serializable {
|
|||
*
|
||||
* @return The SQL fragment for a <code>HavingSridExpression</code>.
|
||||
*/
|
||||
@Override
|
||||
|
||||
public String getHavingSridSQL(String columnName) {
|
||||
return "( ST_srid(" + columnName + ") = ?)";
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ public class PostgisSupport implements SpatialDialect, Serializable {
|
|||
*
|
||||
* @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 + ")";
|
||||
|
@ -175,7 +175,7 @@ public class PostgisSupport implements SpatialDialect, Serializable {
|
|||
*
|
||||
* @return True if filtering is supported
|
||||
*/
|
||||
@Override
|
||||
|
||||
public boolean supportsFiltering() {
|
||||
return true;
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ public class PostgisSupport implements SpatialDialect, Serializable {
|
|||
*
|
||||
* @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 );
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.hibernate.type.descriptor.WrapperOptions;
|
|||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.BasicBinder;
|
||||
import org.hibernate.type.descriptor.jdbc.BasicExtractor;
|
||||
import org.hibernate.type.descriptor.jdbc.SqlTypeDescriptor;
|
||||
import org.hibernate.type.descriptor.jdbc.JdbcTypeDescriptor;
|
||||
|
||||
import org.geolatte.geom.Geometry;
|
||||
import org.geolatte.geom.codec.db.sqlserver.Decoders;
|
||||
|
@ -32,7 +32,7 @@ import org.geolatte.geom.codec.db.sqlserver.Encoders;
|
|||
* @author Karel Maesen, Geovise BVBA
|
||||
* creation-date: 8/23/11
|
||||
*/
|
||||
public class SqlServer2008GeometryTypeDescriptor implements SqlTypeDescriptor {
|
||||
public class SqlServer2008GeometryTypeDescriptor implements JdbcTypeDescriptor {
|
||||
|
||||
/**
|
||||
* An instance of the descrtiptor
|
||||
|
@ -40,7 +40,7 @@ public class SqlServer2008GeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
public static final SqlServer2008GeometryTypeDescriptor INSTANCE = new SqlServer2008GeometryTypeDescriptor();
|
||||
|
||||
@Override
|
||||
public int getSqlType() {
|
||||
public int getJdbcType() {
|
||||
return Types.ARRAY;
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ public class SqlServer2008GeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
@Override
|
||||
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
|
||||
throws SQLException {
|
||||
final Geometry geometry = getJavaDescriptor().unwrap( value, Geometry.class, options );
|
||||
final Geometry geometry = getJavaTypeDescriptor().unwrap( value, Geometry.class, options );
|
||||
final byte[] bytes = Encoders.encode( geometry );
|
||||
st.setObject( index, bytes );
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public class SqlServer2008GeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
@Override
|
||||
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
|
||||
throws SQLException {
|
||||
final Geometry geometry = getJavaDescriptor().unwrap( value, Geometry.class, options );
|
||||
final Geometry geometry = getJavaTypeDescriptor().unwrap( value, Geometry.class, options );
|
||||
final byte[] bytes = Encoders.encode( geometry );
|
||||
st.setObject( name, bytes );
|
||||
}
|
||||
|
@ -77,18 +77,18 @@ public class SqlServer2008GeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
|
||||
@Override
|
||||
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
|
||||
return getJavaDescriptor().wrap( toGeometry( rs.getObject( paramIndex ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( toGeometry( rs.getObject( paramIndex ) ), options );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
|
||||
return getJavaDescriptor().wrap( toGeometry( statement.getObject( index ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( toGeometry( statement.getObject( index ) ), options );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
|
||||
throws SQLException {
|
||||
return getJavaDescriptor().wrap( toGeometry( statement.getObject( name ) ), options );
|
||||
return getJavaTypeDescriptor().wrap( toGeometry( statement.getObject( name ) ), options );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -8,21 +8,8 @@
|
|||
package org.hibernate.spatial.dialect.sqlserver;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.SQLServer2008Dialect;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.dialect.function.SQLFunctionTemplate;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.GeolatteGeometryJavaTypeDescriptor;
|
||||
import org.hibernate.spatial.GeolatteGeometryType;
|
||||
import org.hibernate.spatial.JTSGeometryJavaTypeDescriptor;
|
||||
import org.hibernate.spatial.JTSGeometryType;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.SpatialRelation;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
||||
/**
|
||||
* The <code>SpatialDialect</code> for Microsoft SQL Server (2008).
|
||||
|
@ -31,70 +18,4 @@ import org.hibernate.type.StandardBasicTypes;
|
|||
*/
|
||||
public class SqlServer2008SpatialDialect extends SQLServer2008Dialect implements SpatialDialect {
|
||||
|
||||
|
||||
final private SqlServerSupport support = new SqlServerSupport();
|
||||
|
||||
public SqlServer2008SpatialDialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
SqlServer2008GeometryTypeDescriptor.INSTANCE.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
|
||||
for ( Map.Entry<String, SQLFunction> 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 getSpatialFilterExpression(String columnName) {
|
||||
return support.getSpatialFilterExpression( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
return support.getSpatialAggregateSQL( columnName, aggregation );
|
||||
}
|
||||
|
||||
@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 boolean supportsFiltering() {
|
||||
return support.supportsFiltering();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return support.supports( function );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,81 +6,12 @@
|
|||
*/
|
||||
package org.hibernate.spatial.dialect.sqlserver;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.SQLServer2012Dialect;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
|
||||
/**
|
||||
* Created by Karel Maesen, Geovise BVBA on 19/09/2018.
|
||||
*/
|
||||
public class SqlServer2012SpatialDialect extends SQLServer2012Dialect implements SpatialDialect {
|
||||
|
||||
final private SqlServerSupport support = new SqlServerSupport();
|
||||
|
||||
public SqlServer2012SpatialDialect() {
|
||||
super();
|
||||
registerColumnType(
|
||||
SqlServer2008GeometryTypeDescriptor.INSTANCE.getSqlType(),
|
||||
"GEOMETRY"
|
||||
);
|
||||
|
||||
for ( Map.Entry<String, SQLFunction> 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 getSpatialFilterExpression(String columnName) {
|
||||
return support.getSpatialFilterExpression( columnName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
return support.getSpatialAggregateSQL( columnName, aggregation );
|
||||
}
|
||||
|
||||
@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 boolean supportsFiltering() {
|
||||
return support.supportsFiltering();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return support.supports( function );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
*/
|
||||
package org.hibernate.spatial.dialect.sqlserver;
|
||||
|
||||
import org.hibernate.dialect.function.SQLFunctionTemplate;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
|
||||
import org.hibernate.spatial.dialect.SpatialFunctionsRegistry;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Created by Karel Maesen, Geovise BVBA on 19/09/2018.
|
||||
|
@ -17,53 +17,55 @@ import org.hibernate.type.StandardBasicTypes;
|
|||
class SqlServerFunctions extends SpatialFunctionsRegistry {
|
||||
public SqlServerFunctions() {
|
||||
|
||||
put( "dimension", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "?1.STDimension()" ) );
|
||||
put( "geometrytype", new SQLFunctionTemplate( StandardBasicTypes.STRING, "?1.STGeometryType()" ) );
|
||||
put( "srid", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "?1.STSrid" ) );
|
||||
put( "envelope", new SqlServerMethod( "STEnvelope" ) );
|
||||
put( "astext", new SQLFunctionTemplate( StandardBasicTypes.STRING, "?1.STAsText()" ) );
|
||||
put( "asbinary", new SQLFunctionTemplate( StandardBasicTypes.BINARY, "?1.STAsBinary()" ) );
|
||||
//TODO -- re-implement. In 6.0 there is no longer a SQLFunctionTemplate class
|
||||
|
||||
put( "isempty", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STIsEmpty()" ) );
|
||||
put( "issimple", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STIsSimple()" ) );
|
||||
put( "boundary", new SqlServerMethod( "STBoundary" ) );
|
||||
|
||||
// section 2.1.1.2
|
||||
// Register functions for spatial relation constructs
|
||||
put( "contains", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STContains(?2)" ) );
|
||||
put( "crosses", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STCrosses(?2)" ) );
|
||||
put( "disjoint", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STDisjoint(?2)" ) );
|
||||
put( "equals", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STEquals(?2)" ) );
|
||||
put( "intersects", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STIntersects(?2)" ) );
|
||||
put( "overlaps", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STOverlaps(?2)" ) );
|
||||
put( "touches", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STTouches(?2)" ) );
|
||||
put( "within", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STWithin(?2)" ) );
|
||||
put( "relate", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STRelate(?2,?3)" ) );
|
||||
|
||||
// section 2.1.1.3
|
||||
// Register spatial analysis functions.
|
||||
put( "distance", new SQLFunctionTemplate( StandardBasicTypes.DOUBLE, "?1.STDistance(?2)" ) );
|
||||
put( "buffer", new SqlServerMethod( "STBuffer" ) );
|
||||
put( "convexhull", new SqlServerMethod( "STConvexHull" ) );
|
||||
put( "difference", new SqlServerMethod( "STDifference" ) );
|
||||
put( "intersection", new SqlServerMethod( "STIntersection" ) );
|
||||
put( "symdifference", new SqlServerMethod( "STSymDifference" ) );
|
||||
put( "geomunion", new SqlServerMethod( "STUnion" ) );
|
||||
// we rename OGC union to geomunion because union is a reserved SQL keyword.
|
||||
// (See also postgis documentation).
|
||||
|
||||
// portable spatial aggregate functions
|
||||
// no aggregatefunctions implemented in sql-server2000
|
||||
//put("extent", new SQLFunctionTemplate(geomType, "?1.STExtent()"));
|
||||
|
||||
// section 2.1.9.1 methods on surfaces
|
||||
put( "area", new SQLFunctionTemplate( StandardBasicTypes.DOUBLE, "?1.STArea()" ) );
|
||||
put( "centroid", new SqlServerMethod( "STCentroid" ) );
|
||||
put(
|
||||
"pointonsurface", new SqlServerMethod( "STPointOnSurface" )
|
||||
);
|
||||
|
||||
// Register spatial filter function.
|
||||
put( SpatialFunction.filter.name(), new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.Filter(?2)" ) );
|
||||
// put( "dimension", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "?1.STDimension()" ) );
|
||||
// put( "geometrytype", new SQLFunctionTemplate( StandardBasicTypes.STRING, "?1.STGeometryType()" ) );
|
||||
// put( "srid", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "?1.STSrid" ) );
|
||||
// put( "envelope", new SqlServerMethod( "STEnvelope" ) );
|
||||
// put( "astext", new SQLFunctionTemplate( StandardBasicTypes.STRING, "?1.STAsText()" ) );
|
||||
// put( "asbinary", new SQLFunctionTemplate( StandardBasicTypes.BINARY, "?1.STAsBinary()" ) );
|
||||
//
|
||||
// put( "isempty", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STIsEmpty()" ) );
|
||||
// put( "issimple", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STIsSimple()" ) );
|
||||
// put( "boundary", new SqlServerMethod( "STBoundary" ) );
|
||||
//
|
||||
// // section 2.1.1.2
|
||||
// // Register functions for spatial relation constructs
|
||||
// put( "contains", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STContains(?2)" ) );
|
||||
// put( "crosses", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STCrosses(?2)" ) );
|
||||
// put( "disjoint", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STDisjoint(?2)" ) );
|
||||
// put( "equals", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STEquals(?2)" ) );
|
||||
// put( "intersects", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STIntersects(?2)" ) );
|
||||
// put( "overlaps", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STOverlaps(?2)" ) );
|
||||
// put( "touches", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STTouches(?2)" ) );
|
||||
// put( "within", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STWithin(?2)" ) );
|
||||
// put( "relate", new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.STRelate(?2,?3)" ) );
|
||||
//
|
||||
// // section 2.1.1.3
|
||||
// // Register spatial analysis functions.
|
||||
// put( "distance", new SQLFunctionTemplate( StandardBasicTypes.DOUBLE, "?1.STDistance(?2)" ) );
|
||||
// put( "buffer", new SqlServerMethod( "STBuffer" ) );
|
||||
// put( "convexhull", new SqlServerMethod( "STConvexHull" ) );
|
||||
// put( "difference", new SqlServerMethod( "STDifference" ) );
|
||||
// put( "intersection", new SqlServerMethod( "STIntersection" ) );
|
||||
// put( "symdifference", new SqlServerMethod( "STSymDifference" ) );
|
||||
// put( "geomunion", new SqlServerMethod( "STUnion" ) );
|
||||
// // we rename OGC union to geomunion because union is a reserved SQL keyword.
|
||||
// // (See also postgis documentation).
|
||||
//
|
||||
// // portable spatial aggregate functions
|
||||
// // no aggregatefunctions implemented in sql-server2000
|
||||
// //put("extent", new SQLFunctionTemplate(geomType, "?1.STExtent()"));
|
||||
//
|
||||
// // section 2.1.9.1 methods on surfaces
|
||||
// put( "area", new SQLFunctionTemplate( StandardBasicTypes.DOUBLE, "?1.STArea()" ) );
|
||||
// put( "centroid", new SqlServerMethod( "STCentroid" ) );
|
||||
// put(
|
||||
// "pointonsurface", new SqlServerMethod( "STPointOnSurface" )
|
||||
// );
|
||||
//
|
||||
// // Register spatial filter function.
|
||||
// put( SpatialFunction.filter.name(), new SQLFunctionTemplate( StandardBasicTypes.BOOLEAN, "?1.Filter(?2)" ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class SqlServerMethod extends StandardSQLFunction {
|
|||
super( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public String render(Type firstArgumentType, List arguments, SessionFactoryImplementor sessionFactory) {
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
if ( arguments.size() < 1 ) {
|
||||
|
|
|
@ -10,7 +10,9 @@ import java.io.Serializable;
|
|||
import java.util.Map;
|
||||
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
|
||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.GeolatteGeometryJavaTypeDescriptor;
|
||||
import org.hibernate.spatial.GeolatteGeometryType;
|
||||
|
@ -27,7 +29,7 @@ class SqlServerSupport implements SpatialDialect, Serializable {
|
|||
|
||||
private SqlServerFunctions functions = new SqlServerFunctions();
|
||||
|
||||
Iterable<? extends Map.Entry<String, SQLFunction>> functionsToRegister() {
|
||||
Iterable<? extends Map.Entry<String, SqmFunctionDescriptor>> functionsToRegister() {
|
||||
return functions;
|
||||
}
|
||||
|
||||
|
@ -40,7 +42,7 @@ class SqlServerSupport implements SpatialDialect, Serializable {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
|
||||
final String stfunction;
|
||||
switch ( spatialRelation ) {
|
||||
|
@ -77,38 +79,38 @@ class SqlServerSupport implements SpatialDialect, Serializable {
|
|||
return columnName + "." + stfunction + "(?) = 1";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public String getSpatialFilterExpression(String columnName) {
|
||||
return columnName + ".Filter(?) = 1";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public String getSpatialAggregateSQL(String columnName, int aggregation) {
|
||||
throw new UnsupportedOperationException( "No spatial aggregate SQL functions." );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public String getDWithinSQL(String columnName) {
|
||||
throw new UnsupportedOperationException( "SQL Server has no DWithin function." );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public String getHavingSridSQL(String columnName) {
|
||||
return columnName + ".STSrid = (?)";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public String getIsEmptySQL(String columnName, boolean isEmpty) {
|
||||
final String base = "(" + columnName + ".STIsEmpty() ";
|
||||
return isEmpty ? base + " = 1 )" : base + " = 0 )";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public boolean supportsFiltering() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public boolean supports(SpatialFunction function) {
|
||||
return ( functions.get( function.toString() ) != null );
|
||||
}
|
||||
|
|
|
@ -6,20 +6,9 @@
|
|||
*/
|
||||
package org.hibernate.spatial.predicate;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.Expression;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.query.criteria.internal.CriteriaBuilderImpl;
|
||||
import org.hibernate.query.criteria.internal.ParameterRegistry;
|
||||
import org.hibernate.query.criteria.internal.Renderable;
|
||||
import org.hibernate.query.criteria.internal.compile.RenderingContext;
|
||||
import org.hibernate.query.criteria.internal.predicate.AbstractSimplePredicate;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.dialect.WithCustomJPAFilter;
|
||||
|
||||
import org.geolatte.geom.Envelope;
|
||||
import org.geolatte.geom.Geometry;
|
||||
import org.geolatte.geom.Polygon;
|
||||
|
@ -31,7 +20,7 @@ import org.geolatte.geom.crs.CoordinateReferenceSystem;
|
|||
/**
|
||||
* {@link JTSFilterPredicate}, but for geolatte-geom.
|
||||
*/
|
||||
public class GeolatteFilterPredicate extends AbstractSimplePredicate implements Serializable {
|
||||
public class GeolatteFilterPredicate {
|
||||
|
||||
private final Expression<? extends Geometry> geometry;
|
||||
private final Expression<? extends Geometry> filter;
|
||||
|
@ -39,7 +28,7 @@ public class GeolatteFilterPredicate extends AbstractSimplePredicate implements
|
|||
public GeolatteFilterPredicate(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry,
|
||||
Expression<? extends Geometry> filter) {
|
||||
super( (CriteriaBuilderImpl) criteriaBuilder );
|
||||
|
||||
this.geometry = geometry;
|
||||
this.filter = filter;
|
||||
}
|
||||
|
@ -58,27 +47,27 @@ public class GeolatteFilterPredicate extends AbstractSimplePredicate implements
|
|||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerParameters(ParameterRegistry registry) {
|
||||
Helper.possibleParameter( geometry, registry );
|
||||
Helper.possibleParameter( filter, registry );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String render(boolean isNegated, RenderingContext renderingContext) {
|
||||
String geometryParameter = ( (Renderable) geometry ).render( renderingContext );
|
||||
String filterParameter = ( (Renderable) filter ).render( renderingContext );
|
||||
Dialect dialect = renderingContext.getDialect();
|
||||
if ( !( dialect instanceof SpatialDialect ) ) {
|
||||
throw new IllegalStateException( "Dialect must be spatially enabled dialect" );
|
||||
}
|
||||
if ( dialect instanceof WithCustomJPAFilter ) {
|
||||
return ( (WithCustomJPAFilter) dialect ).filterExpression( geometryParameter, filterParameter );
|
||||
}
|
||||
else {
|
||||
return SpatialFunction.filter.name() + "(" + geometryParameter + ", " + filterParameter + ") = true";
|
||||
}
|
||||
}
|
||||
// @Override
|
||||
// public void registerParameters(ParameterRegistry registry) {
|
||||
// Helper.possibleParameter( geometry, registry );
|
||||
// Helper.possibleParameter( filter, registry );
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String render(boolean isNegated, RenderingContext renderingContext) {
|
||||
// String geometryParameter = ( (Renderable) geometry ).render( renderingContext );
|
||||
// String filterParameter = ( (Renderable) filter ).render( renderingContext );
|
||||
// Dialect dialect = renderingContext.getDialect();
|
||||
// if ( !( dialect instanceof SpatialDialect ) ) {
|
||||
// throw new IllegalStateException( "Dialect must be spatially enabled dialect" );
|
||||
// }
|
||||
// if ( dialect instanceof WithCustomJPAFilter ) {
|
||||
// return ( (WithCustomJPAFilter) dialect ).filterExpression( geometryParameter, filterParameter );
|
||||
// }
|
||||
// else {
|
||||
// return SpatialFunction.filter.name() + "(" + geometryParameter + ", " + filterParameter + ") = true";
|
||||
// }
|
||||
// }
|
||||
|
||||
private static <P extends Position> Polygon<P> fromEnvelope(Envelope<P> envelope) {
|
||||
CoordinateReferenceSystem<P> crs = envelope.getCoordinateReferenceSystem();
|
||||
|
|
|
@ -368,44 +368,54 @@ public class GeolatteSpatialPredicates {
|
|||
public static Predicate filter(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry1,
|
||||
Expression<? extends Geometry> geometry2) {
|
||||
return new GeolatteFilterPredicate( criteriaBuilder, geometry1, geometry2 );
|
||||
return booleanExpressionToPredicate(
|
||||
criteriaBuilder,
|
||||
criteriaBuilder.function( SpatialFunction.filter.toString(), boolean.class,
|
||||
geometry1, geometry2
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a predicate for testing the arguments for bounding box overlap constraint.
|
||||
*
|
||||
* @param criteriaBuilder CriteriaBuilder
|
||||
* @param geometry1 geometry expression
|
||||
* @param geometry2 geometry value whose bounding box to use in the comparison
|
||||
*
|
||||
* @return bounding box overlap predicate
|
||||
*
|
||||
* @see GeolatteFilterPredicate
|
||||
* @see JTSSpatialPredicates#filter(CriteriaBuilder, Expression, org.locationtech.jts.geom.Geometry)
|
||||
*/
|
||||
public static Predicate filter(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry1,
|
||||
Geometry geometry2) {
|
||||
return new GeolatteFilterPredicate( criteriaBuilder, geometry1, geometry2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a predicate for testing the arguments for bounding box overlap constraint.
|
||||
*
|
||||
* @param criteriaBuilder CriteriaBuilder
|
||||
* @param geometry geometry expression
|
||||
* @param envelope envelope or bounding box to use in the comparison
|
||||
*
|
||||
* @return bounding box overlap predicate
|
||||
*
|
||||
* @see GeolatteFilterPredicate
|
||||
* @see JTSSpatialPredicates#filterByPolygon(CriteriaBuilder, Expression, org.locationtech.jts.geom.Envelope, int)
|
||||
*/
|
||||
public static Predicate filterByPolygon(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry,
|
||||
Envelope envelope) {
|
||||
return new GeolatteFilterPredicate( criteriaBuilder, geometry, envelope );
|
||||
}
|
||||
// /**
|
||||
// * Create a predicate for testing the arguments for bounding box overlap constraint.
|
||||
// *
|
||||
// * @param criteriaBuilder CriteriaBuilder
|
||||
// * @param geometry1 geometry expression
|
||||
// * @param geometry2 geometry value whose bounding box to use in the comparison
|
||||
// *
|
||||
// * @return bounding box overlap predicate
|
||||
// *
|
||||
// * @see GeolatteFilterPredicate
|
||||
// * @see JTSSpatialPredicates#filter(CriteriaBuilder, Expression, org.locationtech.jts.geom.Geometry)
|
||||
// */
|
||||
// public static Predicate filter(
|
||||
// CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry1,
|
||||
// Geometry geometry2) {
|
||||
// return booleanExpressionToPredicate(
|
||||
// criteriaBuilder,
|
||||
// criteriaBuilder.function( SpatialFunction.filter.toString(), Geometry.class,
|
||||
// geometry1, geometry2
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Create a predicate for testing the arguments for bounding box overlap constraint.
|
||||
// *
|
||||
// * @param criteriaBuilder CriteriaBuilder
|
||||
// * @param geometry geometry expression
|
||||
// * @param envelope envelope or bounding box to use in the comparison
|
||||
// *
|
||||
// * @return bounding box overlap predicate
|
||||
// *
|
||||
// * @see GeolatteFilterPredicate
|
||||
// * @see JTSSpatialPredicates#filterByPolygon(CriteriaBuilder, Expression, org.locationtech.jts.geom.Envelope, int)
|
||||
// */
|
||||
// public static Predicate filterByPolygon(
|
||||
// CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry,
|
||||
// Envelope envelope) {
|
||||
// return new GeolatteFilterPredicate( criteriaBuilder, geometry, envelope );
|
||||
// }
|
||||
|
||||
/**
|
||||
* Create a predicate for testing the arguments for "distance within" constraint.
|
||||
|
|
|
@ -6,75 +6,27 @@
|
|||
*/
|
||||
package org.hibernate.spatial.predicate;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.Expression;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.query.criteria.internal.CriteriaBuilderImpl;
|
||||
import org.hibernate.query.criteria.internal.ParameterRegistry;
|
||||
import org.hibernate.query.criteria.internal.Renderable;
|
||||
import org.hibernate.query.criteria.internal.compile.RenderingContext;
|
||||
import org.hibernate.query.criteria.internal.predicate.AbstractSimplePredicate;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.criterion.SpatialFilter;
|
||||
import org.hibernate.spatial.dialect.WithCustomJPAFilter;
|
||||
import org.hibernate.NotYetImplementedFor6Exception;
|
||||
import org.hibernate.query.sqm.NodeBuilder;
|
||||
import org.hibernate.query.sqm.SemanticQueryWalker;
|
||||
import org.hibernate.query.sqm.tree.predicate.AbstractNegatableSqmPredicate;
|
||||
import org.hibernate.spatial.jts.EnvelopeAdapter;
|
||||
|
||||
import org.locationtech.jts.geom.Envelope;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
|
||||
/**
|
||||
* JPA Criteria API {@link Predicate} equivalent of {@link SpatialFilter}.
|
||||
* JPA Spatial Filter {@link Predicate}
|
||||
*/
|
||||
public class JTSFilterPredicate extends AbstractSimplePredicate implements Serializable {
|
||||
class JTSFilterPredicate {
|
||||
|
||||
private final Expression<? extends Geometry> geometry;
|
||||
private final Expression<? extends Geometry> filter;
|
||||
private Expression<?> geometry;
|
||||
private Expression<?> filter;
|
||||
|
||||
public JTSFilterPredicate(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry,
|
||||
Expression<? extends Geometry> filter) {
|
||||
super( (CriteriaBuilderImpl) criteriaBuilder );
|
||||
this.geometry = geometry;
|
||||
this.filter = filter;
|
||||
}
|
||||
//require to completely re-implement
|
||||
|
||||
public JTSFilterPredicate(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry,
|
||||
Geometry filter) {
|
||||
this( criteriaBuilder, geometry, criteriaBuilder.literal( filter )
|
||||
);
|
||||
}
|
||||
|
||||
public JTSFilterPredicate(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry,
|
||||
Envelope envelope, int srid) {
|
||||
this( criteriaBuilder, geometry, EnvelopeAdapter.toPolygon( envelope, srid )
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerParameters(ParameterRegistry registry) {
|
||||
Helper.possibleParameter( geometry, registry );
|
||||
Helper.possibleParameter( filter, registry );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String render(boolean isNegated, RenderingContext renderingContext) {
|
||||
String geometryParameter = ( (Renderable) geometry ).render( renderingContext );
|
||||
String filterParameter = ( (Renderable) filter ).render( renderingContext );
|
||||
Dialect dialect = renderingContext.getDialect();
|
||||
if ( !( dialect instanceof SpatialDialect ) ) {
|
||||
throw new IllegalStateException( "Dialect must be spatially enabled dialect" );
|
||||
}
|
||||
if ( dialect instanceof WithCustomJPAFilter ) {
|
||||
return ( (WithCustomJPAFilter) dialect ).filterExpression( geometryParameter, filterParameter );
|
||||
}
|
||||
else {
|
||||
return SpatialFunction.filter.name() + "(" + geometryParameter + ", " + filterParameter + ") = true";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ import javax.persistence.criteria.CriteriaBuilder;
|
|||
import javax.persistence.criteria.Expression;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
|
||||
import org.hibernate.query.sqm.NodeBuilder;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
import org.hibernate.spatial.criterion.SpatialRestrictions;
|
||||
|
||||
import org.locationtech.jts.geom.Envelope;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
|
@ -20,7 +20,6 @@ import org.locationtech.jts.geom.Geometry;
|
|||
* A factory for spatial JPA Criteria API {@link Predicate}s.
|
||||
*
|
||||
* @author Daniel Shuy
|
||||
* @see SpatialRestrictions
|
||||
*/
|
||||
public class JTSSpatialPredicates {
|
||||
|
||||
|
@ -35,17 +34,13 @@ public class JTSSpatialPredicates {
|
|||
* @param geometry2 geometry expression
|
||||
*
|
||||
* @return "spatially equal" predicate
|
||||
*
|
||||
* @see SpatialRestrictions#eq(String, Geometry)
|
||||
*/
|
||||
public static Predicate eq(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry1,
|
||||
Expression<? extends Geometry> geometry2) {
|
||||
return booleanExpressionToPredicate(
|
||||
criteriaBuilder,
|
||||
criteriaBuilder.function( SpatialFunction.equals.toString(), boolean.class,
|
||||
geometry1, geometry2
|
||||
)
|
||||
criteriaBuilder.function( SpatialFunction.equals.toString(), boolean.class, geometry1, geometry2 )
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -63,9 +58,7 @@ public class JTSSpatialPredicates {
|
|||
public static Predicate eq(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry1,
|
||||
Geometry geometry2) {
|
||||
return eq( criteriaBuilder, geometry1,
|
||||
criteriaBuilder.literal( geometry2 )
|
||||
);
|
||||
return eq( criteriaBuilder, geometry1, criteriaBuilder.literal( geometry2 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,17 +69,13 @@ public class JTSSpatialPredicates {
|
|||
* @param geometry2 geometry expression
|
||||
*
|
||||
* @return "spatially within" predicate
|
||||
*
|
||||
* @see SpatialRestrictions#within(String, Geometry)
|
||||
*/
|
||||
public static Predicate within(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry1,
|
||||
Expression<? extends Geometry> geometry2) {
|
||||
return booleanExpressionToPredicate(
|
||||
criteriaBuilder,
|
||||
criteriaBuilder.function( SpatialFunction.within.toString(), boolean.class,
|
||||
geometry1, geometry2
|
||||
)
|
||||
criteriaBuilder.function( SpatialFunction.within.toString(), boolean.class, geometry1, geometry2 )
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -104,9 +93,7 @@ public class JTSSpatialPredicates {
|
|||
public static Predicate within(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry1,
|
||||
Geometry geometry2) {
|
||||
return within( criteriaBuilder, geometry1,
|
||||
criteriaBuilder.literal( geometry2 )
|
||||
);
|
||||
return within( criteriaBuilder, geometry1, criteriaBuilder.literal( geometry2 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,8 +104,6 @@ public class JTSSpatialPredicates {
|
|||
* @param geometry2 geometry expression
|
||||
*
|
||||
* @return "spatially contains" predicate
|
||||
*
|
||||
* @see SpatialRestrictions#contains(String, Geometry)
|
||||
*/
|
||||
public static Predicate contains(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry1,
|
||||
|
@ -158,8 +143,6 @@ public class JTSSpatialPredicates {
|
|||
* @param geometry2 geometry expression
|
||||
*
|
||||
* @return "spatially crosses" predicate
|
||||
*
|
||||
* @see SpatialRestrictions#crosses(String, Geometry)
|
||||
*/
|
||||
public static Predicate crosses(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry1,
|
||||
|
@ -199,8 +182,6 @@ public class JTSSpatialPredicates {
|
|||
* @param geometry2 geometry expression
|
||||
*
|
||||
* @return "spatially disjoint" predicate
|
||||
*
|
||||
* @see SpatialRestrictions#disjoint(String, Geometry)
|
||||
*/
|
||||
public static Predicate disjoint(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry1,
|
||||
|
@ -240,8 +221,6 @@ public class JTSSpatialPredicates {
|
|||
* @param geometry2 geometry expression
|
||||
*
|
||||
* @return "spatially intersects" predicate
|
||||
*
|
||||
* @see SpatialRestrictions#intersects(String, Geometry)
|
||||
*/
|
||||
public static Predicate intersects(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry1,
|
||||
|
@ -281,8 +260,6 @@ public class JTSSpatialPredicates {
|
|||
* @param geometry2 geometry expression
|
||||
*
|
||||
* @return "spatially overlaps" predicate
|
||||
*
|
||||
* @see SpatialRestrictions#overlaps(String, Geometry)
|
||||
*/
|
||||
public static Predicate overlaps(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry1,
|
||||
|
@ -322,8 +299,6 @@ public class JTSSpatialPredicates {
|
|||
* @param geometry2 geometry expression
|
||||
*
|
||||
* @return "spatially touches" predicate
|
||||
*
|
||||
* @see SpatialRestrictions#touches(String, Geometry)
|
||||
*/
|
||||
public static Predicate touches(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry1,
|
||||
|
@ -345,7 +320,7 @@ public class JTSSpatialPredicates {
|
|||
*
|
||||
* @return "spatially touches" predicate
|
||||
*
|
||||
* @see #touches(CriteriaBuilder, Expression, Expression)
|
||||
* @return "spatially touches" predicate
|
||||
*/
|
||||
public static Predicate touches(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry1,
|
||||
|
@ -355,60 +330,62 @@ public class JTSSpatialPredicates {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a predicate for testing the arguments for bounding box overlap constraint.
|
||||
*
|
||||
* @param criteriaBuilder CriteriaBuilder
|
||||
* @param geometry1 geometry expression
|
||||
* @param geometry2 geometry expression whose bounding box to use in the comparison
|
||||
*
|
||||
* @return bounding box overlap predicate
|
||||
*
|
||||
* @see JTSFilterPredicate
|
||||
* @see SpatialRestrictions#filter(String, Geometry)
|
||||
*/
|
||||
public static Predicate filter(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry1,
|
||||
Expression<? extends Geometry> geometry2) {
|
||||
return new JTSFilterPredicate( criteriaBuilder, geometry1, geometry2 );
|
||||
}
|
||||
// /**
|
||||
// * Create a predicate for testing the arguments for bounding box overlap constraint.
|
||||
// *
|
||||
// * @param nodeBuilder NodeBuilder
|
||||
// * @param geometry1 geometry expression
|
||||
// * @param geometry2 geometry expression whose bounding box to use in the comparison
|
||||
// *
|
||||
// * @return bounding box overlap predicate
|
||||
// *
|
||||
// * @see JTSFilterPredicate
|
||||
// */
|
||||
// public static Predicate filter(
|
||||
// NodeBuilder nodeBuilder, Expression<? extends Geometry> geometry1,
|
||||
// Expression<? extends Geometry> geometry2) {
|
||||
// return booleanExpressionToPredicate(
|
||||
// nodeBuilder,
|
||||
// nodeBuilder.function( SpatialFunction.filter.toString(), boolean.class,
|
||||
// geometry1, geometry2
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
|
||||
/**
|
||||
* Create a predicate for testing the arguments for bounding box overlap constraint.
|
||||
*
|
||||
* @param criteriaBuilder CriteriaBuilder
|
||||
* @param geometry1 geometry expression
|
||||
* @param geometry2 geometry value whose bounding box to use in the comparison
|
||||
*
|
||||
* @return bounding box overlap predicate
|
||||
*
|
||||
* @see JTSFilterPredicate
|
||||
* @see SpatialRestrictions#filter(String, Geometry)
|
||||
*/
|
||||
public static Predicate filter(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry1,
|
||||
Geometry geometry2) {
|
||||
return new JTSFilterPredicate( criteriaBuilder, geometry1, geometry2 );
|
||||
}
|
||||
// /**
|
||||
// * Create a predicate for testing the arguments for bounding box overlap constraint.
|
||||
// *
|
||||
// * @param nodeBuilder NodeBuilder
|
||||
// * @param geometry1 geometry expression
|
||||
// * @param geometry2 geometry value whose bounding box to use in the comparison
|
||||
// *
|
||||
// * @return bounding box overlap predicate
|
||||
// *
|
||||
// * @see JTSFilterPredicate*
|
||||
// */
|
||||
// public static Predicate filter(
|
||||
// NodeBuilder nodeBuilder, Expression<? extends Geometry> geometry1,
|
||||
// Geometry geometry2) {
|
||||
// return new JTSFilterPredicate( nodeBuilder, geometry1, geometry2 );
|
||||
// }
|
||||
|
||||
/**
|
||||
* Create a predicate for testing the arguments for bounding box overlap constraint.
|
||||
*
|
||||
* @param criteriaBuilder CriteriaBuilder
|
||||
* @param geometry geometry expression
|
||||
* @param envelope envelope or bounding box to use in the comparison
|
||||
* @param srid the SRID of the bounding box
|
||||
*
|
||||
* @return bounding box overlap predicate
|
||||
*
|
||||
* @see JTSFilterPredicate
|
||||
* @see SpatialRestrictions#filter(String, Envelope, int)
|
||||
*/
|
||||
public static Predicate filterByPolygon(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry,
|
||||
Envelope envelope, int srid) {
|
||||
return new JTSFilterPredicate( criteriaBuilder, geometry, envelope, srid );
|
||||
}
|
||||
// /**
|
||||
// * Create a predicate for testing the arguments for bounding box overlap constraint.
|
||||
// *
|
||||
// * @param nodeBuilder CriteriaBuilder
|
||||
// * @param geometry geometry expression
|
||||
// * @param envelope envelope or bounding box to use in the comparison
|
||||
// * @param srid the SRID of the bounding box
|
||||
// *
|
||||
// * @return bounding box overlap predicate
|
||||
// *
|
||||
// * @see JTSFilterPredicate
|
||||
// */
|
||||
// public static Predicate filterByPolygon(
|
||||
// NodeBuilder nodeBuilder, Expression<? extends Geometry> geometry,
|
||||
// Envelope envelope, int srid) {
|
||||
// return new JTSFilterPredicate( nodeBuilder, geometry, envelope, srid );
|
||||
// }
|
||||
|
||||
/**
|
||||
* Create a predicate for testing the arguments for "distance within" constraint.
|
||||
|
@ -419,8 +396,6 @@ public class JTSSpatialPredicates {
|
|||
* @param distance distance expression
|
||||
*
|
||||
* @return "distance within" predicate
|
||||
*
|
||||
* @see SpatialRestrictions#distanceWithin(String, Geometry, double)
|
||||
*/
|
||||
public static Predicate distanceWithin(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry1,
|
||||
|
@ -501,8 +476,6 @@ public class JTSSpatialPredicates {
|
|||
* @param srid SRID expression
|
||||
*
|
||||
* @return "having srid" predicate
|
||||
*
|
||||
* @see SpatialRestrictions#havingSRID(String, int)
|
||||
*/
|
||||
public static Predicate havingSRID(
|
||||
CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry,
|
||||
|
@ -539,8 +512,6 @@ public class JTSSpatialPredicates {
|
|||
* @param geometry geometry expression
|
||||
*
|
||||
* @return "is empty" predicate
|
||||
*
|
||||
* @see SpatialRestrictions#isEmpty(String)
|
||||
*/
|
||||
public static Predicate isEmpty(CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry) {
|
||||
return booleanExpressionToPredicate(
|
||||
|
@ -558,8 +529,6 @@ public class JTSSpatialPredicates {
|
|||
* @param geometry geometry expression
|
||||
*
|
||||
* @return "is not empty" predicate
|
||||
*
|
||||
* @see SpatialRestrictions#isNotEmpty(String)
|
||||
*/
|
||||
public static Predicate isNotEmpty(CriteriaBuilder criteriaBuilder, Expression<? extends Geometry> geometry) {
|
||||
return isEmpty( criteriaBuilder, geometry )
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.spatial.predicate;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link JTSSpatialPredicates} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public class SpatialPredicates extends JTSSpatialPredicates {
|
||||
|
||||
protected SpatialPredicates() {
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.spatial.dialect.postgis;
|
||||
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
import org.hibernate.spatial.SpatialFunction;
|
||||
|
||||
import org.junit.Test;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests support for
|
||||
*
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
* creation-date: 1/19/11
|
||||
*/
|
||||
public class PostgisDialectTest extends TestCase {
|
||||
|
||||
SpatialDialect dialect = new PostgisDialect();
|
||||
|
||||
@Test
|
||||
public void testSupports() throws Exception {
|
||||
for ( SpatialFunction sf : SpatialFunction.values() ) {
|
||||
assertTrue( "Dialect doesn't support " + sf, dialect.supports( sf ) );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,10 +14,12 @@ import java.util.Map;
|
|||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.query.Query;
|
||||
import org.hibernate.query.criteria.JpaCriteriaQuery;
|
||||
import org.hibernate.spatial.integration.geolatte.GeomEntity;
|
||||
import org.hibernate.spatial.testing.GeometryEquality;
|
||||
import org.hibernate.spatial.testing.SpatialFunctionalTestCase;
|
||||
import org.hibernate.spatial.testing.TestDataElement;
|
||||
import org.hibernate.spatial.testing.datareader.TestDataElement;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -168,8 +170,9 @@ public abstract class AbstractTestStoreRetrieve<G, E extends GeomEntityLike<G>>
|
|||
try {
|
||||
session = openSession();
|
||||
tx = session.beginTransaction();
|
||||
Criteria criteria = session.createCriteria( GeomEntity.class );
|
||||
List<GeomEntity> retrieved = criteria.list();
|
||||
JpaCriteriaQuery<GeomEntity> criteria = session.getCriteriaBuilder().createQuery( GeomEntity.class );
|
||||
Query<GeomEntity> query = session.createQuery( criteria );
|
||||
List<GeomEntity> retrieved = query.list();
|
||||
assertEquals( "Expected exactly one result", 1, retrieved.size() );
|
||||
GeomEntity entity = retrieved.get( 0 );
|
||||
assertNull( entity.getGeom() );
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue