HHH-6509 - Introduces GeolatteGeometryJavaType.
This commit is contained in:
parent
ea833fcdbb
commit
4b7c319cc0
|
@ -27,9 +27,7 @@ dependencies {
|
||||||
compile([group: 'com.vividsolutions', name: 'jts', version: '1.12']) {
|
compile([group: 'com.vividsolutions', name: 'jts', version: '1.12']) {
|
||||||
transitive = false
|
transitive = false
|
||||||
}
|
}
|
||||||
compile([group: 'org.postgis', name: 'postgis-jdbc', version: '1.5.3'])
|
compile([group: 'org.geolatte', name: 'geolatte-geom', version: '0.11-SNAPSHOT'])
|
||||||
compile([group: 'postgresql', name: 'postgresql', version: '8.4-701.jdbc4'])
|
|
||||||
|
|
||||||
|
|
||||||
compile(libraries.dom4j) {
|
compile(libraries.dom4j) {
|
||||||
transitive = false
|
transitive = false
|
||||||
|
@ -38,11 +36,12 @@ dependencies {
|
||||||
|
|
||||||
testCompile(libraries.junit)
|
testCompile(libraries.junit)
|
||||||
testCompile(project(':hibernate-testing'))
|
testCompile(project(':hibernate-testing'))
|
||||||
// testRuntime([group: 'commons-dbcp', name: 'commons-dbcp', version: '1.4'])
|
testRuntime([group: 'commons-dbcp', name: 'commons-dbcp', version: '1.4'])
|
||||||
// testRuntime([group: 'com.oracle.jdbc', name: 'ojdbc6', version: '11.2.0.3'])
|
// testRuntime([group: 'com.oracle.jdbc', name: 'ojdbc6', version: '11.2.0.3'])
|
||||||
// testRuntime([group: 'com.microsoft', name: 'sqljdbc', version: '2.0'])
|
// testRuntime([group: 'com.microsoft', name: 'sqljdbc', version: '2.0'])
|
||||||
// testRuntime("org.opengeo:geodb:0.7")
|
// testRuntime("org.opengeo:geodb:0.7")
|
||||||
// testRuntime("mysql:mysql-connector-java:5.1.15")
|
// testRuntime("mysql:mysql-connector-java:5.1.15")
|
||||||
|
testRuntime("postgresql:postgresql:8.4-701.jdbc4")
|
||||||
testCompile(libraries.validation)
|
testCompile(libraries.validation)
|
||||||
testCompile(libraries.jandex)
|
testCompile(libraries.jandex)
|
||||||
testCompile(libraries.classmate)
|
testCompile(libraries.classmate)
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
package org.hibernate.spatial;
|
||||||
|
|
||||||
|
import org.geolatte.geom.Geometry;
|
||||||
|
import org.geolatte.geom.codec.Wkt;
|
||||||
|
import org.geolatte.geom.jts.JTS;
|
||||||
|
|
||||||
|
import org.hibernate.type.descriptor.WrapperOptions;
|
||||||
|
import org.hibernate.type.descriptor.java.AbstractTypeDescriptor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Karel Maesen, Geovise BVBA
|
||||||
|
* creation-date: 10/12/12
|
||||||
|
*/
|
||||||
|
public class GeolatteGeometryJavaTypeDescriptor extends AbstractTypeDescriptor<Geometry> {
|
||||||
|
|
||||||
|
|
||||||
|
public static final GeolatteGeometryJavaTypeDescriptor INSTANCE = new GeolatteGeometryJavaTypeDescriptor( Geometry.class );
|
||||||
|
|
||||||
|
public GeolatteGeometryJavaTypeDescriptor(Class<Geometry> type) {
|
||||||
|
super( type );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(Geometry value) {
|
||||||
|
return value.asText();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Geometry fromString(String string) {
|
||||||
|
return Wkt.fromWkt( string );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <X> X unwrap(Geometry value, Class<X> type, WrapperOptions options) {
|
||||||
|
if ( value == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( Geometry.class.isAssignableFrom( type ) ) {
|
||||||
|
return (X) value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( com.vividsolutions.jts.geom.Geometry.class.isAssignableFrom( type ) ) {
|
||||||
|
return (X) JTS.to( value );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( String.class.isAssignableFrom( type ) ) {
|
||||||
|
return (X) toString( value );
|
||||||
|
}
|
||||||
|
throw unknownUnwrap( type );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <X> Geometry wrap(X value, WrapperOptions options) {
|
||||||
|
if ( value == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if ( Geometry.class.isInstance( value ) ) {
|
||||||
|
return (Geometry) value;
|
||||||
|
}
|
||||||
|
if ( String.class.isInstance( value ) ) {
|
||||||
|
return fromString( (String) value );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( com.vividsolutions.jts.geom.Geometry.class.isInstance( value ) ) {
|
||||||
|
return JTS.from( (com.vividsolutions.jts.geom.Geometry) value );
|
||||||
|
}
|
||||||
|
|
||||||
|
throw unknownWrap( value.getClass() );
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package org.hibernate.spatial;
|
||||||
|
|
||||||
|
import org.geolatte.geom.*;
|
||||||
|
import org.hibernate.type.AbstractSingleColumnStandardBasicType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Karel Maesen, Geovise BVBA
|
||||||
|
* creation-date: 10/12/12
|
||||||
|
*/
|
||||||
|
public class GeolatteGeometryType extends AbstractSingleColumnStandardBasicType<Geometry> {
|
||||||
|
|
||||||
|
public static final GeolatteGeometryType INSTANCE = new GeolatteGeometryType();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getRegistrationKeys() {
|
||||||
|
return new String[] {
|
||||||
|
Geometry.class.getCanonicalName(),
|
||||||
|
Point.class.getCanonicalName(),
|
||||||
|
Polygon.class.getCanonicalName(),
|
||||||
|
MultiPolygon.class.getCanonicalName(),
|
||||||
|
LineString.class.getCanonicalName(),
|
||||||
|
MultiLineString.class.getCanonicalName(),
|
||||||
|
MultiPoint.class.getCanonicalName(),
|
||||||
|
GeometryCollection.class.getCanonicalName(),
|
||||||
|
"geolatte_geometry"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public GeolatteGeometryType() {
|
||||||
|
super( GeometrySqlTypeDescriptor.INSTANCE, GeolatteGeometryJavaTypeDescriptor.INSTANCE );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "geolatte_geometry";
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,6 +24,7 @@ package org.hibernate.spatial;
|
||||||
import com.vividsolutions.jts.geom.Geometry;
|
import com.vividsolutions.jts.geom.Geometry;
|
||||||
import com.vividsolutions.jts.io.ParseException;
|
import com.vividsolutions.jts.io.ParseException;
|
||||||
import com.vividsolutions.jts.io.WKTReader;
|
import com.vividsolutions.jts.io.WKTReader;
|
||||||
|
import org.geolatte.geom.jts.JTS;
|
||||||
|
|
||||||
import org.hibernate.type.descriptor.WrapperOptions;
|
import org.hibernate.type.descriptor.WrapperOptions;
|
||||||
import org.hibernate.type.descriptor.java.AbstractTypeDescriptor;
|
import org.hibernate.type.descriptor.java.AbstractTypeDescriptor;
|
||||||
|
@ -63,11 +64,12 @@ public class JTSGeometryJavaTypeDescriptor extends AbstractTypeDescriptor<Geomet
|
||||||
if ( value == null ) {
|
if ( value == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( Geometry.class.isAssignableFrom( type ) ) {
|
if ( Geometry.class.isAssignableFrom( type ) ) {
|
||||||
return (X) value;
|
return (X) value;
|
||||||
}
|
}
|
||||||
|
if ( org.geolatte.geom.Geometry.class.isAssignableFrom( type ) ) {
|
||||||
|
return (X) JTS.from( value );
|
||||||
|
}
|
||||||
if ( String.class.isAssignableFrom( type ) ) {
|
if ( String.class.isAssignableFrom( type ) ) {
|
||||||
return (X) toString( value );
|
return (X) toString( value );
|
||||||
}
|
}
|
||||||
|
@ -82,6 +84,9 @@ public class JTSGeometryJavaTypeDescriptor extends AbstractTypeDescriptor<Geomet
|
||||||
if ( Geometry.class.isInstance( value ) ) {
|
if ( Geometry.class.isInstance( value ) ) {
|
||||||
return (Geometry) value;
|
return (Geometry) value;
|
||||||
}
|
}
|
||||||
|
if ( org.geolatte.geom.Geometry.class.isInstance( value ) ) {
|
||||||
|
return JTS.to( (org.geolatte.geom.Geometry) value );
|
||||||
|
}
|
||||||
if ( String.class.isInstance( value ) ) {
|
if ( String.class.isInstance( value ) ) {
|
||||||
return fromString( (String) value );
|
return fromString( (String) value );
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ package org.hibernate.spatial.integration;
|
||||||
|
|
||||||
import org.hibernate.metamodel.spi.MetadataImplementor;
|
import org.hibernate.metamodel.spi.MetadataImplementor;
|
||||||
import org.hibernate.metamodel.spi.TypeContributor;
|
import org.hibernate.metamodel.spi.TypeContributor;
|
||||||
|
import org.hibernate.spatial.GeolatteGeometryType;
|
||||||
import org.hibernate.spatial.JTSGeometryType;
|
import org.hibernate.spatial.JTSGeometryType;
|
||||||
import org.hibernate.spatial.Log;
|
import org.hibernate.spatial.Log;
|
||||||
import org.hibernate.spatial.LogFactory;
|
import org.hibernate.spatial.LogFactory;
|
||||||
|
@ -38,6 +39,8 @@ public class SpatialTypeContributor implements TypeContributor {
|
||||||
public void contribute(MetadataImplementor builder) {
|
public void contribute(MetadataImplementor builder) {
|
||||||
LOG.info( "Registering JTSGeometryType" );
|
LOG.info( "Registering JTSGeometryType" );
|
||||||
builder.getTypeResolver().registerTypeOverride( JTSGeometryType.INSTANCE );
|
builder.getTypeResolver().registerTypeOverride( JTSGeometryType.INSTANCE );
|
||||||
|
LOG.info( "Registering GeolatteGeometryType" );
|
||||||
|
builder.getTypeResolver().registerTypeOverride( GeolatteGeometryType.INSTANCE );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue