/** * This is defined here, so user code need not overide it. * * @return the value of this object, in the syntax expected by org.postgresql */ public String toString() { return getValue(); }
/** * This is defined here, so user code need not overide it. * @return the value of this object, in the syntax expected by org.postgresql */ public String toString() { return getValue(); } }
/** * This must be overidden to allow comparisons of objects. * * @param obj Object to compare with * @return true if the two boxes are identical */ public boolean equals(Object obj) { if (obj instanceof PGobject) { final Object otherValue = ((PGobject) obj).getValue(); if (otherValue == null) { return getValue() == null; } return otherValue.equals(getValue()); } return false; }
@Override @SuppressWarnings("unchecked") public String map(ResultSet r, int columnNumber, StatementContext ctx) throws SQLException { PGobject obj = (PGobject) r.getObject(columnNumber); return obj.getValue(); } }
/** * Extracts a value from a PGobject . * * @param column the column definition describing the {@code data} value; never null * @param fieldDefn the field definition; never null * @param data the data object to be converted into a Kafka Connect type * @return the converted value, or null if the conversion could not be made and the column allows nulls * @throws IllegalArgumentException if the value could not be converted but the column does not allow nulls */ @Override protected Object convertBinary(Column column, Field fieldDefn, Object data) { return super.convertBinary(column, fieldDefn, (data instanceof PGobject) ? ((PGobject)data).getValue() : data); } }
@Override protected Object convertBits(Column column, Field fieldDefn, Object data, int numBytes) { if (data instanceof PGobject) { // returned by the JDBC driver data = ((PGobject) data).getValue(); } if (data instanceof String) { long longValue = Long.parseLong((String) data, 2); // return the smallest possible value if (Short.MIN_VALUE <= longValue && longValue <= Short.MAX_VALUE) { data = (short) longValue; } else if (Integer.MIN_VALUE <= longValue && longValue <= Integer.MAX_VALUE) { data = (int) longValue; } else { data = longValue; } } return super.convertBits(column, fieldDefn, data, numBytes); }
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() ); }
protected Object convertCitext(Column column, Field fieldDefn, Object data) { return convertValue(column, fieldDefn, data, "", (r) -> { if (data instanceof byte[]) { r.deliver(new String((byte[]) data)); } else if (data instanceof String) { r.deliver(data); } else if (data instanceof PGobject) { r.deliver(((PGobject) data).getValue()); } }); }
private void setPGobject(int parameterIndex, PGobject x) throws SQLException { String typename = x.getType(); int oid = connection.getTypeInfo().getPGType(typename); if (oid == Oid.UNSPECIFIED) throw new PSQLException(GT.tr("Unknown type {0}.", typename), PSQLState.INVALID_PARAMETER_TYPE); setString(parameterIndex, x.getValue(), oid); }
private void setPGobject(int parameterIndex, PGobject x) throws SQLException { String typename = x.getType(); int oid = connection.getTypeInfo().getPGType(typename); if (oid == Oid.UNSPECIFIED) { throw new PSQLException(GT.tr("Unknown type {0}.", typename), PSQLState.INVALID_PARAMETER_TYPE); } if ((x instanceof PGBinaryObject) && connection.binaryTransferSend(oid)) { PGBinaryObject binObj = (PGBinaryObject) x; byte[] data = new byte[binObj.lengthInBytes()]; binObj.toBytes(data, 0); bindBytes(parameterIndex, data, oid); } else { setString(parameterIndex, x.getValue(), oid); } }
String value = ((PGobject) valueObject).getValue(); rowBuffer[columnIndex] = (value == null) ? null : connection.encodeString(value); } else {
return type.cast(InetAddress.getByName(((PGobject) addressString).getValue())); } catch (UnknownHostException e) { throw new SQLException("could not create inet address from string '" + addressString + "'");
protected Object convertGeometry(Column column, Field fieldDefn, Object data) { final PostgisGeometry empty = PostgisGeometry.createEmpty(); return convertValue(column, fieldDefn, data, io.debezium.data.geometry.Geometry.createValue(fieldDefn.schema(), empty.getWkb(), empty.getSrid()), (r) -> { try { final Schema schema = fieldDefn.schema(); if (data instanceof byte[]) { PostgisGeometry geom = PostgisGeometry.fromHexEwkb(new String((byte[])data, "ASCII")); r.deliver(io.debezium.data.geometry.Geometry.createValue(schema, geom.getWkb(), geom.getSrid())); } else if (data instanceof PGobject) { PGobject pgo = (PGobject)data; PostgisGeometry geom = PostgisGeometry.fromHexEwkb(pgo.getValue()); r.deliver(io.debezium.data.geometry.Geometry.createValue(schema, geom.getWkb(), geom.getSrid())); } else if (data instanceof String) { PostgisGeometry geom = PostgisGeometry.fromHexEwkb((String)data); r.deliver(io.debezium.data.geometry.Geometry.createValue(schema, geom.getWkb(), geom.getSrid())); } } catch (IllegalArgumentException | UnsupportedEncodingException e) { logger.warn("Error converting to a Geometry type", column); } }); }
protected Object convertGeography(Column column, Field fieldDefn, Object data) { final PostgisGeometry empty = PostgisGeometry.createEmpty(); return convertValue(column, fieldDefn, data, io.debezium.data.geometry.Geography.createValue(fieldDefn.schema(), empty.getWkb(), empty.getSrid()), (r) -> { final Schema schema = fieldDefn.schema(); try { if (data instanceof byte[]) { PostgisGeometry geom = PostgisGeometry.fromHexEwkb(new String((byte[])data, "ASCII")); r.deliver(io.debezium.data.geometry.Geography.createValue(schema, geom.getWkb(), geom.getSrid())); } else if (data instanceof PGobject) { PGobject pgo = (PGobject)data; PostgisGeometry geom = PostgisGeometry.fromHexEwkb(pgo.getValue()); r.deliver(io.debezium.data.geometry.Geography.createValue(schema, geom.getWkb(), geom.getSrid())); } else if (data instanceof String) { PostgisGeometry geom = PostgisGeometry.fromHexEwkb((String)data); r.deliver(io.debezium.data.geometry.Geography.createValue(schema, geom.getWkb(), geom.getSrid())); } } catch (IllegalArgumentException | UnsupportedEncodingException e) { logger.warn("Error converting to a Geography type", column); } }); }
} else { if (pgObject.getType().equals("jsonb")) { object = JsonHelper.read(pgObject.getValue()); } else { throw new UnsupportedOperationException("Postgresql type is not supported");
if (resultSet.wasNull()) return NullNode.getInstance(); node = JsonHelper.read(pgObject.getValue()); } else { throw new UnsupportedOperationException();
/** * This is defined here, so user code need not overide it. * @return the value of this object, in the syntax expected by org.postgresql */ public String toString() { return getValue(); } }
private Node toNode (Map<String, Object> aRecord) { String id = (String) aRecord.get("id"); String type = (String) aRecord.get("node_type"); PGobject properties = (PGobject) aRecord.get("properties"); String propertiesValue = properties.getValue(); return SimpleNode.builder(this) .id(id) .type(type) .properties(JSON.read(propertiesValue, Map.class)) .build(); }