Skip to content

Commit 2dc619c

Browse files
committed
Fix that damn thing
1 parent b101e94 commit 2dc619c

2 files changed

Lines changed: 19 additions & 17 deletions

File tree

src/main/java/picoded/dstack/mongodb/MongoDB_DataObjectMap.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ public Map<String, Object> DataObjectRemoteDataMap_get(String _oid) {
222222
**/
223223
public void DataObjectRemoteDataMap_update(String _oid, Map<String, Object> fullMap,
224224
Set<String> updateKeys) {
225+
225226

226227
// Configure this to be an "upsert" query
227228
FindOneAndUpdateOptions opt = new FindOneAndUpdateOptions();
@@ -236,7 +237,9 @@ public void DataObjectRemoteDataMap_update(String _oid, Map<String, Object> full
236237
Document unset_doc = new Document();
237238

238239
// Lets iterate the keys, and decide accordingly
239-
Set<String> fullKeys = fullMap.keySet();
240+
Set<String> fullKeys = new HashSet<String>(fullMap.keySet());
241+
fullKeys.addAll(updateKeys);
242+
240243
for (String key : fullKeys) {
241244
// Get the value
242245
Object value = fullMap.get(key);
@@ -268,13 +271,10 @@ public void DataObjectRemoteDataMap_update(String _oid, Map<String, Object> full
268271
if (updateKeys.contains(key)) {
269272
// Handle NULL values unset
270273
if (value == null || value == ObjectToken.NULL) {
271-
// In theory this should have worked
274+
272275
unset_doc.append(key, "");
276+
continue;
273277

274-
// // But it didn't so i tried this instead
275-
// set_doc.append(key, null);
276-
// setOnInsert_doc.append(key, null);
277-
// continue;
278278
}
279279

280280
// Handle values update
@@ -290,6 +290,7 @@ public void DataObjectRemoteDataMap_update(String _oid, Map<String, Object> full
290290
setOnInsert_doc.append(key, value);
291291
}
292292
}
293+
293294

294295
// Generate the "update" doc
295296
Document updateDoc = new Document();

src/test/java/picoded/dstack/struct/simple/StructSimple_DataObjectMap_test.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ public void constructorTest() {
5959
// Subset assertion
6060
//-----------------------------------------------
6161

62-
/// Utility function, to ensure the expected values exists in map
63-
/// while allowing future test cases not to break when additional values
64-
/// like create timestamp is added.
62+
// Utility function, to ensure the expected values exists in map
63+
// while allowing future test cases not to break when additional values
64+
// like create timestamp is added.
6565
public void assetSubset(Map<String, Object> expected, Map<String, Object> result) {
6666
for (Map.Entry<String, Object> entry : expected.entrySet()) {
6767
assertEquals(entry.getValue(), result.get(entry.getKey()));
@@ -86,10 +86,9 @@ protected HashMap<String, Object> randomObjMap() {
8686
}
8787

8888
// @Test
89-
// public void invalidSetup() { //Numeric as table prefix tend to cuase
90-
// problems
89+
// public void invalidSetup() {
90+
// //Numeric as table prefix tend to cause problems
9191
// DataObjectMap m;
92-
//
9392
// try {
9493
// m = new DataObjectMap(JStackObj, "1" + TestConfig.randomTablePrefix());
9594
// fail(); // if we got here, no exception was thrown, which is bad
@@ -139,7 +138,7 @@ public void basicTest() {
139138
assetSubset(objMap, mtObj.get(guid));
140139
}
141140

142-
/// Checks if a blank object gets saved
141+
// Checks if a blank object gets saved
143142
@Test
144143
public void blankObjectSave() {
145144
String guid = null;
@@ -607,7 +606,7 @@ public void getKeyNamesTest() {
607606
// }
608607

609608
// remove meta object support
610-
//-----------------------------------------------
609+
// -----------------------------------------------
611610
@Test
612611
public void removePropertyViaDataObject_saveDelta() {
613612

@@ -622,10 +621,11 @@ public void removePropertyViaDataObject_saveDelta() {
622621
// Lets get the first object
623622
DataObject testObject = oRes[0];
624623
String oid = testObject._oid();
624+
625625
testObject.remove("num");
626626
testObject.remove("str_val");
627627
testObject.saveDelta();
628-
628+
629629
// Get the object again
630630
DataObject changedObject = mtObj.get(oid);
631631
assertNotNull( changedObject );
@@ -640,7 +640,7 @@ public void removePropertyViaDataObject_saveAll() {
640640

641641
// Lets just rescycle old test for some dummy data
642642
basicTest();
643-
643+
644644
// Lets get DataObject list
645645
DataObject[] oRes = null;
646646
assertNotNull(oRes = mtObj.query(null, null));
@@ -649,10 +649,11 @@ public void removePropertyViaDataObject_saveAll() {
649649
// Lets get the first object
650650
DataObject testObject = oRes[0];
651651
String oid = testObject._oid();
652+
652653
testObject.remove("num");
653654
testObject.remove("str_val");
654655
testObject.saveAll();
655-
656+
656657
// Get the object again
657658
DataObject changedObject = mtObj.get(oid);
658659
assertNotNull( changedObject );

0 commit comments

Comments
 (0)