@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 ) ); }
@Override public void afterCommit( TransactionData data, Object state ) { for ( PropertyEntry<Node> entry : data.removedNodeProperties() ) { String key = entry.key(); Object value = entry.previouslyCommitedValue(); nodeProps.put( key, value ); } for ( PropertyEntry<Relationship> entry : data.removedRelationshipProperties() ) { relProps.put( entry.key(), entry.previouslyCommitedValue() ); } }
void basicCompareTo( PropertyEntry<T> entry ) { assertEquals( entry.entity(), entity() ); assertEquals( entry.key(), key() ); assertEqualsMaybeNull( entry.previouslyCommitedValue(), previouslyCommitedValue(), entry.entity(), entry.key() ); }
private boolean hasNotActuallyChanged(PropertyEntry<T> propertyEntry) { return propertyEntry.previouslyCommitedValue() != null && propertyEntry.previouslyCommitedValue().equals(propertyEntry.value()); } }
<T extends PropertyContainer> PropertyEntryImpl<T> fetchExpectedPropertyEntry( Map<T, Map<String, PropertyEntryImpl<T>>> map, PropertyEntry<T> entry ) { T entity = entry.entity(); boolean hasEntity = map.containsKey( entity ); if ( ignoreAdditionalData && !hasEntity ) { return null; } assertTrue( "Unexpected entity " + entry, hasEntity ); Map<String, PropertyEntryImpl<T>> innerMap = map.get( entity ); PropertyEntryImpl<T> expectedEntry = innerMap.remove( entry.key() ); if ( expectedEntry == null && ignoreAdditionalData ) { return null; } assertNotNull( "Unexpected property entry " + entry, expectedEntry ); if ( innerMap.isEmpty() ) { map.remove( entity ); } return expectedEntry; } }
/** * Inform this object about a new value of a node's property about to be set. After it has been done, * {@link #nodePropertySet(org.neo4j.graphdb.Node, String, Object)} must be called. * * @param node on which a new property value is about to be set. * @param key of the property. * @param value of the property about to be set. */ public void nodePropertyToBeSet(Node node, String key, Object value) { if (commitInProgress) { return; } IdAndKey idAndKey = new IdAndKey(node.getId(), key); Object previousValue; if (removedNodeProperties.containsKey(idAndKey)) { previousValue = removedNodeProperties.get(idAndKey).previouslyCommitedValue(); removedNodeProperties.remove(idAndKey); } else if (assignedNodeProperties.containsKey(idAndKey)) { previousValue = assignedNodeProperties.get(idAndKey).previouslyCommitedValue(); } else { previousValue = node.getProperty(key, null); } assignedNodeProperties.put(idAndKey, PropertyEntryImpl.assigned(node, key, value, previousValue)); }
@Test public void showsRemovedRelationships() throws Exception { // Given state.relationshipDoDelete( 1L, 1, 1L, 2L ); state.relationshipDoDelete( 2L, 1, 1L, 1L ); ops.withRelationship( 1, 1, 1, 2 ); ops.withRelationship( 2, 1, 1, 1, genericMap( "key", Values.of( "p") ) ); // When & Then TxStateTransactionDataSnapshot snapshot = snapshot(); assertThat( idList( snapshot.deletedRelationships() ), equalTo( asList( 1L, 2L ) ) ); assertThat( single( snapshot.removedRelationshipProperties() ).key(), equalTo( "key" ) ); }
void compareToRemoved( PropertyEntry<T> entry ) { basicCompareTo( entry ); try { entry.value(); fail( "Should throw IllegalStateException" ); } catch ( IllegalStateException e ) { // OK } assertNull( value() ); }
@Test public void shouldListRemovedRelationshipProperties() throws Exception { // Given int propertyKeyId = ops.propertyKeyTokenHolder().getOrCreateId( "theKey" ); Value prevValue = Values.of( "prevValue" ); state.relationshipDoRemoveProperty( 1L, propertyKeyId ); ops.withRelationship( 1, 0, 0, 0, genericMap( "theKey", prevValue ) ); // When Iterable<PropertyEntry<Relationship>> propertyEntries = snapshot().removedRelationshipProperties(); // Then PropertyEntry<Relationship> entry = single( propertyEntries ); assertThat( entry.key(), equalTo( "theKey" ) ); assertThat( entry.previouslyCommitedValue(), equalTo( "prevValue" ) ); assertThat( entry.entity().getId(), equalTo( 1L ) ); }
private boolean hasNotActuallyChanged(PropertyEntry<T> propertyEntry) { return propertyEntry.previouslyCommitedValue() != null && propertyEntry.previouslyCommitedValue().equals(propertyEntry.value()); } }
iterateNodePropertyChange(stream(data.removedNodeProperties()).filter(nodePropertyEntry -> !data.isDeleted(nodePropertyEntry.entity())), true, (index, node, key, value, oldValue) -> indexUpdate(state, aVoid -> { index.remove(node, key); index.remove(node, FreeTextSearch.KEY);
/** * Inform this object about a new value of a relationship's property about to be set. After it has been done, * {@link #relationshipPropertySet(org.neo4j.graphdb.Relationship, String, Object)} must be called. * * @param relationship on which a new property value is about to be set. * @param key of the property. * @param value of the property about to be set. */ public void relationshipPropertyToBeSet(Relationship relationship, String key, Object value) { if (commitInProgress) { return; } IdAndKey idAndKey = new IdAndKey(relationship.getId(), key); Object previousValue; if (removedRelationshipProperties.containsKey(idAndKey)) { previousValue = removedRelationshipProperties.get(idAndKey).previouslyCommitedValue(); removedRelationshipProperties.remove(idAndKey); } else if (assignedRelationshipProperties.containsKey(idAndKey)) { previousValue = assignedRelationshipProperties.get(idAndKey).previouslyCommitedValue(); } else { previousValue = relationship.getProperty(key, null); } assignedRelationshipProperties.put(idAndKey, PropertyEntryImpl.assigned(relationship, key, value, previousValue)); }
@Test public void showsDeletedNodes() throws Exception { // Given state.nodeDoDelete( 1L ); state.nodeDoDelete( 2L ); int labelId = 15; when( tokenRead.nodeLabelName( labelId ) ).thenReturn( "label" ); ops.withNode( 1, new long[]{labelId}, genericMap( "key", Values.of( "p" ) ) ); ops.withNode( 2, NO_LABELS ); // When & Then TxStateTransactionDataSnapshot snapshot = snapshot(); assertThat( idList( snapshot.deletedNodes() ), equalTo( asList( 1L, 2L ) ) ); assertThat( single( snapshot.removedLabels() ).label().name(), equalTo( "label" ) ); assertThat( single( snapshot.removedNodeProperties() ).key(), equalTo( "key" ) ); }
@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 ) ); }
@Test public void shouldListRemovedNodeProperties() throws Exception { // Given int propertyKeyId = ops.propertyKeyTokenHolder().getOrCreateId( "theKey" ); Value prevValue = Values.of( "prevValue" ); state.nodeDoRemoveProperty( 1L, propertyKeyId ); ops.withNode( 1, NO_LABELS, genericMap( "theKey", prevValue ) ); // When Iterable<PropertyEntry<Node>> propertyEntries = snapshot().removedNodeProperties(); // Then PropertyEntry<Node> entry = single( propertyEntries ); assertThat( entry.key(), equalTo( "theKey" ) ); assertThat( entry.previouslyCommitedValue(), equalTo( "prevValue" ) ); assertThat( entry.entity().getId(), equalTo( 1L ) ); }
private boolean hasLabel(PropertyEntry<Node> propEntry) { return hasLabel(propEntry.entity()); }
/** * Inform this object about a relationship's property about to be removed. After it has been done, * {@link #relationshipPropertyRemoved(org.neo4j.graphdb.Relationship, String)} must be called. * * @param relationship whose property is about to be removed. * @param property about to be removed. */ public void relationshipPropertyToBeRemoved(Relationship relationship, String property) { if (commitInProgress) { return; } IdAndKey idAndKey = new IdAndKey(relationship.getId(), property); if (removedRelationshipProperties.containsKey(idAndKey)) { return; } Object previousValue; if (assignedRelationshipProperties.containsKey(idAndKey)) { previousValue = assignedRelationshipProperties.get(idAndKey).previouslyCommitedValue(); assignedRelationshipProperties.remove(idAndKey); if (previousValue == null) { return; } } else { previousValue = relationship.getProperty(property, null); } removedRelationshipProperties.put(idAndKey, PropertyEntryImpl.removed(relationship, property, previousValue)); }
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) {