private String changePlainStringRepresentationToJsonStringRepresentation(String text){ Map<String, String> map = HStoreConverter.fromString(text); StringWriter writer = new StringWriter(); try (JsonGenerator jsonGenerator = jsonFactory.createGenerator(writer)) { jsonGenerator.writeStartObject(); for (Entry<String, String> hstoreEntry : map.entrySet()) { jsonGenerator.writeStringField(hstoreEntry.getKey(), hstoreEntry.getValue()); } jsonGenerator.writeEndObject(); jsonGenerator.flush(); return writer.getBuffer().toString(); } catch(Exception e) { throw new RuntimeException("Couldn't serialize hstore value into JSON: " + text, e); } }
private void setMap(int parameterIndex, Map<?, ?> x) throws SQLException { int oid = connection.getTypeInfo().getPGType("hstore"); if (oid == Oid.UNSPECIFIED) { throw new PSQLException(GT.tr("No hstore extension installed."), PSQLState.INVALID_PARAMETER_TYPE); } if (connection.binaryTransferSend(oid)) { byte[] data = HStoreConverter.toBytes(x, connection.getEncoding()); bindBytes(parameterIndex, data, oid); } else { setString(parameterIndex, HStoreConverter.toString(x), oid); } }
public static String toString(Map<?, ?> map) { if (map.isEmpty()) { return ""; } StringBuilder sb = new StringBuilder(map.size() * 8); for (Entry<?, ?> e : map.entrySet()) { appendEscaped(sb, e.getKey()); sb.append("=>"); appendEscaped(sb, e.getValue()); sb.append(", "); } sb.setLength(sb.length() - 2); return sb.toString(); }
return HStoreConverter.fromBytes(this_row[columnIndex - 1], connection.getEncoding()); return HStoreConverter.fromString(getString(columnIndex));
return HStoreConverter.toString((Map<?, ?>) obj);
public static Map<String, String> fromString(String s) { Map<String, String> m = new HashMap<String, String>(); int pos = 0; StringBuilder sb = new StringBuilder(); while (pos < s.length()) { sb.setLength(0); int start = s.indexOf('"', pos); int end = appendUntilQuote(sb, s, start); String key = sb.toString(); pos = end + 3; String val; if (s.charAt(pos) == 'N') { val = null; pos += 4; } else { sb.setLength(0); end = appendUntilQuote(sb, s, pos); val = sb.toString(); pos = end; } pos++; m.put(key, val); } return m; }
@Override public void nullSafeSet(PreparedStatement preparedStatement, Object value, int i, SharedSessionContractImplementor sessionImplementor) throws HibernateException, SQLException { String s = HStoreConverter.toString((Map) value); preparedStatement.setObject(i, s, Types.OTHER); }
private Object convertHstoreToMap(Column column, Field fieldDefn, Object data){ return convertValue(column, fieldDefn, data, Collections.emptyMap(), (r) -> { if (data instanceof String) { r.deliver(HStoreConverter.fromString((String) data)); } else if (data instanceof byte[]) { r.deliver(HStoreConverter.fromString(asHstoreString((byte[]) data))); } }); }
@Override public Object nullSafeGet(ResultSet resultSet, String[] names, SharedSessionContractImplementor sessionImplementor, Object owner) throws HibernateException, SQLException { String col = names[0]; String val = resultSet.getString(col); return HStoreConverter.fromString(val); }
private String changePlainStringRepresentationToJsonStringRepresentation(String text){ Map<String, String> map = HStoreConverter.fromString(text); StringWriter writer = new StringWriter(); try (JsonGenerator jsonGenerator = jsonFactory.createGenerator(writer)) { jsonGenerator.writeStartObject(); for (Entry<String, String> hstoreEntry : map.entrySet()) { jsonGenerator.writeStringField(hstoreEntry.getKey(), hstoreEntry.getValue()); } jsonGenerator.writeEndObject(); jsonGenerator.flush(); return writer.getBuffer().toString(); } catch(Exception e) { throw new RuntimeException("Couldn't serialize hstore value into JSON: " + text, e); } }
private Object convertHstoreToMap(Column column, Field fieldDefn, Object data){ return convertValue(column, fieldDefn, data, Collections.emptyMap(), (r) -> { if (data instanceof String) { r.deliver(HStoreConverter.fromString((String) data)); } else if (data instanceof byte[]) { r.deliver(HStoreConverter.fromString(asHstoreString((byte[]) data))); } }); }
@Override public void jsonColumn(Column column) { Value v; try { Map map = HStoreConverter.fromString(value); v = jsonParser.parse(mapper.writeValueAsString(map)); } catch (JsonProcessingException | JsonParseException e) { super.jsonColumn(column); return; } to.setJson(column, v); } }