Search in sources :

Example 1 with PGobject

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());
}
Also used : ByteBuffer(org.geolatte.geom.ByteBuffer) WkbDecoder(org.geolatte.geom.codec.WkbDecoder) PGobject(org.postgresql.util.PGobject)

Example 2 with PGobject

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);
}
Also used : PGobject(org.postgresql.util.PGobject)

Example 3 with PGobject

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);
}
Also used : MongoTimestampRecord(com.torodb.backend.udt.record.MongoTimestampRecord) PGobject(org.postgresql.util.PGobject)

Aggregations

PGobject (org.postgresql.util.PGobject)3 MongoTimestampRecord (com.torodb.backend.udt.record.MongoTimestampRecord)1 ByteBuffer (org.geolatte.geom.ByteBuffer)1 WkbDecoder (org.geolatte.geom.codec.WkbDecoder)1