Skip to content

Commit 03d65ba

Browse files
committed
fix: make sure to not mark document dirty if setting a property to exactly the same simple value, issue #10514
1 parent d9b141d commit 03d65ba

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

‎core/src/main/java/com/orientechnologies/orient/core/record/impl/ODocument.java‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,18 @@ public void setProperty(String iPropetyName, Object iPropertyValue, OType... iFi
538538
try {
539539
if (iPropertyValue.equals(oldValue)) {
540540
if (fieldType == oldType) {
541-
if (!(iPropertyValue instanceof ORecordElement))
541+
if (!(iPropertyValue instanceof ORecordElement)
542+
&& !OType.isSimpleType(iPropertyValue))
542543
// SAME BUT NOT TRACKABLE: SET THE RECORD AS DIRTY TO BE SURE IT'S SAVED
543544
setDirty();
544545

545546
// SAVE VALUE: UNCHANGED
546547
return;
547548
}
549+
} else if (iPropertyValue instanceof byte[]
550+
&& Arrays.equals((byte[]) iPropertyValue, (byte[]) oldValue)) {
551+
// SAVE VALUE: UNCHANGED
552+
return;
548553
}
549554
} catch (Exception e) {
550555
OLogManager.instance()
@@ -1681,7 +1686,8 @@ public ODocument field(String iFieldName, Object iPropertyValue, OType... iField
16811686
try {
16821687
if (iPropertyValue.equals(oldValue)) {
16831688
if (fieldType == oldType) {
1684-
if (!(iPropertyValue instanceof ORecordElement))
1689+
if (!(iPropertyValue instanceof ORecordElement)
1690+
&& !OType.isSimpleType(iPropertyValue))
16851691
// SAME BUT NOT TRACKABLE: SET THE RECORD AS DIRTY TO BE SURE IT'S SAVED
16861692
setDirty();
16871693

‎core/src/test/java/com/orientechnologies/orient/core/record/impl/ODocumentTest.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,5 +406,25 @@ public void testNoDirtySameBytes() {
406406
doc.field("bytes", bytes.clone());
407407
assertFalse(doc.isDirty());
408408
assertNull(doc.getOriginalValue("bytes"));
409+
410+
doc.setProperty("bytes", bytes.clone());
411+
assertFalse(doc.isDirty());
412+
assertNull(doc.getOriginalValue("bytes"));
413+
}
414+
415+
@Test
416+
public void testNoDirtySameString() {
417+
ODocument doc = new ODocument();
418+
doc.field("string", "value");
419+
ODocumentInternal.clearTrackData(doc);
420+
ORecordInternal.unsetDirty(doc);
421+
assertFalse(doc.isDirty());
422+
assertNull(doc.getOriginalValue("string"));
423+
doc.field("string", "value");
424+
assertFalse(doc.isDirty());
425+
assertNull(doc.getOriginalValue("string"));
426+
doc.setProperty("string", "value");
427+
assertFalse(doc.isDirty());
428+
assertNull(doc.getOriginalValue("string"));
409429
}
410430
}

0 commit comments

Comments
 (0)