Search in sources :

Example 6 with PropertyItem

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

the class IndexTxStateUpdater method getOrderedPropertyValues.

private OrderedPropertyValues getOrderedPropertyValues(KernelStatement state, NodeItem node, DefinedProperty changedProperty, int[] indexPropertyIds) {
    DefinedProperty[] values = new DefinedProperty[indexPropertyIds.length];
    Cursor<PropertyItem> propertyCursor = readOps.nodeGetProperties(state, node);
    while (propertyCursor.next()) {
        PropertyItem property = propertyCursor.get();
        int k = ArrayUtils.indexOf(indexPropertyIds, property.propertyKeyId());
        if (k >= 0) {
            values[k] = indexPropertyIds[k] == changedProperty.propertyKeyId() ? changedProperty : Property.property(indexPropertyIds[k], property.value());
        }
    }
    if (changedProperty != NO_SUCH_PROPERTY) {
        int k = ArrayUtils.indexOf(indexPropertyIds, changedProperty.propertyKeyId());
        if (k >= 0) {
            values[k] = changedProperty;
        }
    }
    return OrderedPropertyValues.of(values);
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) PropertyItem(org.neo4j.storageengine.api.PropertyItem)

Example 7 with PropertyItem

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

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

the class PropertyContainerProxyHelper method getProperties.

static Map<String, Object> getProperties(Statement statement, Cursor<PropertyItem> propertyCursor, String[] keys) {
    // Create a map which is slightly larger than the list of keys
    int numberOfKeys = keys.length;
    Map<String, Object> properties = new HashMap<>((int) (numberOfKeys * 1.3f));
    // Specific properties given
    int[] propertyKeys = getPropertyKeys(statement, keys, numberOfKeys);
    int propertiesToFind = numberOfKeys;
    while (propertiesToFind > 0 && propertyCursor.next()) {
        PropertyItem propertyItem = propertyCursor.get();
        int propertyKeyId = propertyItem.propertyKeyId();
        for (int i = 0; i < propertyKeys.length; i++) {
            if (propertyKeys[i] == propertyKeyId) {
                properties.put(keys[i], propertyItem.value());
                propertiesToFind--;
                break;
            }
        }
    }
    return properties;
}
Also used : HashMap(java.util.HashMap) PropertyItem(org.neo4j.storageengine.api.PropertyItem)

Example 9 with PropertyItem

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

the class ConstraintEnforcingEntityOperations method getAllPropertyValues.

/**
     * Fetch the property values for all properties in schema for a given node. Return these as an exact predicate
     * array.
     *
     * The changedProperty is used to override the store/txState value of the property. This is used when we intend
     * to change a property, and that to verify that the post-change values do not validate some constraint.
     */
private ExactPredicate[] getAllPropertyValues(KernelStatement state, SchemaDescriptor schema, NodeItem node, DefinedProperty changedProperty) {
    int[] schemaPropertyIds = schema.getPropertyIds();
    ExactPredicate[] values = new ExactPredicate[schemaPropertyIds.length];
    int nMatched = 0;
    Cursor<PropertyItem> nodePropertyCursor = nodeGetProperties(state, node);
    int changedPropId = changedProperty.propertyKeyId();
    while (nodePropertyCursor.next()) {
        PropertyItem property = nodePropertyCursor.get();
        int nodePropertyId = property.propertyKeyId();
        int k = ArrayUtils.indexOf(schemaPropertyIds, nodePropertyId);
        if (k >= 0) {
            if (nodePropertyId != changedPropId) {
                values[k] = IndexQuery.exact(nodePropertyId, property.value());
            }
            nMatched++;
        }
    }
    if (changedPropId != NO_SUCH_PROPERTY_KEY) {
        int k = ArrayUtils.indexOf(schemaPropertyIds, changedPropId);
        if (k >= 0) {
            values[k] = IndexQuery.exact(changedPropId, changedProperty.value());
            nMatched++;
        }
    }
    if (nMatched < values.length) {
        return null;
    }
    return values;
}
Also used : PropertyItem(org.neo4j.storageengine.api.PropertyItem) ExactPredicate(org.neo4j.kernel.api.schema_new.IndexQuery.ExactPredicate)

Example 10 with PropertyItem

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

the class StateOperationsAutoIndexingTest method shouldSignalRelationshipPropertyRemovedToAutoIndex.

@Test
public void shouldSignalRelationshipPropertyRemovedToAutoIndex() throws Exception {
    // Given
    PropertyItem existingProperty = mock(PropertyItem.class);
    int propertyKeyId = 1;
    when(existingProperty.propertyKeyId()).thenReturn(propertyKeyId);
    when(existingProperty.value()).thenReturn("Goodbye!");
    RelationshipItem relationship = mock(RelationshipItem.class);
    when(storeStmt.acquireSingleRelationshipCursor(1337)).thenReturn(cursor(relationship));
    when(storeLayer.relationshipGetProperty(storeStmt, relationship, propertyKeyId)).thenReturn(cursor(existingProperty));
    // When
    context.relationshipRemoveProperty(stmt, 1337, existingProperty.propertyKeyId());
    // Then
    verify(relOps).propertyRemoved(writeOps, 1337L, existingProperty.propertyKeyId());
}
Also used : PropertyItem(org.neo4j.storageengine.api.PropertyItem) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem) Test(org.junit.Test)

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