Search in sources :

Example 16 with NodeItem

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

the class PropertyExistenceEnforcer method validateNode.

private void validateNode(long nodeId) throws NodePropertyExistenceException {
    if (labelExistenceConstraints.isEmpty()) {
        return;
    }
    try (Cursor<NodeItem> node = nodeCursor(nodeId)) {
        if (node.next()) {
            PrimitiveIntSet labelIds = node.get().labels();
            propertyKeyIds.clear();
            try (Cursor<PropertyItem> properties = properties(node.get())) {
                while (properties.next()) {
                    propertyKeyIds.add(properties.get().propertyKeyId());
                }
            }
            for (LabelSchemaDescriptor descriptor : labelExistenceConstraints) {
                if (labelIds.contains(descriptor.getLabelId())) {
                    for (int propertyId : descriptor.getPropertyIds()) {
                        validateNodeProperty(nodeId, propertyId, descriptor);
                    }
                }
            }
        } else {
            throw new IllegalStateException(format("Node %d with changes should exist.", nodeId));
        }
    }
}
Also used : NodeItem(org.neo4j.storageengine.api.NodeItem) PropertyItem(org.neo4j.storageengine.api.PropertyItem) PrimitiveIntSet(org.neo4j.collection.primitive.PrimitiveIntSet) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)

Example 17 with NodeItem

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

the class TestMigrateToDenseNodeSupport method verifyDenseRepresentation.

private void verifyDenseRepresentation(GraphDatabaseService db, Node node, boolean dense) {
    KernelAPI kernelAPI = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(KernelAPI.class);
    try (KernelTransaction tx = kernelAPI.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
        Statement statement = tx.acquireStatement()) {
        Cursor<NodeItem> nodeCursor = statement.readOperations().nodeCursorById(node.getId());
        assertEquals(dense, nodeCursor.get().isDense());
    } catch (TransactionFailureException | IllegalArgumentException | EntityNotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) NodeItem(org.neo4j.storageengine.api.NodeItem) Statement(org.neo4j.kernel.api.Statement) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) KernelAPI(org.neo4j.kernel.api.KernelAPI)

Example 18 with NodeItem

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

the class TwoPhaseNodeForRelationshipLockingTest method returnRelationships.

static void returnRelationships(EntityReadOperations ops, KernelStatement state, long nodeId, final boolean skipFirst, final RelationshipData... relIds) throws EntityNotFoundException {
    NodeItem nodeItem = mock(NodeItem.class);
    when(ops.nodeGetRelationships(state, nodeItem, Direction.BOTH)).thenAnswer(new Answer<Cursor<RelationshipItem>>() {

        private boolean first = skipFirst;

        @Override
        public Cursor<RelationshipItem> answer(InvocationOnMock invocation) throws Throwable {
            try {
                return new Cursor<RelationshipItem>() {

                    private int i = first ? 1 : 0;

                    private RelationshipData relationshipData = null;

                    @Override
                    public boolean next() {
                        boolean next = i < relIds.length;
                        relationshipData = next ? relIds[i++] : null;
                        return next;
                    }

                    @Override
                    public RelationshipItem get() {
                        if (relationshipData == null) {
                            throw new NoSuchElementException();
                        }
                        return relationshipData.asRelationshipItem();
                    }

                    @Override
                    public void close() {
                    }
                };
            } finally {
                first = false;
            }
        }
    });
    when(ops.nodeCursorById(state, nodeId)).thenAnswer(invocationOnMock -> {
        Cursor<NodeItem> cursor = new Cursor<NodeItem>() {

            private int i = 0;

            @Override
            public boolean next() {
                return i++ == 0;
            }

            @Override
            public NodeItem get() {
                if (i != 1) {
                    throw new NoSuchElementException();
                }
                return nodeItem;
            }

            @Override
            public void close() {
            }
        };
        if (!cursor.next()) {
            throw new EntityNotFoundException(EntityType.NODE, nodeId);
        }
        return cursor;
    });
}
Also used : EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) Cursor(org.neo4j.cursor.Cursor) NodeItem(org.neo4j.storageengine.api.NodeItem) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem) NoSuchElementException(java.util.NoSuchElementException)

Example 19 with NodeItem

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

the class NodeSchemaMatcherTest method setup.

@Before
public void setup() {
    state = mock(KernelStatement.class);
    PrimitiveIntSet labels = Primitive.intSet();
    labels.add(labelId1);
    Cursor<NodeItem> nodeItemCursor = StubCursors.asNodeCursor(0, labels);
    nodeItemCursor.next();
    node = nodeItemCursor.get();
    PrimitiveIntSet defaultPropertyIds = PrimitiveIntCollections.asSet(new int[] { propId1, propId2, unIndexedPropId });
    EntityReadOperations readOps = mock(EntityReadOperations.class);
    when(readOps.nodeGetPropertyKeys(state, node)).thenReturn(defaultPropertyIds);
    when(readOps.nodeGetProperty(state, node, propId1)).thenReturn("hi1");
    when(readOps.nodeGetProperty(state, node, propId2)).thenReturn("hi2");
    when(readOps.nodeGetProperty(state, node, unIndexedPropId)).thenReturn("hi3");
    nodeSchemaMatcher = new NodeSchemaMatcher<>(readOps);
}
Also used : NodeItem(org.neo4j.storageengine.api.NodeItem) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) PrimitiveIntSet(org.neo4j.collection.primitive.PrimitiveIntSet) EntityReadOperations(org.neo4j.kernel.impl.api.operations.EntityReadOperations) Before(org.junit.Before)

Example 20 with NodeItem

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

the class IndexTxStateUpdaterTest method setup.

@Before
public void setup() {
    state = mock(KernelStatement.class);
    txState = mock(TransactionState.class);
    when(state.txState()).thenReturn(txState);
    SchemaReadOperations schemaReadOps = mock(SchemaReadOperations.class);
    when(schemaReadOps.indexesGetAll(state)).thenAnswer(x -> filter(GENERAL, indexes.iterator()));
    when(schemaReadOps.uniqueIndexesGetAll(state)).thenAnswer(x -> filter(UNIQUE, indexes.iterator()));
    when(schemaReadOps.indexesGetForLabel(state, labelId1)).thenAnswer(x -> filter(GENERAL, filter(hasLabel(labelId1), indexes.iterator())));
    when(schemaReadOps.uniqueIndexesGetForLabel(state, labelId1)).thenAnswer(x -> filter(UNIQUE, filter(hasLabel(labelId1), indexes.iterator())));
    when(schemaReadOps.indexesGetForLabel(state, labelId2)).thenAnswer(x -> filter(GENERAL, filter(hasLabel(labelId2), indexes.iterator())));
    when(schemaReadOps.uniqueIndexesGetForLabel(state, labelId2)).thenAnswer(x -> filter(UNIQUE, filter(hasLabel(labelId2), indexes.iterator())));
    PrimitiveIntSet labels = Primitive.intSet();
    labels.add(labelId1);
    labels.add(labelId2);
    Cursor<NodeItem> nodeItemCursor = StubCursors.asNodeCursor(0, labels);
    nodeItemCursor.next();
    node = nodeItemCursor.get();
    PrimitiveIntSet defaultPropertyIds = PrimitiveIntCollections.asSet(new int[] { propId1, propId2, propId3 });
    EntityReadOperations readOps = mock(EntityReadOperations.class);
    when(readOps.nodeGetPropertyKeys(state, node)).thenReturn(defaultPropertyIds);
    when(readOps.nodeGetProperties(state, node)).thenAnswer(p -> StubCursors.asPropertyCursor(Property.property(propId1, "hi1"), Property.property(propId2, "hi2"), Property.property(propId3, "hi3")));
    when(readOps.nodeGetProperty(state, node, propId1)).thenReturn("hi1");
    when(readOps.nodeGetProperty(state, node, propId2)).thenReturn("hi2");
    when(readOps.nodeGetProperty(state, node, propId3)).thenReturn("hi3");
    indexTxUpdater = new IndexTxStateUpdater(schemaReadOps, readOps);
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) NodeItem(org.neo4j.storageengine.api.NodeItem) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) SchemaReadOperations(org.neo4j.kernel.impl.api.operations.SchemaReadOperations) PrimitiveIntSet(org.neo4j.collection.primitive.PrimitiveIntSet) EntityReadOperations(org.neo4j.kernel.impl.api.operations.EntityReadOperations) Before(org.junit.Before)

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