Search in sources :

Example 11 with PropertyItem

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

the class StateOperationsAutoIndexingTest method shouldSignalNodePropertyChangedToAutoIndex.

@Test
public void shouldSignalNodePropertyChangedToAutoIndex() throws Exception {
    // Given
    DefinedProperty property = property(1, "Hello!");
    PropertyItem existingProperty = mock(PropertyItem.class);
    when(existingProperty.propertyKeyId()).thenReturn(property.propertyKeyId());
    when(existingProperty.value()).thenReturn("Goodbye!");
    NodeItem node = mock(NodeItem.class);
    when(node.labels()).thenReturn(PrimitiveIntCollections.emptySet());
    when(storeStmt.acquireSingleNodeCursor(1337)).thenReturn(cursor(node));
    when(storeLayer.nodeGetProperty(eq(storeStmt), any(NodeItem.class), eq(property.propertyKeyId()))).thenReturn(cursor(existingProperty));
    // When
    context.nodeSetProperty(stmt, 1337, property);
    // Then
    verify(nodeOps).propertyChanged(eq(writeOps), eq(1337L), any(Property.class), eq(property));
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) NodeItem(org.neo4j.storageengine.api.NodeItem) PropertyItem(org.neo4j.storageengine.api.PropertyItem) Property(org.neo4j.kernel.api.properties.Property) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) Test(org.junit.Test)

Example 12 with PropertyItem

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

the class StateHandlingStatementOperations method nodeSetProperty.

@Override
public Property nodeSetProperty(KernelStatement state, long nodeId, DefinedProperty property) 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, property.propertyKeyId())) {
            if (!properties.next()) {
                autoIndexing.nodes().propertyAdded(ops, nodeId, property);
            } else {
                existingProperty = Property.property(properties.get().propertyKeyId(), properties.get().value());
                autoIndexing.nodes().propertyChanged(ops, nodeId, existingProperty, property);
            }
        }
        if (existingProperty == NO_SUCH_PROPERTY) {
            state.txState().nodeDoAddProperty(node.id(), property);
            indexTxStateUpdater.onPropertyAdd(state, node, property);
            return Property.noProperty(property.propertyKeyId(), EntityType.NODE, node.id());
        } else {
            state.txState().nodeDoChangeProperty(node.id(), existingProperty, property);
            indexTxStateUpdater.onPropertyChange(state, node, existingProperty, property);
            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 13 with PropertyItem

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

the class RelationshipProxy method getAllProperties.

@Override
public Map<String, Object> getAllProperties() {
    try (Statement statement = actions.statement()) {
        try (Cursor<RelationshipItem> relationship = statement.readOperations().relationshipCursorById(getId())) {
            try (Cursor<PropertyItem> propertyCursor = statement.readOperations().relationshipGetProperties(relationship.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("Relationship 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) PropertyItem(org.neo4j.storageengine.api.PropertyItem) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem)

Example 14 with PropertyItem

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

the class PropertyExistenceEnforcer method properties.

private Cursor<PropertyItem> properties(RelationshipItem relationship) {
    Lock lock = relationship.lock();
    Cursor<PropertyItem> cursor = storeStatement().acquirePropertyCursor(relationship.nextPropertyId(), lock);
    return txState.augmentPropertyCursor(cursor, txState.getRelationshipState(relationship.id()));
}
Also used : PropertyItem(org.neo4j.storageengine.api.PropertyItem) Lock(org.neo4j.kernel.impl.locking.Lock)

Example 15 with PropertyItem

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

Aggregations

PropertyItem (org.neo4j.storageengine.api.PropertyItem)18 DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)8 NodeItem (org.neo4j.storageengine.api.NodeItem)8 RelationshipItem (org.neo4j.storageengine.api.RelationshipItem)6 Test (org.junit.Test)5 DataWriteOperations (org.neo4j.kernel.api.DataWriteOperations)4 Property (org.neo4j.kernel.api.properties.Property)4 Lock (org.neo4j.kernel.impl.locking.Lock)4 HashMap (java.util.HashMap)3 PropertyKeyIdNotFoundKernelException (org.neo4j.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)3 StorageProperty (org.neo4j.storageengine.api.StorageProperty)3 NotFoundException (org.neo4j.graphdb.NotFoundException)2 Statement (org.neo4j.kernel.api.Statement)2 EntityNotFoundException (org.neo4j.kernel.api.exceptions.EntityNotFoundException)2 PropertyNotFoundException (org.neo4j.kernel.api.exceptions.PropertyNotFoundException)2 PrimitiveIntSet (org.neo4j.collection.primitive.PrimitiveIntSet)1 Relationship (org.neo4j.graphdb.Relationship)1 LabelNotFoundKernelException (org.neo4j.kernel.api.exceptions.LabelNotFoundKernelException)1 ExactPredicate (org.neo4j.kernel.api.schema_new.IndexQuery.ExactPredicate)1 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)1