Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/main/java/picoded/dstack/jsql_json/JsonbUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ public static MutablePair<String, byte[]> serializeDataMap(Map<String, Object> i
continue;
}
} else if (v instanceof byte[]) {
// Handling of binary data
binMap.put(k, v);
// Skip binary data in keySet loop; processed below from fullSet
} else {
// In all other cases, treat it as JSON data
// we add it to the jsonMap, if its within the keyset
Expand All @@ -114,6 +113,17 @@ public static MutablePair<String, byte[]> serializeDataMap(Map<String, Object> i
}
}

// Build complete binary map from fullSet to prevent losing existing binary properties during partial updates
for (String k : fullSet) {
if (k.equalsIgnoreCase("_otm") || k.length() > 64) {
continue;
}
Object v = inMap.get(k);
if (v instanceof byte[] && v != null && v != ObjectToken.NULL) {
binMap.put(k, v);
}
}

// Lets do the required conversions
String json = ConvertJSON.fromMap(jsonMap);
byte[] bin = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,32 @@ public void DataObjectRemoteDataMap_update(String _oid, Map<String, Object> full
// Curent timestamp
long now = JSql_DataObjectMapUtil.getCurrentTimestamp();

// // Ensure GUID is registered
// sqlObj.upsert( //
// dataStorageTable, //
// new String[] { "oID" }, //
// new Object[] { _oid }, //
// new String[] { "uTm", "data", "bData" }, //
// new Object[] { now, dataPair.getLeft(), dataPair.getRight() }, //
// new String[] { "cTm", "eTm" }, //
// new Object[] { now, 0 }, //
// null // The only misc col, is pKy, which is being handled by DB
// );
// Determine which keys are being deleted/removed (explicitly null or ObjectToken.NULL)
String updateDataSql = dataStorageTable + ".data||EXCLUDED.data";
Set<String> keysToProcess = keys;
if (keysToProcess == null) {
keysToProcess = fullMap.keySet();
}

java.util.List<String> deletedKeys = new java.util.ArrayList<>();
for (String k : keysToProcess) {
if (k.equalsIgnoreCase("oid") || k.equalsIgnoreCase("_oid") || k.equalsIgnoreCase("_otm")) {
continue;
}
Object v = fullMap.get(k);
if (v == null || v == picoded.core.common.ObjectToken.NULL) {
deletedKeys.add(k);
}
}

if (!deletedKeys.isEmpty()) {
StringBuilder sb = new StringBuilder();
sb.append("(").append(updateDataSql).append(")");
for (String dk : deletedKeys) {
sb.append(" - '").append(dk.replace("'", "''")).append("'");
}
updateDataSql = sb.toString();
}

// Perform the upsert command
sqlObj.update_raw( //
Expand All @@ -233,7 +248,7 @@ public void DataObjectRemoteDataMap_update(String _oid, Map<String, Object> full
"VALUES ( ?, ?, ?, ?, ?::jsonb, ? ) " + //
"ON CONFLICT ( oID ) DO UPDATE SET " + //
"uTm=EXCLUDED.uTm, " + //
"data=" + dataStorageTable + ".data||EXCLUDED.data, " + //
"data=" + updateDataSql + ", " + //
"bData=EXCLUDED.bData", new Object[] { //
_oid, now, now, 0, dataPair.getLeft(), dataPair.getRight() //
});
Expand Down
Loading