/** * Make both objects contained in the changed object filtered. * * @param change to decorate with filtering property containers. * @return decorated change. */ protected final Change<T> filteredChange(Change<T> change) { return new Change<>(filtered(change.getPrevious()), filtered(change.getCurrent())); } }
/** * Convert a collection of {@link Change}s of {@link PropertyContainer} to a map of {@link Change}s keyed by the * {@link PropertyContainer} ID. * * @param changes to convert. * @param <T> type of the {@link PropertyContainer}. * @return map keyed by {@link PropertyContainer} ID with the actual {@link Change}s as values. * @throws IllegalArgumentException in case the two {@link PropertyContainer}s contained in a {@link Change} do not * have the same IDs. */ public static <T extends PropertyContainer> Map<Long, Change<T>> changesToMap(Collection<Change<T>> changes) { Map<Long, Change<T>> result = new HashMap<>(); for (Change<T> change : changes) { long id = id(change.getPrevious()); if (id != id(change.getCurrent())) { throw new IllegalArgumentException("IDs of the Property Containers in Change do not match!"); } result.put(id, change); } return result; }
/** * {@inheritDoc} */ @Override protected Relationship fetchNextOrNull() { while (wrappedIterator.hasNext()) { Relationship next = wrappedIterator.next(); if (transactionDataContainer.getRelationshipTransactionData().hasBeenCreated(next)) { //just created - wasn't there before the TX started continue; } if (transactionDataContainer.getRelationshipTransactionData().hasBeenChanged(next)) { return transactionDataContainer.getRelationshipTransactionData().getChanged(next).getPrevious(); } return new RelationshipSnapshot(next, transactionDataContainer); } if (deletedRelationshipIterator.hasNext()) { return deletedRelationshipIterator.next(); } return null; } }
changedProperties.put(id(container), new HashMap<String, Change<Object>>()); changedProperties.get(id(container)).put(propertyEntry.key(), new Change<>(propertyEntry.previouslyCommitedValue(), propertyEntry.value()));
/** * Filter changed property containers according to provided strategies. Only those complying with the provided * {@link PropertyContainerInclusionStrategy} with at least one property created, deleted, or changed that complies * with the provided {@link PropertyInclusionStrategy} will be returned. * * @param toFilter changed property containers to filter. * @return filtered changed property containers. */ protected final Collection<Change<T>> filterChangedPropertyContainers(Collection<Change<T>> toFilter) { Collection<Change<T>> result = new HashSet<>(); for (Change<T> candidate : toFilter) { if (getPropertyContainerInclusionStrategy().include(candidate.getPrevious()) || getPropertyContainerInclusionStrategy().include(candidate.getCurrent())) { if (!createdProperties(candidate.getPrevious()).isEmpty() || !deletedProperties(candidate.getPrevious()).isEmpty() || !changedProperties(candidate.getPrevious()).isEmpty()) { result.add(filteredChange(candidate)); } } } return result; }
/** * {@inheritDoc} */ @Override public Object getProperty(String key) { if (!hasProperty(key)) { throw new NotFoundException("Snapshot of " + wrapped.toString() + " did not have a property with key " + key); } if (transactionData().hasBeenDeleted(wrapped)) { return transactionData().propertiesOfDeletedContainer(wrapped).get(key); } if (transactionData().hasBeenChanged(wrapped)) { if (transactionData().hasPropertyBeenChanged(wrapped, key)) { return transactionData().changedProperties(wrapped).get(key).getPrevious(); } if (transactionData().hasPropertyBeenDeleted(wrapped, key)) { return transactionData().deletedProperties(wrapped).get(key); } } return wrapped.getProperty(key); }
private void initializeChanged() { initializeCreated(); initializeDeleted(); if (changed == null) { changed = new HashMap<>(); for (PropertyEntry<T> propertyEntry : assignedProperties()) { if (hasNotActuallyChanged(propertyEntry)) { continue; } T candidate = propertyEntry.entity(); if (!hasBeenCreated(candidate) && !changed.containsKey(id(candidate))) { Change<T> change = new Change<>(oldSnapshot(candidate), newSnapshot(candidate)); changed.put(id(candidate), change); } } } }