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);
}
};
}
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;
}
};
}
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;
}
};
}
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));
}
};
}
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);
}
};
}
Aggregations