@Override protected Argument build(String value, ConfigRegistry config) { return (pos, stmt, ctx) -> { PGobject obj = new PGobject(); obj.setType("macaddr"); obj.setValue(value); stmt.setObject(pos, obj); }; } }
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 ); }
private PGobject toPGobject(X value, WrapperOptions options) throws SQLException { final WkbEncoder encoder = Wkb.newEncoder( Wkb.Dialect.POSTGIS_EWKB_1 ); final Geometry geometry = getJavaDescriptor().unwrap( value, Geometry.class, options ); final String hexString = encoder.encode( geometry, ByteOrder.NDR ).toString(); final PGobject obj = new PGobject(); obj.setType( "geometry" ); obj.setValue( hexString ); return obj; }
Map<String, String> hstoreMap = new HashMap<>(); hstoreMap.put("key1", "value1"); hstoreMap.put("key2", "value2"); PGobject jsonbObj = new PGobject(); jsonbObj.setType("json"); jsonbObj.setValue("{\"key\" : \"value\"}");
/** * Construct and return Postgres specific PG object. */ public static Object asObject(String pgType, String rawJson) throws SQLException { PGobject pgo = new PGobject(); pgo.setType(pgType); pgo.setValue(rawJson); return pgo; } }
PGobject jsonObject = new PGobject(); jsonObject.setType("json"); jsonObject.setValue(yourJsonString); pstmt.setObject(11, jsonObject);
PGobject jsonObject = new PGobject(); jsonObject.setType("jsonb"); jsonObject.setValue(JsonHelper.encode(value)); ps.setObject(i + 1, jsonObject); } else {
PGobject jsonObject = new PGobject(); jsonObject.setType("jsonb"); jsonObject.setValue(JsonHelper.encode(value)); return jsonObject; } else {
ObjectMapper objectMapper = new ObjectMapper(); PGobject jsonObject = new PGobject(); String Map_Json_String = objectMapper.writeValueAsString(your_map); jsonObject.setType("jsonb"); jsonObject.setValue(Map_Json_String); String final insertSql = "INSERT INTO \"Table_Name\"" + " VALUES (:jsonObject);";
/** * @param value Long value of ctid * @return PGObject instance * @throws SQLException */ public static PGobject longToTid(long value) throws SQLException { PGobject pGobject = new PGobject(); pGobject.setType("tid"); pGobject.setValue("(" + Long.toString(value >> 32)+","+Long.toString(value << 32 >> 32)+ ")"); return pGobject; }
@Override public boolean saveState(NewBot newBot) throws Exception { try (Connection c = newConnection()) { PGobject jsonObject = new PGobject(); jsonObject.setType("json"); jsonObject.setValue(mapper.writeValueAsString(newBot)); PreparedStatement stmt = c.prepareStatement("INSERT INTO states (botId, bot) VALUES (?, ?)"); stmt.setObject(1, botId); stmt.setObject(2, jsonObject); return stmt.executeUpdate() == 1; } }
protected final PGobject createJsonObject(String json) { try { PGobject jsonObject = new PGobject(); jsonObject.setType("jsonb"); jsonObject.setValue(json); return jsonObject; } catch (Exception e) { throw new RuntimeException(e); } }
PGobject toInsertUUID = new PGobject(); toInsertUUID.setType("uuid"); toInsertUUID.setValue(uuid.toString()); PreparedStmt stmt = conn.prepareStatement(query); stmt.setObject(placeHolder,toInsertUUID); stmt.execute();
/** * Construct and return Postgres specific PG object. */ public static Object asObject(String pgType, String rawJson) throws SQLException { PGobject pgo = new PGobject(); pgo.setType(pgType); pgo.setValue(rawJson); return pgo; } }
/** * Construct and return Postgres specific PG object. */ public static Object asObject(String pgType, String rawJson) throws SQLException { PGobject pgo = new PGobject(); pgo.setType(pgType); pgo.setValue(rawJson); return pgo; } }
@Override public Object serialize(String value) { PGobject pg = new PGobject(); pg.setType(getDataType()); try { pg.setValue(value); } catch (SQLException e) { // not thrown on base PGobject } return pg; }
@Override public Object serialize(String value) { PGobject pg = new PGobject(); pg.setType(getDataType()); try { pg.setValue(value); } catch (SQLException e) { // not thrown on base PGobject } return pg; }
@Override public void set(PreparedStatement st, IPv4 value, int index, SharedSessionContractImplementor session) throws SQLException { if (value == null) { st.setNull(index, Types.OTHER); } else { PGobject holder = new PGobject(); holder.setType("inet"); holder.setValue(value.getAddress()); st.setObject(index, holder); } } }