Search in sources :

Example 1 with RelationshipItem

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

the class NeoStoresTest method validateAndCountRelationships.

private int validateAndCountRelationships(long node, long rel1, long rel2, int relType1, int relType2) throws IOException {
    int count = 0;
    try (KernelStatement statement = (KernelStatement) tx.acquireStatement();
        Cursor<NodeItem> nodeCursor = statement.getStoreStatement().acquireSingleNodeCursor(node)) {
        nodeCursor.next();
        NodeItem nodeItem = nodeCursor.get();
        try (Cursor<RelationshipItem> relationships = statement.getStoreStatement().acquireNodeRelationshipCursor(nodeItem.isDense(), nodeItem.id(), nodeItem.nextRelationshipId(), BOTH, ALWAYS_TRUE_INT)) {
            while (relationships.next()) {
                long rel = relationships.get().id();
                if (rel == rel1) {
                    assertEquals(node, relationships.get().startNode());
                    assertEquals(relType1, relationships.get().type());
                } else if (rel == rel2) {
                    assertEquals(node, relationships.get().endNode());
                    assertEquals(relType2, relationships.get().type());
                } else {
                    throw new IOException();
                }
                count++;
            }
        }
    }
    return count;
}
Also used : NodeItem(org.neo4j.storageengine.api.NodeItem) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem)

Example 2 with RelationshipItem

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

the class NeoStoresTest method validateNodeRel2.

private void validateNodeRel2(final long node, DefinedProperty prop1, DefinedProperty prop2, DefinedProperty prop3, long rel1, long rel2, final int relType1, final int relType2) throws IOException, RuntimeException {
    assertTrue(nodeExists(node));
    ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
    propertyLoader.nodeLoadProperties(node, newPropertyReceiver(props));
    int count = 0;
    for (int keyId : props.keySet()) {
        long id = props.get(keyId).other();
        PropertyRecord record = getRecord(pStore, id);
        PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
        DefinedProperty data = block.newPropertyData(pStore);
        if (data.propertyKeyId() == prop1.propertyKeyId()) {
            assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals("string2", data.value());
            nodeAddProperty(node, prop1.propertyKeyId(), "-string2");
        } else if (data.propertyKeyId() == prop2.propertyKeyId()) {
            assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(2, data.value());
            nodeAddProperty(node, prop2.propertyKeyId(), -2);
        } else if (data.propertyKeyId() == prop3.propertyKeyId()) {
            assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(false, data.value());
            nodeAddProperty(node, prop3.propertyKeyId(), true);
        } else {
            throw new IOException();
        }
        count++;
    }
    assertEquals(3, count);
    count = 0;
    try (KernelStatement statement = (KernelStatement) tx.acquireStatement();
        Cursor<NodeItem> nodeCursor = statement.getStoreStatement().acquireSingleNodeCursor(node)) {
        nodeCursor.next();
        NodeItem nodeItem = nodeCursor.get();
        try (Cursor<RelationshipItem> relationships = statement.getStoreStatement().acquireNodeRelationshipCursor(nodeItem.isDense(), nodeItem.id(), nodeItem.nextRelationshipId(), BOTH, ALWAYS_TRUE_INT)) {
            while (relationships.next()) {
                long rel = relationships.get().id();
                if (rel == rel1) {
                    assertEquals(node, relationships.get().endNode());
                    assertEquals(relType1, relationships.get().type());
                } else if (rel == rel2) {
                    assertEquals(node, relationships.get().startNode());
                    assertEquals(relType2, relationships.get().type());
                } else {
                    throw new IOException();
                }
                count++;
            }
        }
    }
    assertEquals(2, count);
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) NodeItem(org.neo4j.storageengine.api.NodeItem) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem) Pair(org.neo4j.helpers.collection.Pair)

Example 3 with RelationshipItem

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

the class StateHandlingStatementOperations method nodeGetRelationships.

@Override
public Cursor<RelationshipItem> nodeGetRelationships(KernelStatement statement, NodeItem node, Direction direction) {
    Cursor<RelationshipItem> cursor;
    if (statement.hasTxStateWithChanges() && statement.txState().nodeIsAddedInThisTx(node.id())) {
        cursor = empty();
    } else {
        cursor = storeLayer.nodeGetRelationships(statement.getStoreStatement(), node, direction);
    }
    if (!statement.hasTxStateWithChanges()) {
        return cursor;
    }
    NodeState nodeState = statement.txState().getNodeState(node.id());
    return statement.txState().augmentNodeRelationshipCursor(cursor, nodeState, direction);
}
Also used : NodeState(org.neo4j.storageengine.api.txstate.NodeState) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem)

Example 4 with RelationshipItem

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

the class TxIteratorRelationshipCursor method next.

@Override
public boolean next() {
    if (added == null) {
        while (cursor.next()) {
            RelationshipItem relationshipItem = cursor.get();
            long id = relationshipItem.id();
            if (state.relationshipIsDeletedInThisTx(id)) {
                continue;
            }
            visit(id, relationshipItem.type(), relationshipItem.startNode(), relationshipItem.endNode());
            relationshipState = state.getRelationshipState(relationshipItem.id());
            return true;
        }
        added = addedRelationshipIterator;
        relationshipIsAddedInThisTx = true;
    }
    if (added.hasNext()) {
        relationshipState = state.getRelationshipState(added.next());
        relationshipState.accept(this);
        return true;
    } else {
        visit(-1, -1, -1, -1);
        relationshipState = null;
        return false;
    }
}
Also used : RelationshipItem(org.neo4j.storageengine.api.RelationshipItem)

Example 5 with RelationshipItem

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

the class TxSingleRelationshipCursor method next.

@Override
public boolean next() {
    if (state.relationshipIsDeletedInThisTx(nextId)) {
        visit(StatementConstants.NO_SUCH_RELATIONSHIP, StatementConstants.NO_SUCH_RELATIONSHIP_TYPE, StatementConstants.NO_SUCH_NODE, StatementConstants.NO_SUCH_NODE);
        nextId = StatementConstants.NO_SUCH_RELATIONSHIP;
        return false;
    }
    boolean exists = cursor.next();
    this.relationshipIsAddedInThisTx = state.relationshipIsAddedInThisTx(nextId);
    if (exists || relationshipIsAddedInThisTx) {
        if (relationshipIsAddedInThisTx) {
            state.relationshipVisit(nextId, this);
        } else {
            RelationshipItem relationshipItem = cursor.get();
            visit(nextId, relationshipItem.type(), relationshipItem.startNode(), relationshipItem.endNode());
        }
        relationshipState = state.getRelationshipState(nextId);
        return true;
    } else {
        visit(StatementConstants.NO_SUCH_RELATIONSHIP, StatementConstants.NO_SUCH_RELATIONSHIP_TYPE, StatementConstants.NO_SUCH_NODE, StatementConstants.NO_SUCH_NODE);
        relationshipState = null;
        nextId = StatementConstants.NO_SUCH_RELATIONSHIP;
        return false;
    }
}
Also used : RelationshipItem(org.neo4j.storageengine.api.RelationshipItem)

Aggregations

RelationshipItem (org.neo4j.storageengine.api.RelationshipItem)21 DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)7 PropertyItem (org.neo4j.storageengine.api.PropertyItem)6 NodeItem (org.neo4j.storageengine.api.NodeItem)5 Test (org.junit.Test)4 Property (org.neo4j.kernel.api.properties.Property)4 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)3 StorageProperty (org.neo4j.storageengine.api.StorageProperty)3 NodeState (org.neo4j.storageengine.api.txstate.NodeState)3 IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)2 HashMap (java.util.HashMap)2 NoSuchElementException (java.util.NoSuchElementException)2 DataWriteOperations (org.neo4j.kernel.api.DataWriteOperations)2 EntityNotFoundException (org.neo4j.kernel.api.exceptions.EntityNotFoundException)2 PropertyKeyIdNotFoundKernelException (org.neo4j.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Cursor (org.neo4j.cursor.Cursor)1 NotFoundException (org.neo4j.graphdb.NotFoundException)1 Relationship (org.neo4j.graphdb.Relationship)1