org.hibernate.spatial.dialect.postgis.PostgisPG92Dialect Maven / Gradle / Ivy
Show all versions of hibernate-spatial Show documentation
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.spatial.dialect.postgis;
import java.util.Map;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.dialect.PostgreSQL92Dialect;
import org.hibernate.dialect.function.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 .
*
* 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 entry : support.functionsToRegister() ) {
registerFunction( entry.getKey(), entry.getValue() );
}
}
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes(
typeContributions,
serviceRegistry
);
support.contributeTypes( typeContributions, serviceRegistry );
}
/**
* Returns the SQL fragment for the SQL WHERE-clause when parsing
* org.hibernatespatial.criterion.SpatialRelateExpression
s
* into prepared statements.
*
*
* @param columnName The name of the geometry-typed column to which the relation is
* applied
* @param spatialRelation The type of spatial relation (as defined in
* SpatialRelation
).
*
* @return SQL fragment {@code SpatialRelateExpression}
*/
@Override
public String getSpatialRelateSQL(String columnName, int spatialRelation) {
return support.getSpatialRelateSQL( columnName, spatialRelation );
}
/**
* Returns the SQL fragment for the SQL WHERE-expression when parsing
* org.hibernate.spatial.criterion.SpatialFilterExpression
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 SpatialAggregate
*
* @return The SQL fragment for the projection
*/
@Override
public String getSpatialAggregateSQL(String columnName, int aggregation) {
return support.getSpatialAggregateSQL( columnName, aggregation );
}
/**
* Returns The SQL fragment when parsing a DWithinExpression
.
*
* @param columnName The geometry column to test against
*
* @return The SQL fragment when parsing a DWithinExpression
.
*/
@Override
public String getDWithinSQL(String columnName) {
return support.getDWithinSQL( columnName );
}
/**
* Returns the SQL fragment when parsing a HavingSridExpression
.
*
* @param columnName The geometry column to test against
*
* @return The SQL fragment for a HavingSridExpression
.
*/
@Override
public String getHavingSridSQL(String columnName) {
return support.getHavingSridSQL( columnName );
}
/**
* Returns the SQL fragment when parsing a IsEmptyExpression
or
* IsNotEmpty
expression.
*
* @param columnName The geometry column
* @param isEmpty Whether the geometry is tested for empty or non-empty
*
* @return The SQL fragment for the isempty function
*/
@Override
public String getIsEmptySQL(String columnName, boolean isEmpty) {
return support.getIsEmptySQL( columnName, isEmpty );
}
/**
* Returns true if this SpatialDialect
supports a specific filtering function.
* This is intended to signal DB-support for fast window queries, or MBR-overlap queries.
*
* @return True if filtering is supported
*/
@Override
public boolean supportsFiltering() {
return support.supportsFiltering();
}
/**
* Does this dialect supports the specified SpatialFunction
.
*
* @param function SpatialFunction
*
* @return True if this SpatialDialect
supports the spatial function specified by the function parameter.
*/
@Override
public boolean supports(SpatialFunction function) {
return support.supports( function );
}
}