Search in sources :

Example 6 with Geometry

use of org.geolatte.geom.Geometry in project hibernate-orm by hibernate.

the class GeomEntity method createFrom.

static GeomEntity createFrom(TestDataElement element, Dialect dialect) throws WktDecodeException {
    WktDecoder decoder = getWktDecoder(dialect);
    Geometry geom = decoder.decode(element.wkt);
    GeomEntity result = new GeomEntity();
    result.setId(element.id);
    result.setGeom(geom);
    result.setType(element.type);
    return result;
}
Also used : Geometry(org.geolatte.geom.Geometry) DecodeUtil.getWktDecoder(org.hibernate.spatial.integration.DecodeUtil.getWktDecoder) WktDecoder(org.geolatte.geom.codec.WktDecoder)

Example 7 with Geometry

use of org.geolatte.geom.Geometry in project hibernate-orm by hibernate.

the class PGGeometryTypeDescriptor method getBinder.

@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
    return new BasicBinder<X>(javaTypeDescriptor, this) {

        @Override
        protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
            final PGobject obj = toPGobject(value, options);
            st.setObject(index, obj);
        }

        @Override
        protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException {
            final PGobject obj = toPGobject(value, options);
            st.setObject(name, obj);
        }

        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 String hexString = encoder.encode(geometry, ByteOrder.NDR).toString();
            final PGobject obj = new PGobject();
            obj.setType("geometry");
            obj.setValue(hexString);
            return obj;
        }
    };
}
Also used : Geometry(org.geolatte.geom.Geometry) WkbEncoder(org.geolatte.geom.codec.WkbEncoder) CallableStatement(java.sql.CallableStatement) WrapperOptions(org.hibernate.type.descriptor.WrapperOptions) PreparedStatement(java.sql.PreparedStatement) BasicBinder(org.hibernate.type.descriptor.sql.BasicBinder) PGobject(org.postgresql.util.PGobject)

Example 8 with Geometry

use of org.geolatte.geom.Geometry in project hibernate-orm by hibernate.

the class GeoDBGeometryTypeDescriptor method getBinder.

@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
    return new BasicBinder<X>(javaTypeDescriptor, this) {

        @Override
        protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
            final Geometry geometry = getJavaDescriptor().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);
            st.setBytes(name, GeoDbWkb.to(geometry));
        }
    };
}
Also used : Geometry(org.geolatte.geom.Geometry) CallableStatement(java.sql.CallableStatement) WrapperOptions(org.hibernate.type.descriptor.WrapperOptions) PreparedStatement(java.sql.PreparedStatement) BasicBinder(org.hibernate.type.descriptor.sql.BasicBinder)

Example 9 with Geometry

use of org.geolatte.geom.Geometry in project hibernate-orm by hibernate.

the class MySQLGeometryTypeDescriptor method getBinder.

@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
    return new BasicBinder<X>(javaTypeDescriptor, this) {

        @Override
        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 ByteBuffer buffer = encoder.encode(geometry, ByteOrder.NDR);
            final byte[] bytes = (buffer == null ? null : buffer.toByteArray());
            st.setBytes(index, bytes);
        }

        @Override
        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 ByteBuffer buffer = encoder.encode(geometry, ByteOrder.NDR);
            final byte[] bytes = (buffer == null ? null : buffer.toByteArray());
            st.setBytes(name, bytes);
        }
    };
}
Also used : Geometry(org.geolatte.geom.Geometry) WkbEncoder(org.geolatte.geom.codec.WkbEncoder) CallableStatement(java.sql.CallableStatement) WrapperOptions(org.hibernate.type.descriptor.WrapperOptions) PreparedStatement(java.sql.PreparedStatement) ByteBuffer(org.geolatte.geom.ByteBuffer) BasicBinder(org.hibernate.type.descriptor.sql.BasicBinder)

Example 10 with Geometry

use of org.geolatte.geom.Geometry in project querydsl by querydsl.

the class PGgeometryConverterTest method roundTrip.

@Test
public void roundTrip() {
    List<Geometry> geometries = getGeometries();
    for (Geometry geometry : geometries) {
        org.postgis.Geometry converted = PGgeometryConverter.convert(geometry);
        Geometry back = PGgeometryConverter.convert(converted);
        assertEquals(geometry, back);
    }
}
Also used : Geometry(org.geolatte.geom.Geometry) Test(org.junit.Test)

Aggregations

Geometry (org.geolatte.geom.Geometry)12 CallableStatement (java.sql.CallableStatement)4 PreparedStatement (java.sql.PreparedStatement)4 WrapperOptions (org.hibernate.type.descriptor.WrapperOptions)4 BasicBinder (org.hibernate.type.descriptor.sql.BasicBinder)4 WktDecoder (org.geolatte.geom.codec.WktDecoder)3 Test (org.junit.Test)3 WkbEncoder (org.geolatte.geom.codec.WkbEncoder)2 SDOGeometry (org.geolatte.geom.codec.db.oracle.SDOGeometry)2 HashMap (java.util.HashMap)1 ByteBuffer (org.geolatte.geom.ByteBuffer)1 WktDecodeException (org.geolatte.geom.codec.WktDecodeException)1 MetadataSources (org.hibernate.boot.MetadataSources)1 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)1 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)1 MetadataBuilderImplementor (org.hibernate.boot.spi.MetadataBuilderImplementor)1 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1 JpaAttributeConverter (org.hibernate.metamodel.model.convert.spi.JpaAttributeConverter)1 EntityPersister (org.hibernate.persister.entity.EntityPersister)1 DecodeUtil.getWktDecoder (org.hibernate.spatial.integration.DecodeUtil.getWktDecoder)1