Skip to content

Commit

Permalink
Fix issue with consistency checks on maps and propagate returnOnlyCha…
Browse files Browse the repository at this point in the history
…ngedValues to nested backed models
  • Loading branch information
Ndiritu committed Sep 11, 2024
1 parent cde4c39 commit 70bc888
Showing 1 changed file with 49 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,19 @@ public void setIsInitializationCompleted(final boolean value) {
if (isCollectionValue(wrapper)) {
final Pair<?, Integer> collectionTuple = (Pair<?, Integer>) wrapper.getValue1();
Object[] items = getObjectArrayFromCollectionWrapper(collectionTuple);

for (final Object item : items) {
if (!(item instanceof BackedModel)) break;

BackedModel backedModel = (BackedModel) item;
backedModel
.getBackingStore()
.setIsInitializationCompleted(value); // propagate initialization
final boolean isCollection = collectionTuple.getValue0() instanceof Collection;

// No need to iterate over collection if first item is not BackedModel
if ((isCollection && items.length != 0 && items[0] instanceof BackedModel)
|| !isCollection) {
for (final Object item : items) {
if (item instanceof BackedModel) {
BackedModel backedModel = (BackedModel) item;
backedModel
.getBackingStore()
.setIsInitializationCompleted(value); // propagate initialization
}
}
}
}
}
Expand All @@ -89,6 +94,32 @@ public boolean getIsInitializationCompleted() {

public void setReturnOnlyChangedValues(final boolean value) {
this.returnOnlyChangedValues = value;
// propagate to nested backed models
for (final Map.Entry<String, Pair<Boolean, Object>> entry : this.store.entrySet()) {
final Pair<Boolean, Object> wrapper = entry.getValue();
if (wrapper.getValue1() instanceof BackedModel) {
final BackedModel item = (BackedModel) wrapper.getValue1();
item.getBackingStore().setReturnOnlyChangedValues(value);
}
if (isCollectionValue(wrapper)) {
final Pair<?, Integer> collectionTuple = (Pair<?, Integer>) wrapper.getValue1();
Object[] items = getObjectArrayFromCollectionWrapper(collectionTuple);
final boolean isCollection = collectionTuple.getValue0() instanceof Collection;

// No need to iterate over collection if first item is not BackedModel
if ((isCollection && items.length != 0 && items[0] instanceof BackedModel)
|| !isCollection) {
for (final Object item : items) {
if (item instanceof BackedModel) {
BackedModel backedModel = (BackedModel) item;
backedModel
.getBackingStore()
.setReturnOnlyChangedValues(value);
}
}
}
}
}
}

public boolean getReturnOnlyChangedValues() {
Expand Down Expand Up @@ -243,9 +274,16 @@ private void ensureCollectionPropertiesAreConsistent() {
if (isCollectionValue(wrapper)) {
final Pair<?, Integer> collectionTuple = (Pair<?, Integer>) wrapper.getValue1();
Object[] items = getObjectArrayFromCollectionWrapper(collectionTuple);
for (final Object item : items) {
if (!(item instanceof BackedModel)) break;
nestedBackedModelsToEnumerate.add((BackedModel) item);
final boolean isCollection = collectionTuple.getValue0() instanceof Collection;
// No need to iterate over collection if first item is not BackedModel
if ((isCollection && items.length != 0 && items[0] instanceof BackedModel)
|| !isCollection) {
for (final Object item : items) {
if (item instanceof BackedModel) {
final BackedModel backedModel = (BackedModel) item;
nestedBackedModelsToEnumerate.add(backedModel);
}
}
}
if (collectionTuple.getValue1()
!= items.length) { // and the size has changed since we last updated
Expand Down

0 comments on commit 70bc888

Please sign in to comment.