Search in sources :

Example 6 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 7 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)

Example 8 with RelationshipItem

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

the class StateHandlingStatementOperations method relationshipDelete.

@Override
public void relationshipDelete(final KernelStatement state, long relationshipId) throws EntityNotFoundException, InvalidTransactionTypeKernelException, AutoIndexingKernelException {
    try (Cursor<RelationshipItem> cursor = relationshipCursorById(state, relationshipId)) {
        RelationshipItem relationship = cursor.get();
        // NOTE: We implicitly delegate to neoStoreTransaction via txState.legacyState here. This is because that
        // call returns modified properties, which node manager uses to update legacy tx state. This will be cleaned up
        // once we've removed legacy tx state.
        autoIndexing.relationships().entityRemoved(state.dataWriteOperations(), relationshipId);
        final TransactionState txState = state.txState();
        if (txState.relationshipIsAddedInThisTx(relationship.id())) {
            txState.relationshipDoDeleteAddedInThisTx(relationship.id());
        } else {
            txState.relationshipDoDelete(relationship.id(), relationship.type(), relationship.startNode(), relationship.endNode());
        }
    }
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem)

Example 9 with RelationshipItem

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

the class StateHandlingStatementOperations method relationshipRemoveProperty.

@Override
public Property relationshipRemoveProperty(KernelStatement state, long relationshipId, int propertyKeyId) throws EntityNotFoundException, InvalidTransactionTypeKernelException, AutoIndexingKernelException {
    DataWriteOperations ops = state.dataWriteOperations();
    try (Cursor<RelationshipItem> cursor = relationshipCursorById(state, relationshipId)) {
        RelationshipItem relationship = cursor.get();
        Property existingProperty;
        try (Cursor<PropertyItem> properties = relationshipGetPropertyCursor(state, relationship, propertyKeyId)) {
            if (!properties.next()) {
                existingProperty = Property.noProperty(propertyKeyId, EntityType.RELATIONSHIP, relationship.id());
            } else {
                existingProperty = Property.property(properties.get().propertyKeyId(), properties.get().value());
                autoIndexing.relationships().propertyRemoved(ops, relationshipId, propertyKeyId);
                state.txState().relationshipDoRemoveProperty(relationship.id(), (DefinedProperty) existingProperty);
            }
        }
        return existingProperty;
    }
}
Also used : DataWriteOperations(org.neo4j.kernel.api.DataWriteOperations) PropertyItem(org.neo4j.storageengine.api.PropertyItem) Property(org.neo4j.kernel.api.properties.Property) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) StorageProperty(org.neo4j.storageengine.api.StorageProperty) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem)

Example 10 with RelationshipItem

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

the class StateHandlingStatementOperations method relationshipSetProperty.

@Override
public Property relationshipSetProperty(KernelStatement state, long relationshipId, DefinedProperty property) throws EntityNotFoundException, InvalidTransactionTypeKernelException, AutoIndexingKernelException {
    DataWriteOperations ops = state.dataWriteOperations();
    try (Cursor<RelationshipItem> cursor = relationshipCursorById(state, relationshipId)) {
        RelationshipItem relationship = cursor.get();
        Property existingProperty;
        try (Cursor<PropertyItem> properties = relationshipGetPropertyCursor(state, relationship, property.propertyKeyId())) {
            if (!properties.next()) {
                autoIndexing.relationships().propertyAdded(ops, relationshipId, property);
                existingProperty = Property.noProperty(property.propertyKeyId(), EntityType.RELATIONSHIP, relationship.id());
            } else {
                existingProperty = Property.property(properties.get().propertyKeyId(), properties.get().value());
                autoIndexing.relationships().propertyChanged(ops, relationshipId, existingProperty, property);
            }
        }
        state.txState().relationshipDoReplaceProperty(relationship.id(), existingProperty, property);
        return existingProperty;
    }
}
Also used : DataWriteOperations(org.neo4j.kernel.api.DataWriteOperations) PropertyItem(org.neo4j.storageengine.api.PropertyItem) Property(org.neo4j.kernel.api.properties.Property) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) StorageProperty(org.neo4j.storageengine.api.StorageProperty) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem)

Aggregations

RelationshipItem (org.neo4j.storageengine.api.RelationshipItem)20 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