HHH-14804 Various improvements
This commit is contained in:
parent
022d2c0a13
commit
54967d0265
|
@ -20,9 +20,9 @@ import org.geolatte.geom.jts.JTS;
|
|||
|
||||
public class GeometryLiteralFormatter<T> implements JdbcLiteralFormatter<T> {
|
||||
|
||||
private final JavaType<T> javaType;
|
||||
private final Wkt.Dialect wktDialect;
|
||||
private final String geomFromTextName;
|
||||
protected final JavaType<T> javaType;
|
||||
protected final Wkt.Dialect wktDialect;
|
||||
protected final String geomFromTextName;
|
||||
|
||||
public GeometryLiteralFormatter(JavaType<T> javaType, Wkt.Dialect wktDialect, String geomFromTextName) {
|
||||
this.javaType = javaType;
|
||||
|
@ -33,21 +33,15 @@ public class GeometryLiteralFormatter<T> implements JdbcLiteralFormatter<T> {
|
|||
@Override
|
||||
public void appendJdbcLiteral(
|
||||
SqlAppender appender, T value, Dialect dialect, WrapperOptions wrapperOptions) {
|
||||
Geometry<?> geom;
|
||||
if ( javaType instanceof GeolatteGeometryJavaTypeDescriptor ) {
|
||||
geom = (Geometry<?>) value;
|
||||
}
|
||||
else {
|
||||
geom = jts2Gl( value );
|
||||
}
|
||||
appender.appendSql( "ST_GeomFromText('" );
|
||||
appender.appendSql( Wkt.toWkt( geom, Wkt.Dialect.SFA_1_1_0 ) );
|
||||
Geometry<?> geom = javaType.unwrap( value, Geometry.class, wrapperOptions );
|
||||
appender.appendSql( geomFromTextName );
|
||||
appender.appendSql( Wkt.toWkt( geom, wktDialect ) );
|
||||
appender.appendSql( "'," );
|
||||
appender.appendSql( ( Math.max( geom.getSRID(), 0 ) ) );
|
||||
appender.appendSql( ")" );
|
||||
}
|
||||
|
||||
private <T> Geometry<?> jts2Gl(T value) {
|
||||
private Geometry<?> jts2Gl(T value) {
|
||||
return JTS.from( (org.locationtech.jts.geom.Geometry) value );
|
||||
}
|
||||
|
||||
|
|
|
@ -16,11 +16,9 @@ import org.hibernate.spatial.GeolatteGeometryType;
|
|||
import org.hibernate.spatial.HSMessageLogger;
|
||||
import org.hibernate.spatial.JTSGeometryType;
|
||||
import org.hibernate.spatial.contributor.ContributorImplementor;
|
||||
import org.hibernate.spatial.dialect.postgis.PGGeometryType;
|
||||
import org.hibernate.spatial.dialect.postgis.PGGeometryJdbcType;
|
||||
import org.hibernate.spatial.dialect.postgis.PostgisSqmFunctionDescriptors;
|
||||
|
||||
import org.geolatte.geom.codec.Wkt;
|
||||
|
||||
public class CockroachDbContributor implements ContributorImplementor {
|
||||
|
||||
private final ServiceRegistry serviceRegistry;
|
||||
|
@ -32,8 +30,8 @@ public class CockroachDbContributor implements ContributorImplementor {
|
|||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions) {
|
||||
HSMessageLogger.LOGGER.typeContributions( this.getClass().getCanonicalName() );
|
||||
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryType.INSTANCE_WKB_2 ) );
|
||||
typeContributions.contributeType( new JTSGeometryType( PGGeometryType.INSTANCE_WKB_2 ) );
|
||||
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryJdbcType.INSTANCE_WKB_2 ) );
|
||||
typeContributions.contributeType( new JTSGeometryType( PGGeometryJdbcType.INSTANCE_WKB_2 ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,6 +10,9 @@ package org.hibernate.spatial.dialect.mariadb;
|
|||
import org.hibernate.dialect.MariaDB103Dialect;
|
||||
import org.hibernate.spatial.SpatialDialect;
|
||||
|
||||
/**
|
||||
* @deprecated Spatial Dialects are no longer needed. Use the standard MariaDB dialects
|
||||
*/
|
||||
@Deprecated
|
||||
public class MariaDB103SpatialDialect extends MariaDB103Dialect implements SpatialDialect {
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ public class MariaDBDialectContributor implements ContributorImplementor {
|
|||
|
||||
public void contributeTypes(TypeContributions typeContributions) {
|
||||
HSMessageLogger.LOGGER.typeContributions( this.getClass().getCanonicalName() );
|
||||
typeContributions.contributeType( new GeolatteGeometryType( MariaDBGeometryType.INSTANCE ) );
|
||||
typeContributions.contributeType( new JTSGeometryType( MariaDBGeometryType.INSTANCE ) );
|
||||
typeContributions.contributeType( new GeolatteGeometryType( MariaDBGeometryJdbcType.INSTANCE ) );
|
||||
typeContributions.contributeType( new JTSGeometryType( MariaDBGeometryJdbcType.INSTANCE ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,9 +32,9 @@ import org.geolatte.geom.codec.WkbDecoder;
|
|||
import org.geolatte.geom.codec.WkbEncoder;
|
||||
import org.geolatte.geom.codec.Wkt;
|
||||
|
||||
public class MariaDBGeometryType implements JdbcType {
|
||||
public class MariaDBGeometryJdbcType implements JdbcType {
|
||||
|
||||
public static final MariaDBGeometryType INSTANCE = new MariaDBGeometryType();
|
||||
public static final MariaDBGeometryJdbcType INSTANCE = new MariaDBGeometryJdbcType();
|
||||
final WkbEncoder encoder = Wkb.newEncoder( Wkb.Dialect.MYSQL_WKB );
|
||||
final WkbDecoder decoder = Wkb.newDecoder( Wkb.Dialect.MYSQL_WKB );
|
||||
|
|
@ -28,8 +28,8 @@ public class MySQLDialectContributor implements ContributorImplementor {
|
|||
@Override
|
||||
public void contributeTypes(TypeContributions typeContributions) {
|
||||
HSMessageLogger.LOGGER.typeContributions( this.getClass().getCanonicalName() );
|
||||
typeContributions.contributeType( new GeolatteGeometryType( MySQLGeometryType.INSTANCE ) );
|
||||
typeContributions.contributeType( new JTSGeometryType( MySQLGeometryType.INSTANCE ) );
|
||||
typeContributions.contributeType( new GeolatteGeometryType( MySQLGeometryJdbcType.INSTANCE ) );
|
||||
typeContributions.contributeType( new JTSGeometryType( MySQLGeometryJdbcType.INSTANCE ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,12 +37,12 @@ import org.geolatte.geom.codec.Wkt;
|
|||
*
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
*/
|
||||
public class MySQLGeometryType implements JdbcType {
|
||||
public class MySQLGeometryJdbcType implements JdbcType {
|
||||
|
||||
/**
|
||||
* An instance of this Descriptor
|
||||
*/
|
||||
public static final MySQLGeometryType INSTANCE = new MySQLGeometryType();
|
||||
public static final MySQLGeometryJdbcType INSTANCE = new MySQLGeometryJdbcType();
|
||||
|
||||
@Override
|
||||
public int getJdbcTypeCode() {
|
|
@ -9,7 +9,9 @@ package org.hibernate.spatial.dialect.mysql;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.boot.model.FunctionContributions;
|
||||
import org.hibernate.spatial.BaseSqmFunctionDescriptors;
|
||||
|
@ -17,12 +19,8 @@ import org.hibernate.spatial.CommonSpatialFunction;
|
|||
|
||||
public class MySqlSqmFunctionDescriptors extends BaseSqmFunctionDescriptors {
|
||||
|
||||
final static private List<CommonSpatialFunction> unsupported = new ArrayList<>();
|
||||
|
||||
static {
|
||||
unsupported.add( CommonSpatialFunction.ST_BOUNDARY );
|
||||
unsupported.add( CommonSpatialFunction.ST_RELATE );
|
||||
}
|
||||
private static final Set<CommonSpatialFunction> UNSUPPORTED = EnumSet.of(
|
||||
CommonSpatialFunction.ST_BOUNDARY, CommonSpatialFunction.ST_RELATE );
|
||||
|
||||
public MySqlSqmFunctionDescriptors(FunctionContributions functionContributions) {
|
||||
super( functionContributions );
|
||||
|
@ -31,7 +29,7 @@ public class MySqlSqmFunctionDescriptors extends BaseSqmFunctionDescriptors {
|
|||
@Override
|
||||
public CommonSpatialFunction[] filter(CommonSpatialFunction[] functions) {
|
||||
return Arrays.stream( functions )
|
||||
.filter( f -> !unsupported.contains( f ) )
|
||||
.filter( f -> !UNSUPPORTED.contains( f ) )
|
||||
.toArray( CommonSpatialFunction[]::new );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,9 @@ import java.sql.ResultSet;
|
|||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import org.hibernate.spatial.GeolatteGeometryJavaTypeDescriptor;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.spatial.GeometryLiteralFormatter;
|
||||
import org.hibernate.sql.ast.spi.SqlAppender;
|
||||
import org.hibernate.type.SqlTypes;
|
||||
import org.hibernate.type.descriptor.ValueBinder;
|
||||
import org.hibernate.type.descriptor.ValueExtractor;
|
||||
|
@ -33,7 +34,6 @@ import org.geolatte.geom.codec.WkbDecoder;
|
|||
import org.geolatte.geom.codec.WkbEncoder;
|
||||
import org.geolatte.geom.codec.Wkt;
|
||||
import org.geolatte.geom.codec.WktDecoder;
|
||||
import org.geolatte.geom.jts.JTS;
|
||||
import org.postgresql.util.PGobject;
|
||||
|
||||
/**
|
||||
|
@ -41,22 +41,22 @@ import org.postgresql.util.PGobject;
|
|||
*
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
*/
|
||||
public class PGGeometryType implements JdbcType {
|
||||
public class PGGeometryJdbcType implements JdbcType {
|
||||
|
||||
|
||||
private final Wkb.Dialect wkbDialect;
|
||||
|
||||
// Type descriptor instance using EWKB v1 (postgis versions < 2.2.2)
|
||||
public static final PGGeometryType INSTANCE_WKB_1 = new PGGeometryType( Wkb.Dialect.POSTGIS_EWKB_1 );
|
||||
public static final PGGeometryJdbcType INSTANCE_WKB_1 = new PGGeometryJdbcType( Wkb.Dialect.POSTGIS_EWKB_1 );
|
||||
// Type descriptor instance using EWKB v2 (postgis versions >= 2.2.2, see: https://trac.osgeo.org/postgis/ticket/3181)
|
||||
public static final PGGeometryType INSTANCE_WKB_2 = new PGGeometryType( Wkb.Dialect.POSTGIS_EWKB_2 );
|
||||
public static final PGGeometryJdbcType INSTANCE_WKB_2 = new PGGeometryJdbcType( Wkb.Dialect.POSTGIS_EWKB_2 );
|
||||
|
||||
@Override
|
||||
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaType<T> javaTypeDescriptor) {
|
||||
return new GeometryLiteralFormatter<T>( javaTypeDescriptor, Wkt.Dialect.SFA_1_1_0, "ST_GeomFromText" );
|
||||
return new PGGeometryLiteralFormatter<>( javaTypeDescriptor );
|
||||
}
|
||||
|
||||
private PGGeometryType(Wkb.Dialect dialect) {
|
||||
private PGGeometryJdbcType(Wkb.Dialect dialect) {
|
||||
wkbDialect = dialect;
|
||||
}
|
||||
|
||||
|
@ -64,10 +64,12 @@ public class PGGeometryType implements JdbcType {
|
|||
if ( object == null ) {
|
||||
return null;
|
||||
}
|
||||
ByteBuffer buffer = null;
|
||||
ByteBuffer buffer;
|
||||
if ( object instanceof PGobject ) {
|
||||
String pgValue = ( (PGobject) object ).getValue();
|
||||
|
||||
if (pgValue == null) {
|
||||
return null;
|
||||
}
|
||||
if ( pgValue.startsWith( "00" ) || pgValue.startsWith( "01" ) ) {
|
||||
//we have a WKB because this pgValue starts with the bit-order byte
|
||||
buffer = ByteBuffer.from( pgValue );
|
||||
|
@ -150,4 +152,19 @@ public class PGGeometryType implements JdbcType {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
static class PGGeometryLiteralFormatter<T> extends GeometryLiteralFormatter<T> {
|
||||
public PGGeometryLiteralFormatter(JavaType<T> javaType) {
|
||||
super( javaType, Wkt.Dialect.POSTGIS_EWKT_1, "" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendJdbcLiteral(
|
||||
SqlAppender appender, T value, Dialect dialect, WrapperOptions wrapperOptions) {
|
||||
Geometry<?> geom = javaType.unwrap( value, Geometry.class, wrapperOptions );
|
||||
appender.appendSql( "st_geomfromewkt('" );
|
||||
appender.appendSql( Wkt.toWkt( geom, wktDialect ) );
|
||||
appender.appendSql( "')" );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,13 +11,13 @@ import org.hibernate.boot.model.FunctionContributions;
|
|||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.spatial.GeolatteGeometryJavaTypeDescriptor;
|
||||
import org.hibernate.spatial.GeolatteGeometryType;
|
||||
import org.hibernate.spatial.HSMessageLogger;
|
||||
import org.hibernate.spatial.JTSGeometryJavaTypeDescriptor;
|
||||
import org.hibernate.spatial.JTSGeometryType;
|
||||
import org.hibernate.spatial.contributor.ContributorImplementor;
|
||||
|
||||
import org.geolatte.geom.codec.Wkt;
|
||||
|
||||
public class PostgisDialectContributor implements ContributorImplementor {
|
||||
|
||||
private final ServiceRegistry serviceRegistryegistry;
|
||||
|
@ -28,8 +28,11 @@ public class PostgisDialectContributor implements ContributorImplementor {
|
|||
|
||||
public void contributeTypes(TypeContributions typeContributions) {
|
||||
HSMessageLogger.LOGGER.typeContributions( this.getClass().getCanonicalName() );
|
||||
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryType.INSTANCE_WKB_2 ) );
|
||||
typeContributions.contributeType( new JTSGeometryType( PGGeometryType.INSTANCE_WKB_2 ) );
|
||||
typeContributions.contributeType( new GeolatteGeometryType( PGGeometryJdbcType.INSTANCE_WKB_2 ) );
|
||||
typeContributions.contributeType( new JTSGeometryType( PGGeometryJdbcType.INSTANCE_WKB_2 ) );
|
||||
typeContributions.contributeJavaTypeDescriptor( GeolatteGeometryJavaTypeDescriptor.INSTANCE );
|
||||
typeContributions.contributeJavaTypeDescriptor( JTSGeometryJavaTypeDescriptor.INSTANCE );
|
||||
typeContributions.contributeJdbcTypeDescriptor( PGGeometryJdbcType.INSTANCE_WKB_2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -69,7 +69,7 @@ public class PostgisUnmarshalTest {
|
|||
public void testCase(String pgValue, Geometry<?> expected) throws SQLException {
|
||||
PGobject pgo = new PGobject();
|
||||
pgo.setValue( pgValue );
|
||||
Geometry<?> received = PGGeometryType.INSTANCE_WKB_1.toGeometry( pgo );
|
||||
Geometry<?> received = PGGeometryJdbcType.INSTANCE_WKB_1.toGeometry( pgo );
|
||||
assertEquals( String.format( "Failure on %s", pgValue ), expected, received );
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
package org.hibernate.spatial.testing.dialects.cockroachdb;
|
||||
|
||||
import org.hibernate.spatial.GeomCodec;
|
||||
import org.hibernate.spatial.dialect.postgis.PGGeometryType;
|
||||
import org.hibernate.spatial.dialect.postgis.PGGeometryJdbcType;
|
||||
import org.hibernate.spatial.testing.datareader.TestData;
|
||||
import org.hibernate.spatial.testing.datareader.TestSupport;
|
||||
import org.hibernate.spatial.testing.dialects.NativeSQLTemplates;
|
||||
|
@ -16,7 +16,6 @@ import org.hibernate.spatial.testing.dialects.PredicateRegexes;
|
|||
import org.hibernate.spatial.testing.dialects.postgis.PostgisNativeSQLTemplates;
|
||||
|
||||
import org.geolatte.geom.Geometry;
|
||||
import org.geolatte.geom.codec.Wkt;
|
||||
|
||||
public class CockroachDBTestSupport extends TestSupport {
|
||||
|
||||
|
@ -44,7 +43,7 @@ public class CockroachDBTestSupport extends TestSupport {
|
|||
return new GeomCodec() {
|
||||
@Override
|
||||
public Geometry<?> toGeometry(Object in) {
|
||||
return PGGeometryType.INSTANCE_WKB_2.toGeometry( in );
|
||||
return PGGeometryJdbcType.INSTANCE_WKB_2.toGeometry( in );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -11,9 +11,7 @@ import java.util.Map;
|
|||
|
||||
import org.hibernate.spatial.CommonSpatialFunction;
|
||||
import org.hibernate.spatial.GeomCodec;
|
||||
import org.hibernate.spatial.dialect.mariadb.MariaDBGeometryType;
|
||||
import org.hibernate.spatial.dialect.postgis.PGGeometryType;
|
||||
import org.hibernate.spatial.testing.AbstractExpectationsFactory;
|
||||
import org.hibernate.spatial.dialect.mariadb.MariaDBGeometryJdbcType;
|
||||
import org.hibernate.spatial.testing.datareader.TestData;
|
||||
import org.hibernate.spatial.testing.datareader.TestSupport;
|
||||
import org.hibernate.spatial.testing.dialects.NativeSQLTemplates;
|
||||
|
@ -21,7 +19,6 @@ import org.hibernate.spatial.testing.dialects.PredicateRegexes;
|
|||
import org.hibernate.spatial.testing.dialects.mysql.MySqlNativeSqlTemplates;
|
||||
|
||||
import org.geolatte.geom.Geometry;
|
||||
import org.geolatte.geom.codec.Wkt;
|
||||
|
||||
public class MariaDBTestSupport extends TestSupport {
|
||||
|
||||
|
@ -50,7 +47,7 @@ public class MariaDBTestSupport extends TestSupport {
|
|||
return new GeomCodec() {
|
||||
@Override
|
||||
public Geometry<?> toGeometry(Object in) {
|
||||
return MariaDBGeometryType.INSTANCE.toGeometry( (byte[])in );
|
||||
return MariaDBGeometryJdbcType.INSTANCE.toGeometry( (byte[])in );
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.Map;
|
|||
|
||||
import org.hibernate.spatial.CommonSpatialFunction;
|
||||
import org.hibernate.spatial.GeomCodec;
|
||||
import org.hibernate.spatial.dialect.mysql.MySQLGeometryType;
|
||||
import org.hibernate.spatial.dialect.mysql.MySQLGeometryJdbcType;
|
||||
import org.hibernate.spatial.testing.datareader.TestData;
|
||||
import org.hibernate.spatial.testing.datareader.TestSupport;
|
||||
import org.hibernate.spatial.testing.dialects.NativeSQLTemplates;
|
||||
|
@ -83,7 +83,7 @@ public class MySQLTestSupport extends TestSupport {
|
|||
return new GeomCodec() {
|
||||
@Override
|
||||
public Geometry<?> toGeometry(Object in) {
|
||||
return MySQLGeometryType.INSTANCE.toGeometry( (byte[]) in );
|
||||
return MySQLGeometryJdbcType.INSTANCE.toGeometry( (byte[]) in );
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -13,14 +13,13 @@ import java.util.Map;
|
|||
|
||||
import org.hibernate.spatial.CommonSpatialFunction;
|
||||
import org.hibernate.spatial.GeomCodec;
|
||||
import org.hibernate.spatial.dialect.postgis.PGGeometryType;
|
||||
import org.hibernate.spatial.dialect.postgis.PGGeometryJdbcType;
|
||||
import org.hibernate.spatial.testing.datareader.TestData;
|
||||
import org.hibernate.spatial.testing.datareader.TestSupport;
|
||||
import org.hibernate.spatial.testing.dialects.NativeSQLTemplates;
|
||||
import org.hibernate.spatial.testing.dialects.PredicateRegexes;
|
||||
|
||||
import org.geolatte.geom.Geometry;
|
||||
import org.geolatte.geom.codec.Wkt;
|
||||
|
||||
/**
|
||||
* @author Karel Maesen, Geovise BVBA
|
||||
|
@ -36,7 +35,7 @@ public class PostgisTestSupport extends TestSupport {
|
|||
}
|
||||
|
||||
@Override
|
||||
public PredicateRegexes predicateRegexes(){ return new PredicateRegexes("st_geomfromtext");}
|
||||
public PredicateRegexes predicateRegexes(){ return new PredicateRegexes("st_geomfromewkt");}
|
||||
|
||||
//TODO put this in its own class (analogous to NativeSQLTemplates)
|
||||
@Override
|
||||
|
@ -57,10 +56,11 @@ public class PostgisTestSupport extends TestSupport {
|
|||
|
||||
|
||||
public GeomCodec codec() {
|
||||
//This appears actually no longer needed after changing to JavaType/jdbcType
|
||||
return new GeomCodec() {
|
||||
@Override
|
||||
public Geometry<?> toGeometry(Object in) {
|
||||
return PGGeometryType.INSTANCE_WKB_2.toGeometry( in );
|
||||
return (Geometry<?>)in;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue