use of org.postgresql.util.PGobject in project hibernate-orm by hibernate.
the class PGGeometryTypeDescriptor method toGeometry.
public static Geometry<?> toGeometry(Object object) {
if (object == null) {
return null;
}
ByteBuffer buffer = null;
if (object instanceof PGobject) {
String pgValue = ((PGobject) object).getValue();
if (pgValue.startsWith("00") || pgValue.startsWith("01")) {
//we have a WKB because this pgValue starts with the bit-order byte
buffer = ByteBuffer.from(pgValue);
final WkbDecoder decoder = Wkb.newDecoder(Wkb.Dialect.POSTGIS_EWKB_1);
return decoder.decode(buffer);
} else {
return parseWkt(pgValue);
}
}
throw new IllegalStateException("Received object of type " + object.getClass().getCanonicalName());
}
use of org.postgresql.util.PGobject in project hibernate-orm by hibernate.
the class PostgisUnmarshalTest method testCase.
public void testCase(String pgValue, Geometry<?> expected) throws SQLException {
PGobject pgo = new PGobject();
pgo.setValue(pgValue);
Geometry<?> received = PGGeometryTypeDescriptor.toGeometry(pgo);
assertEquals(String.format("Failure on %s", pgValue), expected, received);
}
use of org.postgresql.util.PGobject in project torodb by torodb.
the class MongoTimestampRecordSqlBinding method get.
@Override
public MongoTimestampRecord get(ResultSet resultSet, int columnIndex) throws SQLException {
PGobject pgObject = (PGobject) resultSet.getObject(columnIndex);
if (pgObject == null) {
return null;
}
String value = pgObject.getValue();
int indexOfComma = value.indexOf(',');
Integer secs = Integer.parseInt(value.substring(1, indexOfComma));
Integer count = Integer.parseInt(value.substring(indexOfComma + 1, value.length() - 1));
return new MongoTimestampRecord(secs, count);
}
Aggregations