Search in sources :

Example 6 with WrapperOptions

use of org.hibernate.type.descriptor.WrapperOptions 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)6 WrapperOptions (org.hibernate.type.descriptor.WrapperOptions)6 PreparedStatement (java.sql.PreparedStatement)5 Geometry (org.geolatte.geom.Geometry)4 BasicBinder (org.hibernate.type.descriptor.sql.BasicBinder)4 PersistenceException (javax.persistence.PersistenceException)2 WkbEncoder (org.geolatte.geom.codec.WkbEncoder)2 ResultSet (java.sql.ResultSet)1 ByteBuffer (org.geolatte.geom.ByteBuffer)1 ValueBinder (org.hibernate.type.descriptor.ValueBinder)1 ValueExtractor (org.hibernate.type.descriptor.ValueExtractor)1