Skip to content

Commit

Permalink
HHH-11490 Fix for UUID mapping conflict
Browse files Browse the repository at this point in the history
* HHH-11490 Fix for UUID mapping conflict

* HHH-11490 Custom ValueBinder implementation
  • Loading branch information
maesenka committed Apr 15, 2021
1 parent ac4f4ff commit 2aa2bee
Showing 1 changed file with 28 additions and 8 deletions.
Expand Up @@ -17,7 +17,6 @@
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.sql.BasicBinder;
import org.hibernate.type.descriptor.sql.BasicExtractor;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;

Expand All @@ -39,12 +38,12 @@
public class PGGeometryTypeDescriptor implements SqlTypeDescriptor {


final private Wkb.Dialect wkbDialect;
private final Wkb.Dialect wkbDialect;

// Type descriptor instance using EWKB v1 (postgis versions < 2.2.2)
public static final PGGeometryTypeDescriptor INSTANCE_WKB_1 = new PGGeometryTypeDescriptor( Wkb.Dialect.POSTGIS_EWKB_1);
public static final PGGeometryTypeDescriptor INSTANCE_WKB_1 = new PGGeometryTypeDescriptor( Wkb.Dialect.POSTGIS_EWKB_1 );
// Type descriptor instance using EWKB v2 (postgis versions >= 2.2.2, see: https://trac.osgeo.org/postgis/ticket/3181)
public static final PGGeometryTypeDescriptor INSTANCE_WKB_2 = new PGGeometryTypeDescriptor(Wkb.Dialect.POSTGIS_EWKB_2);
public static final PGGeometryTypeDescriptor INSTANCE_WKB_2 = new PGGeometryTypeDescriptor( Wkb.Dialect.POSTGIS_EWKB_2 );

private PGGeometryTypeDescriptor(Wkb.Dialect dialect) {
wkbDialect = dialect;
Expand Down Expand Up @@ -79,7 +78,7 @@ private static Geometry<?> parseWkt(String pgValue) {

@Override
public int getSqlType() {
return Types.OTHER;
return 5432;
}

@Override
Expand All @@ -89,15 +88,36 @@ public boolean canBeRemapped() {

@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
return new BasicBinder<X>( javaTypeDescriptor, this ) {
return new ValueBinder<X>() {

@Override
public final void bind(PreparedStatement st, X value, int index, WrapperOptions options)
throws SQLException {
if ( value == null ) {
st.setNull( index, Types.OTHER );
}
else {
doBind( st, value, index, options );
}
}

@Override
public final void bind(CallableStatement st, X value, String name, WrapperOptions options)
throws SQLException {
if ( value == null ) {
st.setNull( name, Types.OTHER );
}
else {
doBind( st, value, name, options );
}
}

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 );
Expand All @@ -106,7 +126,7 @@ protected void doBind(CallableStatement st, X value, String name, WrapperOptions

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 Geometry geometry = javaTypeDescriptor.unwrap( value, Geometry.class, options );
final String hexString = encoder.encode( geometry, ByteOrder.NDR ).toString();
final PGobject obj = new PGobject();
obj.setType( "geometry" );
Expand Down

0 comments on commit 2aa2bee

Please sign in to comment.