Search in sources :

Example 1 with BasicBinder

use of org.hibernate.type.descriptor.sql.BasicBinder 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 2 with BasicBinder

use of org.hibernate.type.descriptor.sql.BasicBinder in project hibernate-orm by hibernate.

the class DB2GeometryTypeDescriptor 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 {
            st.setObject(index, toText(value, options));
        }

        @Override
        protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException {
            st.setObject(name, toText(value, options));
        }

        private String toText(X value, WrapperOptions options) {
            final Geometry<?> geometry = getJavaDescriptor().unwrap(value, Geometry.class, options);
            final Db2ClobEncoder encoder = new Db2ClobEncoder();
            String encoded = encoder.encode(geometry);
            return encoded;
        }
    };
}
Also used : CallableStatement(java.sql.CallableStatement) WrapperOptions(org.hibernate.type.descriptor.WrapperOptions) Db2ClobEncoder(org.geolatte.geom.codec.db.db2.Db2ClobEncoder) PreparedStatement(java.sql.PreparedStatement) BasicBinder(org.hibernate.type.descriptor.sql.BasicBinder)

Example 3 with BasicBinder

use of org.hibernate.type.descriptor.sql.BasicBinder 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 4 with BasicBinder

use of org.hibernate.type.descriptor.sql.BasicBinder 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 5 with BasicBinder

use of org.hibernate.type.descriptor.sql.BasicBinder 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)

Aggregations

CallableStatement (java.sql.CallableStatement)5 PreparedStatement (java.sql.PreparedStatement)5 WrapperOptions (org.hibernate.type.descriptor.WrapperOptions)5 BasicBinder (org.hibernate.type.descriptor.sql.BasicBinder)5 Geometry (org.geolatte.geom.Geometry)4 WkbEncoder (org.geolatte.geom.codec.WkbEncoder)2 ByteBuffer (org.geolatte.geom.ByteBuffer)1 Db2ClobEncoder (org.geolatte.geom.codec.db.db2.Db2ClobEncoder)1 PGobject (org.postgresql.util.PGobject)1