Search in sources :

Example 1 with Db2ClobEncoder

use of org.geolatte.geom.codec.db.db2.Db2ClobEncoder 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)

Aggregations

CallableStatement (java.sql.CallableStatement)1 PreparedStatement (java.sql.PreparedStatement)1 Db2ClobEncoder (org.geolatte.geom.codec.db.db2.Db2ClobEncoder)1 WrapperOptions (org.hibernate.type.descriptor.WrapperOptions)1 BasicBinder (org.hibernate.type.descriptor.sql.BasicBinder)1