Search in sources :

Example 36 with DefinedProperty

use of org.neo4j.kernel.api.properties.DefinedProperty in project neo4j by neo4j.

the class StateOperationsAutoIndexingTest method shouldSignalRelationshipPropertyAddedToAutoIndex.

@Test
public void shouldSignalRelationshipPropertyAddedToAutoIndex() throws Exception {
    // Given
    int propertyKeyId = 1;
    DefinedProperty property = property(propertyKeyId, "Hello!");
    RelationshipItem relationship = mock(RelationshipItem.class);
    when(storeStmt.acquireSingleRelationshipCursor(1337)).thenReturn(cursor(relationship));
    when(storeLayer.relationshipGetProperty(storeStmt, relationship, propertyKeyId)).thenReturn(empty());
    // When
    context.relationshipSetProperty(stmt, 1337, property);
    // Then
    verify(relOps).propertyAdded(writeOps, 1337, property);
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem) Test(org.junit.Test)

Example 37 with DefinedProperty

use of org.neo4j.kernel.api.properties.DefinedProperty in project neo4j by neo4j.

the class StateOperationsAutoIndexingTest method shouldSignalRelationshipPropertyChangedToAutoIndex.

@Test
public void shouldSignalRelationshipPropertyChangedToAutoIndex() throws Exception {
    // Given
    int propertyKeyId = 1;
    DefinedProperty property = property(propertyKeyId, "Hello!");
    PropertyItem existingProperty = mock(PropertyItem.class);
    when(existingProperty.propertyKeyId()).thenReturn(property.propertyKeyId());
    when(existingProperty.value()).thenReturn("Goodbye!");
    RelationshipItem relationship = mock(RelationshipItem.class);
    when(storeStmt.acquireSingleRelationshipCursor(1337)).thenReturn(cursor(relationship));
    when(storeLayer.relationshipGetProperty(storeStmt, relationship, propertyKeyId)).thenReturn(cursor(existingProperty));
    // When
    context.relationshipSetProperty(stmt, 1337, property);
    // Then
    verify(relOps).propertyChanged(eq(writeOps), eq(1337L), any(Property.class), eq(property));
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) PropertyItem(org.neo4j.storageengine.api.PropertyItem) Property(org.neo4j.kernel.api.properties.Property) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem) Test(org.junit.Test)

Example 38 with DefinedProperty

use of org.neo4j.kernel.api.properties.DefinedProperty in project neo4j by neo4j.

the class StateOperationsAutoIndexingTest method shouldSignalNodePropertyAddedToAutoIndex.

@Test
public void shouldSignalNodePropertyAddedToAutoIndex() throws Exception {
    // Given
    DefinedProperty property = property(1, "Hello!");
    NodeItem node = mock(NodeItem.class);
    when(node.labels()).thenReturn(PrimitiveIntCollections.emptySet());
    when(storeStmt.acquireSingleNodeCursor(1337)).thenReturn(cursor(node));
    when(storeLayer.nodeGetProperty(eq(storeStmt), any(NodeItem.class), eq(property.propertyKeyId()))).thenReturn(cursor());
    // When
    context.nodeSetProperty(stmt, 1337, property);
    // Then
    verify(nodeOps).propertyAdded(writeOps, 1337, property);
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) NodeItem(org.neo4j.storageengine.api.NodeItem) Test(org.junit.Test)

Example 39 with DefinedProperty

use of org.neo4j.kernel.api.properties.DefinedProperty in project neo4j by neo4j.

the class TxStateTest method addNodesToIndex.

private IndexUpdater addNodesToIndex(final NewIndexDescriptor descriptor) {
    return new IndexUpdater() {

        @Override
        public void withDefaultStringProperties(long... nodeIds) {
            Collection<Pair<Long, String>> entries = new ArrayList<>(nodeIds.length);
            for (long nodeId : nodeIds) {
                entries.add(of(nodeId, "value" + nodeId));
            }
            withStringProperties(entries);
        }

        @Override
        public void withStringProperties(Collection<Pair<Long, String>> nodesWithValues) {
            final int labelId = descriptor.schema().getLabelId();
            final int propertyKeyId = descriptor.schema().getPropertyId();
            for (Pair<Long, String> entry : nodesWithValues) {
                long nodeId = entry.first();
                state.nodeDoCreate(nodeId);
                state.nodeDoAddLabel(labelId, nodeId);
                DefinedProperty propertyAfter = stringProperty(propertyKeyId, entry.other());
                state.nodeDoAddProperty(nodeId, propertyAfter);
                state.indexDoUpdateEntry(descriptor.schema(), nodeId, null, OrderedPropertyValues.ofUndefined(propertyAfter.value()));
            }
        }

        @Override
        public <T extends Number> void withNumberProperties(Collection<Pair<Long, T>> nodesWithValues) {
            final int labelId = descriptor.schema().getLabelId();
            final int propertyKeyId = descriptor.schema().getPropertyId();
            for (Pair<Long, T> entry : nodesWithValues) {
                long nodeId = entry.first();
                state.nodeDoCreate(nodeId);
                state.nodeDoAddLabel(labelId, nodeId);
                DefinedProperty propertyAfter = numberProperty(propertyKeyId, entry.other());
                state.nodeDoAddProperty(nodeId, propertyAfter);
                state.indexDoUpdateEntry(descriptor.schema(), nodeId, null, OrderedPropertyValues.ofUndefined(propertyAfter.value()));
            }
        }

        @Override
        public void withBooleanProperties(Collection<Pair<Long, Boolean>> nodesWithValues) {
            final int labelId = descriptor.schema().getLabelId();
            final int propertyKeyId = descriptor.schema().getPropertyId();
            for (Pair<Long, Boolean> entry : nodesWithValues) {
                long nodeId = entry.first();
                state.nodeDoCreate(nodeId);
                state.nodeDoAddLabel(labelId, nodeId);
                DefinedProperty propertyAfter = booleanProperty(propertyKeyId, entry.other());
                state.nodeDoAddProperty(nodeId, propertyAfter);
                state.indexDoUpdateEntry(descriptor.schema(), nodeId, null, OrderedPropertyValues.ofUndefined(propertyAfter.value()));
            }
        }
    };
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Pair(org.neo4j.helpers.collection.Pair)

Example 40 with DefinedProperty

use of org.neo4j.kernel.api.properties.DefinedProperty in project neo4j by neo4j.

the class TxStateVisitorTest method shouldSeeAddedRelationshipProperties.

@Test
public void shouldSeeAddedRelationshipProperties() throws Exception {
    // Given
    long relId = 1L;
    int propKey = 2;
    GatheringVisitor visitor = new GatheringVisitor();
    DefinedProperty prop = stringProperty(propKey, "hello");
    state.relationshipDoReplaceProperty(relId, stringProperty(propKey, ""), prop);
    // When
    state.accept(visitor);
    // Then
    assertThat(visitor.relPropertyChanges, contains(propChange(relId, noProperty, asList(prop), noRemoved)));
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) Test(org.junit.Test)

Aggregations

DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)47 Test (org.junit.Test)23 Pair (org.neo4j.helpers.collection.Pair)9 IOException (java.io.IOException)8 InterruptedIOException (java.io.InterruptedIOException)8 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)8 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)8 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)8 PropertyItem (org.neo4j.storageengine.api.PropertyItem)8 NodeItem (org.neo4j.storageengine.api.NodeItem)7 RelationshipItem (org.neo4j.storageengine.api.RelationshipItem)7 Property (org.neo4j.kernel.api.properties.Property)6 PropertyEntry (org.neo4j.graphdb.event.PropertyEntry)4 DataWriteOperations (org.neo4j.kernel.api.DataWriteOperations)4 NodeUpdates (org.neo4j.kernel.api.index.NodeUpdates)4 NeoStores (org.neo4j.kernel.impl.store.NeoStores)4 StorageProperty (org.neo4j.storageengine.api.StorageProperty)4 Node (org.neo4j.graphdb.Node)3 Relationship (org.neo4j.graphdb.Relationship)3 Statement (org.neo4j.kernel.api.Statement)3