- case MERGE:
- if(currentMeta.isPresent()) {
- return modification.storeSnapshot(Optional.of(applyMerge(modification,currentMeta.get(), version)));
- }
- // intentional fall-through: if the node does not exist a merge is same as a write
- case WRITE:
- return modification.storeSnapshot(Optional.of(applyWrite(modification, currentMeta, version)));
- case UNMODIFIED:
- return currentMeta;
- default:
- throw new IllegalArgumentException("Provided modification type is not supported.");
+ case MERGE:
+ final TreeNode result;
+
+ if (!currentMeta.isPresent()) {
+ // This is a slight optimization: a merge on a non-existing node equals to a write. Written data
+ // structure is usually verified when the transaction is sealed. To preserve correctness, we have
+ // to run that validation here.
+ modification.resolveModificationType(ModificationType.WRITE);
+ result = applyWrite(modification, modification.getWrittenValue(), currentMeta, version);
+ fullVerifyStructure(result.getData());
+ } else {
+ result = applyMerge(modification, currentMeta.get(), version);
+ }
+
+ return modification.setSnapshot(Optional.of(result));
+ case WRITE:
+ modification.resolveModificationType(ModificationType.WRITE);
+ return modification.setSnapshot(Optional.of(applyWrite(modification,
+ verifyNotNull(modification.getWrittenValue()), currentMeta, version)));
+ case NONE:
+ modification.resolveModificationType(ModificationType.UNMODIFIED);
+ return currentMeta;
+ default:
+ throw new IllegalArgumentException("Provided modification type is not supported.");