void compareToRemoved( PropertyEntry<T> entry ) { basicCompareTo( entry ); try { entry.value(); fail( "Should throw IllegalStateException" ); } catch ( IllegalStateException e ) { // OK } assertNull( value() ); }
void compareToAssigned( PropertyEntry<T> entry ) { basicCompareTo( entry ); assertEqualsMaybeNull( entry.value(), value(), entry.entity(), entry.key() ); }
@Test public void shouldListAddedNodePropertiesProperties() throws Exception { // Given int propertyKeyId = ops.propertyKeyTokenHolder().getOrCreateId( "theKey" ); Value prevValue = Values.of( "prevValue" ); state.nodeDoChangeProperty( 1L, propertyKeyId, Values.of( "newValue" ) ); ops.withNode( 1, NO_LABELS, genericMap( "theKey", prevValue ) ); // When Iterable<PropertyEntry<Node>> propertyEntries = snapshot().assignedNodeProperties(); // Then PropertyEntry<Node> entry = single( propertyEntries ); assertThat( entry.key(), equalTo( "theKey" ) ); assertThat( entry.value(), equalTo( "newValue" ) ); assertThat( entry.previouslyCommitedValue(), equalTo( "prevValue" ) ); assertThat( entry.entity().getId(), equalTo( 1L ) ); }
@Test public void shouldListAddedRelationshipProperties() throws Exception { // Given Value prevValue = Values.of( "prevValue" ); int propertyKeyId = ops.propertyKeyTokenHolder().getOrCreateId( "theKey" ); state.relationshipDoReplaceProperty( 1L, propertyKeyId, prevValue, Values.of( "newValue" ) ); ops.withRelationship( 1, 0, 0, 0, genericMap( "theKey", prevValue ) ); // When Iterable<PropertyEntry<Relationship>> propertyEntries = snapshot().assignedRelationshipProperties(); // Then PropertyEntry<Relationship> entry = single( propertyEntries ); assertThat( entry.key(), equalTo( "theKey" ) ); assertThat( entry.value(), equalTo( "newValue" ) ); assertThat( entry.previouslyCommitedValue(), equalTo( "prevValue" ) ); assertThat( entry.entity().getId(), equalTo( 1L ) ); }
private static <T extends PropertyContainer> Map<String,List<Map<String,Object>>> aggregatePropertyKeys(Iterable<PropertyEntry<T>> entries, boolean nodes, boolean removed) { if (!entries.iterator().hasNext()) return Collections.emptyMap(); Map<String,List<Map<String,Object>>> result = new HashMap<>(); String entityType = nodes ? "node" : "relationship"; for (PropertyEntry<T> entry : entries) { result.compute(entry.key(), (k, v) -> { if (v == null) v = new ArrayList<>(100); Map<String, Object> map = map("key", k, entityType, entry.entity(), "old", entry.previouslyCommitedValue()); if (!removed) map.put("new", entry.value()); v.add(map); return v; }); } return result; } private static Map<String,List<Node>> aggregateLabels(Iterable<LabelEntry> labelEntries) {
private void iterateNodePropertyChange(Stream<PropertyEntry<Node>> stream, boolean propertyRemoved, IndexFunction<Index<Node>, Node, String, Object, Object> function) { stream.forEach(nodePropertyEntry -> { final Node entity = nodePropertyEntry.entity(); final String key = nodePropertyEntry.key(); final Object value = propertyRemoved ? null : nodePropertyEntry.value(); entity.getLabels().forEach(label -> { final String labelName = label.name(); final Map<String, Collection<Index<Node>>> propertyIndexMap = indexesByLabelAndProperty.get(labelName); if (propertyIndexMap!=null) { final Collection<Index<Node>> indices = propertyIndexMap.get(key); if (indices!= null) { for (Index<Node> index : indices) { String indexKey = labelName + "." + key; function.apply(index, entity, indexKey, value, nodePropertyEntry.previouslyCommitedValue()); } } } }); }); }
private boolean hasNotActuallyChanged(PropertyEntry<T> propertyEntry) { return propertyEntry.previouslyCommitedValue() != null && propertyEntry.previouslyCommitedValue().equals(propertyEntry.value()); } }
private boolean hasNotActuallyChanged(PropertyEntry<T> propertyEntry) { return propertyEntry.previouslyCommitedValue() != null && propertyEntry.previouslyCommitedValue().equals(propertyEntry.value()); } }
createdProperties.put(id(container), new HashMap<String, Object>()); createdProperties.get(id(container)).put(propertyEntry.key(), propertyEntry.value()); } else { if (!changedProperties.containsKey(id(container))) { changedProperties.put(id(container), new HashMap<String, Change<Object>>()); changedProperties.get(id(container)).put(propertyEntry.key(), new Change<>(propertyEntry.previouslyCommitedValue(), propertyEntry.value()));
createdProperties.put(entity.getId(), new HashMap<String, Object>()); createdProperties.get(entity.getId()).put(propertyEntry.key(), propertyEntry.value()); } else { if (!changedProperties.containsKey(entity.getId())) { changedProperties.put(entity.getId(), new HashMap<String, Change<Object>>()); changedProperties.get(entity.getId()).put(propertyEntry.key(), new Change<>(propertyEntry.previouslyCommitedValue(), propertyEntry.value()));