HHH-11490 Fix for UUID mapping conflict
* HHH-11490 Fix for UUID mapping conflict * HHH-11490 Custom ValueBinder implementation
This commit is contained in:
parent
ac4f4ff4ad
commit
2aa2bee255
|
@ -17,7 +17,6 @@ import org.hibernate.type.descriptor.ValueBinder;
|
|||
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;
|
||||
|
||||
|
@ -39,12 +38,12 @@ import org.postgresql.util.PGobject;
|
|||
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;
|
||||
|
@ -79,7 +78,7 @@ public class PGGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
|
||||
@Override
|
||||
public int getSqlType() {
|
||||
return Types.OTHER;
|
||||
return 5432;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -89,15 +88,36 @@ public class PGGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
|
||||
@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 );
|
||||
|
@ -106,7 +126,7 @@ public class PGGeometryTypeDescriptor implements SqlTypeDescriptor {
|
|||
|
||||
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" );
|
||||
|
|
Loading…
Reference in New Issue