Search in sources :

Example 11 with NodeItem

use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.

the class StateOperationsAutoIndexingTest method shouldSignalNodePropertyChangedToAutoIndex.

@Test
public void shouldSignalNodePropertyChangedToAutoIndex() throws Exception {
    // Given
    DefinedProperty property = property(1, "Hello!");
    PropertyItem existingProperty = mock(PropertyItem.class);
    when(existingProperty.propertyKeyId()).thenReturn(property.propertyKeyId());
    when(existingProperty.value()).thenReturn("Goodbye!");
    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(existingProperty));
    // When
    context.nodeSetProperty(stmt, 1337, property);
    // Then
    verify(nodeOps).propertyChanged(eq(writeOps), eq(1337L), any(Property.class), eq(property));
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) NodeItem(org.neo4j.storageengine.api.NodeItem) PropertyItem(org.neo4j.storageengine.api.PropertyItem) Property(org.neo4j.kernel.api.properties.Property) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) Test(org.junit.Test)

Example 12 with NodeItem

use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.

the class ConstraintEnforcingEntityOperations method nodeSetProperty.

@Override
public Property nodeSetProperty(KernelStatement state, long nodeId, DefinedProperty property) throws EntityNotFoundException, AutoIndexingKernelException, InvalidTransactionTypeKernelException, ConstraintValidationException {
    try (Cursor<NodeItem> cursor = nodeCursorById(state, nodeId)) {
        NodeItem node = cursor.get();
        Iterator<ConstraintDescriptor> constraints = getConstraintsInvolvingProperty(state, property.propertyKeyId());
        Iterator<UniquenessConstraintDescriptor> uniquenessConstraints = new CastingIterator<>(constraints, UniquenessConstraintDescriptor.class);
        nodeSchemaMatcher.onMatchingSchema(state, uniquenessConstraints, node, property.propertyKeyId(), constraint -> {
            validateNoExistingNodeWithExactValues(state, constraint, getAllPropertyValues(state, constraint.schema(), node, property), node.id());
        });
    }
    return entityWriteOperations.nodeSetProperty(state, nodeId, property);
}
Also used : NodeItem(org.neo4j.storageengine.api.NodeItem) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) NodeExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.NodeExistenceConstraintDescriptor) RelExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.RelExistenceConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) CastingIterator(org.neo4j.helpers.collection.CastingIterator)

Example 13 with NodeItem

use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.

the class StateHandlingStatementOperations method nodeSetProperty.

@Override
public Property nodeSetProperty(KernelStatement state, long nodeId, DefinedProperty property) throws EntityNotFoundException, InvalidTransactionTypeKernelException, AutoIndexingKernelException {
    DataWriteOperations ops = state.dataWriteOperations();
    try (Cursor<NodeItem> cursor = nodeCursorById(state, nodeId)) {
        NodeItem node = cursor.get();
        DefinedProperty existingProperty = NO_SUCH_PROPERTY;
        try (Cursor<PropertyItem> properties = nodeGetPropertyCursor(state, node, property.propertyKeyId())) {
            if (!properties.next()) {
                autoIndexing.nodes().propertyAdded(ops, nodeId, property);
            } else {
                existingProperty = Property.property(properties.get().propertyKeyId(), properties.get().value());
                autoIndexing.nodes().propertyChanged(ops, nodeId, existingProperty, property);
            }
        }
        if (existingProperty == NO_SUCH_PROPERTY) {
            state.txState().nodeDoAddProperty(node.id(), property);
            indexTxStateUpdater.onPropertyAdd(state, node, property);
            return Property.noProperty(property.propertyKeyId(), EntityType.NODE, node.id());
        } else {
            state.txState().nodeDoChangeProperty(node.id(), existingProperty, property);
            indexTxStateUpdater.onPropertyChange(state, node, existingProperty, property);
            return existingProperty;
        }
    }
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) NodeItem(org.neo4j.storageengine.api.NodeItem) DataWriteOperations(org.neo4j.kernel.api.DataWriteOperations) PropertyItem(org.neo4j.storageengine.api.PropertyItem)

Example 14 with NodeItem

use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.

the class StateHandlingStatementOperations method nodeAddLabel.

@Override
public boolean nodeAddLabel(KernelStatement state, long nodeId, int labelId) throws EntityNotFoundException {
    try (Cursor<NodeItem> cursor = nodeCursorById(state, nodeId)) {
        NodeItem node = cursor.get();
        if (node.hasLabel(labelId)) {
            // Label is already in state or in store, no-op
            return false;
        }
        state.txState().nodeDoAddLabel(labelId, node.id());
        indexTxStateUpdater.onLabelChange(state, labelId, node, ADDED_LABEL);
        return true;
    }
}
Also used : NodeItem(org.neo4j.storageengine.api.NodeItem)

Example 15 with NodeItem

use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.

the class LabelsAcceptanceTest method shouldAllowManyLabelsAndPropertyCursor.

@Test
public void shouldAllowManyLabelsAndPropertyCursor() throws Exception {
    int propertyCount = 10;
    int labelCount = 15;
    GraphDatabaseAPI db = dbRule.getGraphDatabaseAPI();
    Node node;
    try (Transaction tx = db.beginTx()) {
        node = db.createNode();
        for (int i = 0; i < propertyCount; i++) {
            node.setProperty("foo" + i, "bar");
        }
        for (int i = 0; i < labelCount; i++) {
            node.addLabel(label("label" + i));
        }
        tx.success();
    }
    Set<Integer> seenProperties = new HashSet<>();
    Set<Integer> seenLabels = new HashSet<>();
    try (Transaction tx = db.beginTx()) {
        DependencyResolver resolver = db.getDependencyResolver();
        ThreadToStatementContextBridge bridge = resolver.resolveDependency(ThreadToStatementContextBridge.class);
        try (Statement statement = bridge.getTopLevelTransactionBoundToThisThread(true).acquireStatement()) {
            try (Cursor<NodeItem> nodeCursor = statement.readOperations().nodeCursorById(node.getId())) {
                try (Cursor<PropertyItem> properties = statement.readOperations().nodeGetProperties(nodeCursor.get())) {
                    while (properties.next()) {
                        seenProperties.add(properties.get().propertyKeyId());
                        consume(nodeCursor.get().labels().iterator(), seenLabels::add);
                    }
                }
            }
        }
        tx.success();
    }
    assertEquals(propertyCount, seenProperties.size());
    assertEquals(labelCount, seenLabels.size());
}
Also used : Statement(org.neo4j.kernel.api.Statement) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) NodeItem(org.neo4j.storageengine.api.NodeItem) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) PropertyItem(org.neo4j.storageengine.api.PropertyItem) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

NodeItem (org.neo4j.storageengine.api.NodeItem)25 PropertyItem (org.neo4j.storageengine.api.PropertyItem)10 DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)8 Test (org.junit.Test)6 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)6 RelationshipItem (org.neo4j.storageengine.api.RelationshipItem)6 Statement (org.neo4j.kernel.api.Statement)5 PrimitiveIntSet (org.neo4j.collection.primitive.PrimitiveIntSet)4 EntityNotFoundException (org.neo4j.kernel.api.exceptions.EntityNotFoundException)4 DataWriteOperations (org.neo4j.kernel.api.DataWriteOperations)3 PropertyKeyIdNotFoundKernelException (org.neo4j.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)3 ConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor)3 NodeExistenceConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.NodeExistenceConstraintDescriptor)3 RelExistenceConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.RelExistenceConstraintDescriptor)3 UniquenessConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor)3 StorageStatement (org.neo4j.storageengine.api.StorageStatement)3 IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)2 Before (org.junit.Before)2 Cursor (org.neo4j.cursor.Cursor)2