Search in sources :

Example 1 with Geometry

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

the class SDOGeometryValueBinder method bind.

@Override
public void bind(CallableStatement st, J value, String name, WrapperOptions options) throws SQLException {
    if (value == null) {
        st.setNull(name, Types.STRUCT, SQL_TYPE_NAME);
    } else {
        final Geometry geometry = javaTypeDescriptor.unwrap(value, Geometry.class, options);
        final Object dbGeom = toNative(geometry, st.getConnection());
        st.setObject(name, dbGeom);
    }
}
Also used : SDOGeometry(org.geolatte.geom.codec.db.oracle.SDOGeometry) Geometry(org.geolatte.geom.Geometry)

Example 2 with Geometry

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

the class SqlServer2008GeometryTypeDescriptor 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);
            final byte[] bytes = Encoders.encode(geometry);
            st.setObject(index, bytes);
        }

        @Override
        protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException {
            final Geometry geometry = getJavaDescriptor().unwrap(value, Geometry.class, options);
            final byte[] bytes = Encoders.encode(geometry);
            st.setObject(name, bytes);
        }
    };
}
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 3 with Geometry

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

the class GeomEntity method createFrom.

public static GeomEntity createFrom(TestDataElement element) throws WktDecodeException {
    WktDecoder decoder = Wkt.newDecoder(Wkt.Dialect.POSTGIS_EWKT_1);
    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) WktDecoder(org.geolatte.geom.codec.WktDecoder)

Example 4 with Geometry

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

the class SDOGeometryValueBinder method bind.

@Override
public void bind(PreparedStatement st, J value, int index, WrapperOptions options) throws SQLException {
    if (value == null) {
        st.setNull(index, Types.STRUCT, SQL_TYPE_NAME);
    } else {
        final Geometry geometry = javaTypeDescriptor.unwrap(value, Geometry.class, options);
        final Object dbGeom = toNative(geometry, st.getConnection());
        st.setObject(index, dbGeom);
    }
}
Also used : SDOGeometry(org.geolatte.geom.codec.db.oracle.SDOGeometry) Geometry(org.geolatte.geom.Geometry)

Example 5 with Geometry

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

the class GeometryConverterTest method testConverterUsage.

@Test
public void testConverterUsage() {
    try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, GeoDBDialect.class).applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).build()) {
        final MetadataSources metadataSources = new MetadataSources(ssr).addAnnotatedClass(GeometryConverter.class).addAnnotatedClass(MyEntity.class);
        final MetadataBuilderImplementor metadataBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder();
        try (final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) metadataBuilder.build().buildSessionFactory()) {
            final TypeConfiguration typeConfiguration = sessionFactory.getMetamodel().getTypeConfiguration();
            assertThat(typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor(Geometry.class), sameInstance(GeolatteGeometryJavaTypeDescriptor.INSTANCE));
            // todo (5.3) : what to assert wrt to SqlTypeDescriptor?  Anything?
            final EntityPersister entityPersister = sessionFactory.getMetamodel().entityPersister(MyEntity.class);
            final AttributeConverterTypeAdapter geometryAttributeType = assertTyping(AttributeConverterTypeAdapter.class, entityPersister.getPropertyType("geometry"));
            final JpaAttributeConverter converter = assertTyping(JpaAttributeConverter.class, geometryAttributeType.getAttributeConverter());
            assert GeometryConverter.class.equals(converter.getConverterBean().getBeanClass());
        }
    }
}
Also used : MetadataBuilderImplementor(org.hibernate.boot.spi.MetadataBuilderImplementor) Geometry(org.geolatte.geom.Geometry) EntityPersister(org.hibernate.persister.entity.EntityPersister) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) JpaAttributeConverter(org.hibernate.metamodel.model.convert.spi.JpaAttributeConverter) MetadataSources(org.hibernate.boot.MetadataSources) AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter) TypeConfiguration(org.hibernate.type.spi.TypeConfiguration) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) 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