Skip to content
Merged
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
6 changes: 4 additions & 2 deletions teaql-core/src/main/java/io/teaql/core/ChangeSetStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ public EntityChangeSet pop() {

public Object get(EntityKey key, String field) {
for (int i = stack.size() - 1; i >= 0; i--) {
Object value = stack.get(i).get(key, field);
if (value != null) return value;
EntityChangeSet changeSet = stack.get(i);
if (changeSet.contains(key, field)) {
return changeSet.get(key, field);
}
}
return null;
}
Expand Down
5 changes: 5 additions & 0 deletions teaql-core/src/main/java/io/teaql/core/EntityChangeSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public Object get(EntityKey key, String field) {
return record != null ? record.get(field) : null;
}

boolean contains(EntityKey key, String field) {
Map<String, Object> record = changes.get(key);
return record != null && record.containsKey(field);
}

public Map<EntityKey, Map<String, Object>> changes() {
return Collections.unmodifiableMap(changes);
}
Expand Down
15 changes: 15 additions & 0 deletions teaql-core/src/test/java/io/teaql/core/ChangeSetStackTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ public void topScopeShadowsLowerScopeAndPopRestoresIt() {
assertEquals("CREATED", stack.get(ORDER, "status"));
}

@Test
public void explicitNullInTopScopeShadowsLowerValue() {
ChangeSetStack stack = new ChangeSetStack();
stack.set(ORDER, "status", "CREATED");
stack.push();
stack.set(ORDER, "status", null);

assertNull(stack.get(ORDER, "status"));

stack.pop();

assertEquals("CREATED", stack.get(ORDER, "status"));
assertNull(stack.get(ORDER, "missing"));
}

@Test
public void clearCurrentClearsOnlyTopScope() {
ChangeSetStack stack = new ChangeSetStack();
Expand Down
Loading