Search in sources :

Example 6 with NodeItem

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

the class StateHandlingStatementOperations method nodeRemoveLabel.

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

Example 7 with NodeItem

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

the class TxStateTransactionDataSnapshot method takeSnapshot.

private void takeSnapshot() {
    try {
        for (long nodeId : state.addedAndRemovedNodes().getRemoved()) {
            try (Cursor<NodeItem> node = storeStatement.acquireSingleNodeCursor(nodeId)) {
                if (node.next()) {
                    Lock lock = node.get().lock();
                    try (Cursor<PropertyItem> properties = storeStatement.acquirePropertyCursor(node.get().nextPropertyId(), lock)) {
                        while (properties.next()) {
                            removedNodeProperties.add(new NodePropertyEntryView(nodeId, store.propertyKeyGetName(properties.get().propertyKeyId()), null, properties.get().value()));
                        }
                    }
                    node.get().labels().visitKeys(labelId -> {
                        removedLabels.add(new LabelEntryView(nodeId, store.labelGetName(labelId)));
                        return false;
                    });
                }
            }
        }
        for (long relId : state.addedAndRemovedRelationships().getRemoved()) {
            Relationship relationshipProxy = relationship(relId);
            try (Cursor<RelationshipItem> relationship = storeStatement.acquireSingleRelationshipCursor(relId)) {
                if (relationship.next()) {
                    Lock lock = relationship.get().lock();
                    try (Cursor<PropertyItem> properties = storeStatement.acquirePropertyCursor(relationship.get().nextPropertyId(), lock)) {
                        while (properties.next()) {
                            removedRelationshipProperties.add(new RelationshipPropertyEntryView(relationshipProxy, store.propertyKeyGetName(properties.get().propertyKeyId()), null, properties.get().value()));
                        }
                    }
                }
            }
        }
        for (NodeState nodeState : state.modifiedNodes()) {
            Iterator<StorageProperty> added = nodeState.addedAndChangedProperties();
            while (added.hasNext()) {
                DefinedProperty property = (DefinedProperty) added.next();
                assignedNodeProperties.add(new NodePropertyEntryView(nodeState.getId(), store.propertyKeyGetName(property.propertyKeyId()), property.value(), committedValue(nodeState, property.propertyKeyId())));
            }
            Iterator<Integer> removed = nodeState.removedProperties();
            while (removed.hasNext()) {
                Integer property = removed.next();
                removedNodeProperties.add(new NodePropertyEntryView(nodeState.getId(), store.propertyKeyGetName(property), null, committedValue(nodeState, property)));
            }
            ReadableDiffSets<Integer> labels = nodeState.labelDiffSets();
            for (Integer label : labels.getAdded()) {
                assignedLabels.add(new LabelEntryView(nodeState.getId(), store.labelGetName(label)));
            }
            for (Integer label : labels.getRemoved()) {
                removedLabels.add(new LabelEntryView(nodeState.getId(), store.labelGetName(label)));
            }
        }
        for (RelationshipState relState : state.modifiedRelationships()) {
            Relationship relationship = relationship(relState.getId());
            Iterator<StorageProperty> added = relState.addedAndChangedProperties();
            while (added.hasNext()) {
                DefinedProperty property = (DefinedProperty) added.next();
                assignedRelationshipProperties.add(new RelationshipPropertyEntryView(relationship, store.propertyKeyGetName(property.propertyKeyId()), property.value(), committedValue(relState, property.propertyKeyId())));
            }
            Iterator<Integer> removed = relState.removedProperties();
            while (removed.hasNext()) {
                Integer property = removed.next();
                removedRelationshipProperties.add(new RelationshipPropertyEntryView(relationship, store.propertyKeyGetName(property), null, committedValue(relState, property)));
            }
        }
    } catch (PropertyKeyIdNotFoundKernelException | LabelNotFoundKernelException e) {
        throw new IllegalStateException("An entity that does not exist was modified.", e);
    }
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) NodeState(org.neo4j.storageengine.api.txstate.NodeState) LabelNotFoundKernelException(org.neo4j.kernel.api.exceptions.LabelNotFoundKernelException) RelationshipState(org.neo4j.storageengine.api.txstate.RelationshipState) Lock(org.neo4j.kernel.impl.locking.Lock) PropertyKeyIdNotFoundKernelException(org.neo4j.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException) NodeItem(org.neo4j.storageengine.api.NodeItem) PropertyItem(org.neo4j.storageengine.api.PropertyItem) Relationship(org.neo4j.graphdb.Relationship) StorageProperty(org.neo4j.storageengine.api.StorageProperty) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem)

Example 8 with NodeItem

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

the class NodeProxy method getAllProperties.

@Override
public Map<String, Object> getAllProperties() {
    try (Statement statement = actions.statement()) {
        try (Cursor<NodeItem> node = statement.readOperations().nodeCursorById(nodeId)) {
            try (Cursor<PropertyItem> propertyCursor = statement.readOperations().nodeGetProperties(node.get())) {
                Map<String, Object> properties = new HashMap<>();
                // Get all properties
                while (propertyCursor.next()) {
                    String name = statement.readOperations().propertyKeyGetName(propertyCursor.get().propertyKeyId());
                    properties.put(name, propertyCursor.get().value());
                }
                return properties;
            }
        } catch (EntityNotFoundException e) {
            throw new NotFoundException("Node not found", e);
        }
    } catch (PropertyKeyIdNotFoundKernelException e) {
        throw new IllegalStateException("Property key retrieved through kernel API should exist.", e);
    }
}
Also used : HashMap(java.util.HashMap) Statement(org.neo4j.kernel.api.Statement) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) PropertyNotFoundException(org.neo4j.kernel.api.exceptions.PropertyNotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) PropertyKeyIdNotFoundKernelException(org.neo4j.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException) NodeItem(org.neo4j.storageengine.api.NodeItem) PropertyItem(org.neo4j.storageengine.api.PropertyItem)

Example 9 with NodeItem

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

the class KernelIT method txReturnsCorrectIdWhenReadOnly.

@Test
public void txReturnsCorrectIdWhenReadOnly() throws Exception {
    executeDummyTxs(db, 42);
    KernelTransaction tx = kernel.newTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED);
    try (Statement statement = tx.acquireStatement();
        Cursor<NodeItem> cursor = statement.readOperations().nodeCursorById(1)) {
    }
    tx.success();
    assertEquals(KernelTransaction.READ_ONLY, tx.closeTransaction());
    assertFalse(tx.isOpen());
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeItem(org.neo4j.storageengine.api.NodeItem) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 10 with NodeItem

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

the class ConstraintEnforcingEntityOperations method nodeAddLabel.

@Override
public boolean nodeAddLabel(KernelStatement state, long nodeId, int labelId) throws EntityNotFoundException, ConstraintValidationException {
    try (Cursor<NodeItem> cursor = nodeCursorById(state, nodeId)) {
        NodeItem node = cursor.get();
        Iterator<ConstraintDescriptor> constraints = schemaReadOperations.constraintsGetForLabel(state, labelId);
        while (constraints.hasNext()) {
            ConstraintDescriptor constraint = constraints.next();
            if (constraint.type() == UNIQUE) {
                UniquenessConstraintDescriptor uniqueConstraint = (UniquenessConstraintDescriptor) constraint;
                ExactPredicate[] propertyValues = getAllPropertyValues(state, uniqueConstraint.schema(), node);
                if (propertyValues != null) {
                    validateNoExistingNodeWithExactValues(state, uniqueConstraint, propertyValues, node.id());
                }
            }
        }
    }
    return entityWriteOperations.nodeAddLabel(state, nodeId, labelId);
}
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) ExactPredicate(org.neo4j.kernel.api.schema_new.IndexQuery.ExactPredicate)

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