use of org.geolatte.geom.Geometry in project hibernate-orm by hibernate.
the class SDOGeometryValueBinder method bind.
@Override
public void bind(CallableStatement st, J value, String name, WrapperOptions options) throws SQLException {
if (value == null) {
st.setNull(name, Types.STRUCT, SQL_TYPE_NAME);
} else {
final Geometry geometry = javaTypeDescriptor.unwrap(value, Geometry.class, options);
final Object dbGeom = toNative(geometry, st.getConnection());
st.setObject(name, dbGeom);
}
}
use of org.geolatte.geom.Geometry 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.geolatte.geom.Geometry in project hibernate-orm by hibernate.
the class GeomEntity method createFrom.
public static GeomEntity createFrom(TestDataElement element) throws WktDecodeException {
WktDecoder decoder = Wkt.newDecoder(Wkt.Dialect.POSTGIS_EWKT_1);
Geometry geom = decoder.decode(element.wkt);
GeomEntity result = new GeomEntity();
result.setId(element.id);
result.setGeom(geom);
result.setType(element.type);
return result;
}
use of org.geolatte.geom.Geometry in project hibernate-orm by hibernate.
the class SDOGeometryValueBinder method bind.
@Override
public void bind(PreparedStatement st, J value, int index, WrapperOptions options) throws SQLException {
if (value == null) {
st.setNull(index, Types.STRUCT, SQL_TYPE_NAME);
} else {
final Geometry geometry = javaTypeDescriptor.unwrap(value, Geometry.class, options);
final Object dbGeom = toNative(geometry, st.getConnection());
st.setObject(index, dbGeom);
}
}
use of org.geolatte.geom.Geometry in project hibernate-orm by hibernate.
the class GeometryConverterTest method testConverterUsage.
@Test
public void testConverterUsage() {
try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, GeoDBDialect.class).applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).build()) {
final MetadataSources metadataSources = new MetadataSources(ssr).addAnnotatedClass(GeometryConverter.class).addAnnotatedClass(MyEntity.class);
final MetadataBuilderImplementor metadataBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder();
try (final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) metadataBuilder.build().buildSessionFactory()) {
final TypeConfiguration typeConfiguration = sessionFactory.getMetamodel().getTypeConfiguration();
assertThat(typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor(Geometry.class), sameInstance(GeolatteGeometryJavaTypeDescriptor.INSTANCE));
// todo (5.3) : what to assert wrt to SqlTypeDescriptor? Anything?
final EntityPersister entityPersister = sessionFactory.getMetamodel().entityPersister(MyEntity.class);
final AttributeConverterTypeAdapter geometryAttributeType = assertTyping(AttributeConverterTypeAdapter.class, entityPersister.getPropertyType("geometry"));
final JpaAttributeConverter converter = assertTyping(JpaAttributeConverter.class, geometryAttributeType.getAttributeConverter());
assert GeometryConverter.class.equals(converter.getConverterBean().getBeanClass());
}
}
}
Aggregations