Search in sources :

Example 1 with NodeItem

use of org.neo4j.storageengine.api.NodeItem 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 NodeItem

use of org.neo4j.storageengine.api.NodeItem 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 NodeItem

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

the class StateHandlingStatementOperations method relationshipTypes.

@Override
public PrimitiveIntSet relationshipTypes(KernelStatement statement, NodeItem node) {
    if (statement.hasTxStateWithChanges() && statement.txState().nodeIsAddedInThisTx(node.id())) {
        return statement.txState().getNodeState(node.id()).relationshipTypes();
    }
    // Read types in the current transaction
    PrimitiveIntSet types = statement.hasTxStateWithChanges() ? statement.txState().getNodeState(node.id()).relationshipTypes() : Primitive.intSet();
    // Augment with types stored on disk, minus any types where all rels of that type are deleted
    // in current tx.
    types.addAll(filter(storeLayer.relationshipTypes(statement.getStoreStatement(), node).iterator(), (current) -> !types.contains(current) && degree(statement, node, Direction.BOTH, current) > 0));
    return types;
}
Also used : LegacyIndexStore(org.neo4j.kernel.impl.index.LegacyIndexStore) InternalIndexState(org.neo4j.kernel.api.index.InternalIndexState) Arrays(java.util.Arrays) Iterators.iterator(org.neo4j.helpers.collection.Iterators.iterator) Iterators.singleOrNull(org.neo4j.helpers.collection.Iterators.singleOrNull) EMPTY(org.neo4j.storageengine.api.txstate.TxStateVisitor.EMPTY) GENERAL(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor.Filter.GENERAL) Statement(org.neo4j.kernel.api.Statement) Cursor(org.neo4j.cursor.Cursor) Direction(org.neo4j.storageengine.api.Direction) Map(java.util.Map) StorageStatement(org.neo4j.storageengine.api.StorageStatement) SchemaReadOperations(org.neo4j.kernel.impl.api.operations.SchemaReadOperations) Registers.newDoubleLongRegister(org.neo4j.register.Registers.newDoubleLongRegister) EntityOperations(org.neo4j.kernel.impl.api.operations.EntityOperations) InvalidTransactionTypeKernelException(org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException) CountsOperations(org.neo4j.kernel.impl.api.operations.CountsOperations) IndexTxStateUpdater(org.neo4j.kernel.impl.api.state.IndexTxStateUpdater) PrimitiveIntCollection(org.neo4j.collection.primitive.PrimitiveIntCollection) PropertyKeyIdNotFoundKernelException(org.neo4j.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException) LegacyIndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.legacyindex.LegacyIndexNotFoundKernelException) Primitive(org.neo4j.collection.primitive.Primitive) DataWriteOperations(org.neo4j.kernel.api.DataWriteOperations) Predicates.any(org.neo4j.function.Predicates.any) LegacyIndex(org.neo4j.kernel.api.LegacyIndex) LegacyIndexHits(org.neo4j.kernel.api.LegacyIndexHits) PrimitiveLongCollections.single(org.neo4j.collection.primitive.PrimitiveLongCollections.single) LegacyIndexWriteOperations(org.neo4j.kernel.impl.api.operations.LegacyIndexWriteOperations) Cursors.count(org.neo4j.kernel.impl.util.Cursors.count) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) PrimitiveIntCollections.filter(org.neo4j.collection.primitive.PrimitiveIntCollections.filter) IllegalTokenNameException(org.neo4j.kernel.api.exceptions.schema.IllegalTokenNameException) UNIQUE(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor.Filter.UNIQUE) PopulationProgress(org.neo4j.storageengine.api.schema.PopulationProgress) KeyWriteOperations(org.neo4j.kernel.impl.api.operations.KeyWriteOperations) CreateConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem) AutoIndexingKernelException(org.neo4j.kernel.api.exceptions.legacyindex.AutoIndexingKernelException) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) ReadableDiffSets(org.neo4j.storageengine.api.txstate.ReadableDiffSets) REMOVED_LABEL(org.neo4j.kernel.impl.api.state.IndexTxStateUpdater.LabelChangeType.REMOVED_LABEL) NewIndexDescriptorFactory(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) DoubleLongRegister(org.neo4j.register.Register.DoubleLongRegister) ConstraintDescriptorFactory(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptorFactory) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) NodeItem(org.neo4j.storageengine.api.NodeItem) Iterators.filter(org.neo4j.helpers.collection.Iterators.filter) NO_SUCH_PROPERTY(org.neo4j.kernel.api.properties.DefinedProperty.NO_SUCH_PROPERTY) AlreadyConstrainedException(org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException) ConstraintValidationException(org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException) Property(org.neo4j.kernel.api.properties.Property) PrimitiveIntIterator(org.neo4j.collection.primitive.PrimitiveIntIterator) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) PrimitiveLongResourceIterator(org.neo4j.collection.primitive.PrimitiveLongResourceIterator) NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) IndexBrokenKernelException(org.neo4j.kernel.api.exceptions.schema.IndexBrokenKernelException) RelationTypeSchemaDescriptor(org.neo4j.kernel.api.schema_new.RelationTypeSchemaDescriptor) PrimitiveLongCollections.resourceIterator(org.neo4j.collection.primitive.PrimitiveLongCollections.resourceIterator) OrderedPropertyValues(org.neo4j.kernel.api.schema_new.OrderedPropertyValues) LabelNotFoundKernelException(org.neo4j.kernel.api.exceptions.LabelNotFoundKernelException) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) String.format(java.lang.String.format) NO_SUCH_NODE(org.neo4j.kernel.api.StatementConstants.NO_SUCH_NODE) ADDED_LABEL(org.neo4j.kernel.impl.api.state.IndexTxStateUpdater.LabelChangeType.ADDED_LABEL) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) IndexEntityType(org.neo4j.kernel.impl.index.IndexEntityType) RelationshipTypeIdNotFoundKernelException(org.neo4j.kernel.api.exceptions.RelationshipTypeIdNotFoundKernelException) StorageProperty(org.neo4j.storageengine.api.StorageProperty) PrimitiveIntStack(org.neo4j.collection.primitive.PrimitiveIntStack) PropertyItem(org.neo4j.storageengine.api.PropertyItem) IndexNotApplicableKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) NodeExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.NodeExistenceConstraintDescriptor) SchemaBoundary(org.neo4j.kernel.api.schema_new.SchemaBoundary) EntityType(org.neo4j.storageengine.api.EntityType) DropIndexFailureException(org.neo4j.kernel.api.exceptions.schema.DropIndexFailureException) Token(org.neo4j.storageengine.api.Token) NotFoundException(org.neo4j.graphdb.NotFoundException) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) PropertyKeyIdIterator(org.neo4j.kernel.api.properties.PropertyKeyIdIterator) TransactionCountingStateVisitor(org.neo4j.kernel.api.txstate.TransactionCountingStateVisitor) SchemaUtil(org.neo4j.kernel.api.schema_new.SchemaUtil) SchemaDescriptor(org.neo4j.kernel.api.schema_new.SchemaDescriptor) AutoIndexing(org.neo4j.kernel.api.legacyindex.AutoIndexing) PrimitiveIntSet(org.neo4j.collection.primitive.PrimitiveIntSet) LegacyIndexReadOperations(org.neo4j.kernel.impl.api.operations.LegacyIndexReadOperations) NodeState(org.neo4j.storageengine.api.txstate.NodeState) Iterator(java.util.Iterator) Cursors.empty(org.neo4j.kernel.impl.util.Cursors.empty) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) TooManyLabelsException(org.neo4j.kernel.api.exceptions.schema.TooManyLabelsException) SchemaWriteOperations(org.neo4j.kernel.impl.api.operations.SchemaWriteOperations) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) RelExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.RelExistenceConstraintDescriptor) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) RelationshipIterator(org.neo4j.kernel.impl.api.store.RelationshipIterator) PrimitiveIntSet(org.neo4j.collection.primitive.PrimitiveIntSet)

Example 4 with NodeItem

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

the class StateHandlingStatementOperations method nodeRemoveProperty.

@Override
public Property nodeRemoveProperty(KernelStatement state, long nodeId, int propertyKeyId) 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, propertyKeyId)) {
            if (properties.next()) {
                existingProperty = Property.property(properties.get().propertyKeyId(), properties.get().value());
                autoIndexing.nodes().propertyRemoved(ops, nodeId, propertyKeyId);
                state.txState().nodeDoRemoveProperty(node.id(), existingProperty);
                indexTxStateUpdater.onPropertyRemove(state, node, existingProperty);
            }
        }
        if (existingProperty == NO_SUCH_PROPERTY) {
            return Property.noProperty(propertyKeyId, EntityType.NODE, node.id());
        }
        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 5 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)

Aggregations

NodeItem (org.neo4j.storageengine.api.NodeItem)22 PropertyItem (org.neo4j.storageengine.api.PropertyItem)9 DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)7 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)6 RelationshipItem (org.neo4j.storageengine.api.RelationshipItem)6 Test (org.junit.Test)4 PrimitiveIntSet (org.neo4j.collection.primitive.PrimitiveIntSet)4 EntityNotFoundException (org.neo4j.kernel.api.exceptions.EntityNotFoundException)4 DataWriteOperations (org.neo4j.kernel.api.DataWriteOperations)3 Statement (org.neo4j.kernel.api.Statement)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 IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)2 Before (org.junit.Before)2 Cursor (org.neo4j.cursor.Cursor)2 NotFoundException (org.neo4j.graphdb.NotFoundException)2