Revert "HHH-11198 - Add Geometry cast to Postgis st_extent() function"
This reverts commit af301bc9ba
.
This commit is contained in:
parent
23688a7703
commit
19ae3a8220
|
@ -159,19 +159,9 @@ public enum SpatialFunction {
|
||||||
* <p>The semantics are those of the Postgis function ST_Transform(geometry, srid) : geometry. It returns new geometry
|
* <p>The semantics are those of the Postgis function ST_Transform(geometry, srid) : geometry. It returns new geometry
|
||||||
* with its coordinates transformed to the spatial reference system referenced by the srid parameter.
|
* with its coordinates transformed to the spatial reference system referenced by the srid parameter.
|
||||||
*/
|
*/
|
||||||
transform( "common" ),
|
transform( "common" );
|
||||||
|
|
||||||
/**
|
|
||||||
* the extents function
|
|
||||||
*/
|
|
||||||
extent( "common" );
|
|
||||||
|
|
||||||
|
|
||||||
private final String description;
|
private final String description;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SpatialFunction(String specification) {
|
SpatialFunction(String specification) {
|
||||||
this.description = specification;
|
this.description = specification;
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,6 @@ public class MySQLSpatialDialect extends MySQLDialect implements SpatialDialect
|
||||||
case geomunion:
|
case geomunion:
|
||||||
case dwithin:
|
case dwithin:
|
||||||
case transform:
|
case transform:
|
||||||
case extent:
|
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -7,12 +7,10 @@
|
||||||
package org.hibernate.spatial.dialect.postgis;
|
package org.hibernate.spatial.dialect.postgis;
|
||||||
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.hibernate.boot.model.TypeContributions;
|
import org.hibernate.boot.model.TypeContributions;
|
||||||
import org.hibernate.dialect.PostgreSQL82Dialect;
|
import org.hibernate.dialect.PostgreSQL82Dialect;
|
||||||
import org.hibernate.dialect.function.StandardSQLFunction;
|
import org.hibernate.dialect.function.StandardSQLFunction;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.spatial.GeolatteGeometryType;
|
import org.hibernate.spatial.GeolatteGeometryType;
|
||||||
import org.hibernate.spatial.JTSGeometryType;
|
import org.hibernate.spatial.JTSGeometryType;
|
||||||
|
@ -21,7 +19,6 @@ import org.hibernate.spatial.SpatialDialect;
|
||||||
import org.hibernate.spatial.SpatialFunction;
|
import org.hibernate.spatial.SpatialFunction;
|
||||||
import org.hibernate.spatial.SpatialRelation;
|
import org.hibernate.spatial.SpatialRelation;
|
||||||
import org.hibernate.type.StandardBasicTypes;
|
import org.hibernate.type.StandardBasicTypes;
|
||||||
import org.hibernate.type.Type;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Dialect for Postgresql with support for the Postgis spatial types, functions and operators (release 1.3 or higher)
|
* A Dialect for Postgresql with support for the Postgis spatial types, functions and operators (release 1.3 or higher)
|
||||||
|
@ -66,138 +63,138 @@ public class PostgisDialect extends PostgreSQL82Dialect implements SpatialDialec
|
||||||
// it occurs in the spatial dialect
|
// it occurs in the spatial dialect
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"dimension", new StandardSQLFunction(
|
"dimension", new StandardSQLFunction(
|
||||||
"st_dimension",
|
"st_dimension",
|
||||||
StandardBasicTypes.INTEGER
|
StandardBasicTypes.INTEGER
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"geometrytype", new StandardSQLFunction(
|
"geometrytype", new StandardSQLFunction(
|
||||||
"st_geometrytype", StandardBasicTypes.STRING
|
"st_geometrytype", StandardBasicTypes.STRING
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"srid", new StandardSQLFunction(
|
"srid", new StandardSQLFunction(
|
||||||
"st_srid",
|
"st_srid",
|
||||||
StandardBasicTypes.INTEGER
|
StandardBasicTypes.INTEGER
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"envelope", new StandardSQLFunction(
|
"envelope", new StandardSQLFunction(
|
||||||
"st_envelope"
|
"st_envelope"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"astext", new StandardSQLFunction(
|
"astext", new StandardSQLFunction(
|
||||||
"st_astext",
|
"st_astext",
|
||||||
StandardBasicTypes.STRING
|
StandardBasicTypes.STRING
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"asbinary", new StandardSQLFunction(
|
"asbinary", new StandardSQLFunction(
|
||||||
"st_asbinary",
|
"st_asbinary",
|
||||||
StandardBasicTypes.BINARY
|
StandardBasicTypes.BINARY
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"isempty", new StandardSQLFunction(
|
"isempty", new StandardSQLFunction(
|
||||||
"st_isempty",
|
"st_isempty",
|
||||||
StandardBasicTypes.BOOLEAN
|
StandardBasicTypes.BOOLEAN
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"issimple", new StandardSQLFunction(
|
"issimple", new StandardSQLFunction(
|
||||||
"st_issimple",
|
"st_issimple",
|
||||||
StandardBasicTypes.BOOLEAN
|
StandardBasicTypes.BOOLEAN
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"boundary", new StandardSQLFunction(
|
"boundary", new StandardSQLFunction(
|
||||||
"st_boundary"
|
"st_boundary"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Register functions for spatial relation constructs
|
// Register functions for spatial relation constructs
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"overlaps", new StandardSQLFunction(
|
"overlaps", new StandardSQLFunction(
|
||||||
"st_overlaps",
|
"st_overlaps",
|
||||||
StandardBasicTypes.BOOLEAN
|
StandardBasicTypes.BOOLEAN
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"intersects", new StandardSQLFunction(
|
"intersects", new StandardSQLFunction(
|
||||||
"st_intersects",
|
"st_intersects",
|
||||||
StandardBasicTypes.BOOLEAN
|
StandardBasicTypes.BOOLEAN
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"equals", new StandardSQLFunction(
|
"equals", new StandardSQLFunction(
|
||||||
"st_equals",
|
"st_equals",
|
||||||
StandardBasicTypes.BOOLEAN
|
StandardBasicTypes.BOOLEAN
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"contains", new StandardSQLFunction(
|
"contains", new StandardSQLFunction(
|
||||||
"st_contains",
|
"st_contains",
|
||||||
StandardBasicTypes.BOOLEAN
|
StandardBasicTypes.BOOLEAN
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"crosses", new StandardSQLFunction(
|
"crosses", new StandardSQLFunction(
|
||||||
"st_crosses",
|
"st_crosses",
|
||||||
StandardBasicTypes.BOOLEAN
|
StandardBasicTypes.BOOLEAN
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"disjoint", new StandardSQLFunction(
|
"disjoint", new StandardSQLFunction(
|
||||||
"st_disjoint",
|
"st_disjoint",
|
||||||
StandardBasicTypes.BOOLEAN
|
StandardBasicTypes.BOOLEAN
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"touches", new StandardSQLFunction(
|
"touches", new StandardSQLFunction(
|
||||||
"st_touches",
|
"st_touches",
|
||||||
StandardBasicTypes.BOOLEAN
|
StandardBasicTypes.BOOLEAN
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"within", new StandardSQLFunction(
|
"within", new StandardSQLFunction(
|
||||||
"st_within",
|
"st_within",
|
||||||
StandardBasicTypes.BOOLEAN
|
StandardBasicTypes.BOOLEAN
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"relate", new StandardSQLFunction(
|
"relate", new StandardSQLFunction(
|
||||||
"st_relate",
|
"st_relate",
|
||||||
StandardBasicTypes.BOOLEAN
|
StandardBasicTypes.BOOLEAN
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// register the spatial analysis functions
|
// register the spatial analysis functions
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"distance", new StandardSQLFunction(
|
"distance", new StandardSQLFunction(
|
||||||
"st_distance",
|
"st_distance",
|
||||||
StandardBasicTypes.DOUBLE
|
StandardBasicTypes.DOUBLE
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"buffer", new StandardSQLFunction(
|
"buffer", new StandardSQLFunction(
|
||||||
"st_buffer"
|
"st_buffer"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"convexhull", new StandardSQLFunction(
|
"convexhull", new StandardSQLFunction(
|
||||||
"st_convexhull"
|
"st_convexhull"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"difference", new StandardSQLFunction(
|
"difference", new StandardSQLFunction(
|
||||||
"st_difference"
|
"st_difference"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"intersection", new StandardSQLFunction(
|
"intersection", new StandardSQLFunction(
|
||||||
"st_intersection"
|
"st_intersection"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"symdifference",
|
"symdifference",
|
||||||
|
@ -205,26 +202,28 @@ public class PostgisDialect extends PostgreSQL82Dialect implements SpatialDialec
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"geomunion", new StandardSQLFunction(
|
"geomunion", new StandardSQLFunction(
|
||||||
"st_union"
|
"st_union"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
//register Spatial Aggregate function
|
//register Spatial Aggregate function
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"extent", new ExtentFunction()
|
"extent", new StandardSQLFunction(
|
||||||
|
"extent"
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
//other common functions
|
//other common functions
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"dwithin", new StandardSQLFunction(
|
"dwithin", new StandardSQLFunction(
|
||||||
"st_dwithin",
|
"st_dwithin",
|
||||||
StandardBasicTypes.BOOLEAN
|
StandardBasicTypes.BOOLEAN
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
registerFunction(
|
registerFunction(
|
||||||
"transform", new StandardSQLFunction(
|
"transform", new StandardSQLFunction(
|
||||||
"st_transform"
|
"st_transform"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +281,7 @@ public class PostgisDialect extends PostgreSQL82Dialect implements SpatialDialec
|
||||||
switch ( aggregation ) {
|
switch ( aggregation ) {
|
||||||
case SpatialAggregate.EXTENT:
|
case SpatialAggregate.EXTENT:
|
||||||
final StringBuilder stbuf = new StringBuilder();
|
final StringBuilder stbuf = new StringBuilder();
|
||||||
stbuf.append( "st_extent(" ).append( columnName ).append( ")::geometry" );
|
stbuf.append( "extent(" ).append( columnName ).append( ")" );
|
||||||
return stbuf.toString();
|
return stbuf.toString();
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
@ -299,21 +298,6 @@ public class PostgisDialect extends PostgreSQL82Dialect implements SpatialDialec
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(SpatialFunction function) {
|
public boolean supports(SpatialFunction function) {
|
||||||
return (getFunctions().get( function.toString() ) != null);
|
return ( getFunctions().get( function.toString() ) != null );
|
||||||
}
|
|
||||||
|
|
||||||
private static class ExtentFunction extends StandardSQLFunction {
|
|
||||||
|
|
||||||
public ExtentFunction() {
|
|
||||||
super( "st_extent" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String render(
|
|
||||||
Type firstArgumentType, List arguments, SessionFactoryImplementor sessionFactory) {
|
|
||||||
String rendered = super.render( firstArgumentType, arguments, sessionFactory );
|
|
||||||
//add cast
|
|
||||||
return rendered + "::geometry";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ public class PostgisUnmarshalTest {
|
||||||
|
|
||||||
public void testCase(String pgValue, Geometry<?> expected) throws SQLException {
|
public void testCase(String pgValue, Geometry<?> expected) throws SQLException {
|
||||||
PGobject pgo = new PGobject();
|
PGobject pgo = new PGobject();
|
||||||
|
System.out.println( "pgValue " + pgValue );
|
||||||
pgo.setValue( pgValue );
|
pgo.setValue( pgValue );
|
||||||
Geometry<?> received = PGGeometryTypeDescriptor.toGeometry( pgo );
|
Geometry<?> received = PGGeometryTypeDescriptor.toGeometry( pgo );
|
||||||
assertEquals( String.format( "Failure on %s", pgValue ), expected, received );
|
assertEquals( String.format( "Failure on %s", pgValue ), expected, received );
|
||||||
|
|
|
@ -676,28 +676,6 @@ public class TestSpatialFunctions extends SpatialFunctionalTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test_extent_on_jts() throws SQLException {
|
|
||||||
extent( JTS );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test_extent_on_geolatte() throws SQLException {
|
|
||||||
extent( GEOLATTE );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void extent(String pckg) throws SQLException {
|
|
||||||
if ( !isSupportedByDialect( SpatialFunction.extent ) ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// here we just check if we get a result, and can read it
|
|
||||||
String hql = format(
|
|
||||||
"SELECT id, extent(geom) from org.hibernate.spatial.integration.%s.GeomEntity group by id", pckg
|
|
||||||
);
|
|
||||||
Map<Integer, Object> hsreceived = new HashMap<Integer, Object>();
|
|
||||||
doInSession( hql, hsreceived, new HashMap<String, Object>() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> void retrieveHQLResultsAndCompare(Map<Integer, T> dbexpected, String hql, String geometryType) {
|
public <T> void retrieveHQLResultsAndCompare(Map<Integer, T> dbexpected, String hql, String geometryType) {
|
||||||
retrieveHQLResultsAndCompare( dbexpected, hql, null, geometryType );
|
retrieveHQLResultsAndCompare( dbexpected, hql, null, geometryType );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue