use of org.hibernate.type.descriptor.WrapperOptions 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 WkbEncoder encoder = Wkb.newEncoder(Wkb.Dialect.POSTGIS_EWKB_1);
final Geometry geometry = getJavaDescriptor().unwrap(value, Geometry.class, options);
final byte[] bytes = encoder.encode(geometry, ByteOrder.NDR).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.POSTGIS_EWKB_1);
final Geometry geometry = getJavaDescriptor().unwrap(value, Geometry.class, options);
final byte[] bytes = encoder.encode(geometry, ByteOrder.NDR).toByteArray();
st.setBytes(name, bytes);
}
};
}
use of org.hibernate.type.descriptor.WrapperOptions 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.WrapperOptions in project hibernate-orm by hibernate.
the class AttributeConverterSqlTypeDescriptorAdapter method getBinder.
// Binding ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Override
@SuppressWarnings("unchecked")
public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {
// Get the binder for the intermediate type representation
final ValueBinder realBinder = delegate.getBinder(intermediateJavaTypeDescriptor);
return new ValueBinder<X>() {
@Override
public void bind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
final Object convertedValue;
try {
convertedValue = converter.convertToDatabaseColumn(value);
} catch (PersistenceException pe) {
throw pe;
} catch (RuntimeException re) {
throw new PersistenceException("Error attempting to apply AttributeConverter", re);
}
log.debugf("Converted value on binding : %s -> %s", value, convertedValue);
realBinder.bind(st, convertedValue, index, options);
}
@Override
public void bind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException {
final Object convertedValue;
try {
convertedValue = converter.convertToDatabaseColumn(value);
} catch (PersistenceException pe) {
throw pe;
} catch (RuntimeException re) {
throw new PersistenceException("Error attempting to apply AttributeConverter", re);
}
log.debugf("Converted value on binding : %s -> %s", value, convertedValue);
realBinder.bind(st, convertedValue, name, options);
}
};
}
use of org.hibernate.type.descriptor.WrapperOptions in project hibernate-orm by hibernate.
the class AttributeConverterSqlTypeDescriptorAdapter method getExtractor.
// Extraction ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@Override
public <X> ValueExtractor<X> getExtractor(JavaTypeDescriptor<X> javaTypeDescriptor) {
// Get the extractor for the intermediate type representation
final ValueExtractor realExtractor = delegate.getExtractor(intermediateJavaTypeDescriptor);
return new ValueExtractor<X>() {
@Override
public X extract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
return doConversion(realExtractor.extract(rs, name, options));
}
@Override
public X extract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
return doConversion(realExtractor.extract(statement, index, options));
}
@Override
public X extract(CallableStatement statement, String[] paramNames, WrapperOptions options) throws SQLException {
if (paramNames.length > 1) {
throw new IllegalArgumentException("Basic value extraction cannot handle multiple output parameters");
}
return doConversion(realExtractor.extract(statement, paramNames, options));
}
@SuppressWarnings("unchecked")
private X doConversion(Object extractedValue) {
try {
X convertedValue = (X) converter.convertToEntityAttribute(extractedValue);
log.debugf("Converted value on extraction: %s -> %s", extractedValue, convertedValue);
return convertedValue;
} catch (PersistenceException pe) {
throw pe;
} catch (RuntimeException re) {
throw new PersistenceException("Error attempting to apply AttributeConverter", re);
}
}
};
}
use of org.hibernate.type.descriptor.WrapperOptions 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));
}
};
}
Aggregations