Search in sources :

Example 1 with DataWriteOperations

use of org.neo4j.kernel.api.DataWriteOperations in project neo4j by neo4j.

the class NodeGetUniqueFromIndexSeekIT method createNodeWithValues.

private long createNodeWithValues(String value1, String value2) throws KernelException {
    DataWriteOperations dataStatement = dataWriteOperationsInNewTransaction();
    long nodeId = dataStatement.nodeCreate();
    dataStatement.nodeAddLabel(nodeId, labelId);
    dataStatement.nodeSetProperty(nodeId, Property.stringProperty(propertyId1, value1));
    dataStatement.nodeSetProperty(nodeId, Property.stringProperty(propertyId2, value2));
    commit();
    return nodeId;
}
Also used : DataWriteOperations(org.neo4j.kernel.api.DataWriteOperations)

Example 2 with DataWriteOperations

use of org.neo4j.kernel.api.DataWriteOperations in project neo4j by neo4j.

the class PropertyIT method shouldBeAbleToRemoveResetAndTwiceRemovePropertyOnNode.

@Test
public void shouldBeAbleToRemoveResetAndTwiceRemovePropertyOnNode() throws Exception {
    // given
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    int prop = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("foo");
    long node = statement.dataWriteOperations().nodeCreate();
    statement.dataWriteOperations().nodeSetProperty(node, property(prop, "bar"));
    commit();
    // when
    DataWriteOperations dataWriteOperations = dataWriteOperationsInNewTransaction();
    dataWriteOperations.nodeRemoveProperty(node, prop);
    dataWriteOperations.nodeSetProperty(node, property(prop, "bar"));
    dataWriteOperations.nodeRemoveProperty(node, prop);
    dataWriteOperations.nodeRemoveProperty(node, prop);
    commit();
    // then
    ReadOperations readOperations = readOperationsInNewTransaction();
    assertThat(readOperations.nodeGetProperty(node, prop), nullValue());
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) DataWriteOperations(org.neo4j.kernel.api.DataWriteOperations) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 3 with DataWriteOperations

use of org.neo4j.kernel.api.DataWriteOperations 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 4 with DataWriteOperations

use of org.neo4j.kernel.api.DataWriteOperations 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 5 with DataWriteOperations

use of org.neo4j.kernel.api.DataWriteOperations 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

DataWriteOperations (org.neo4j.kernel.api.DataWriteOperations)17 Test (org.junit.Test)11 Statement (org.neo4j.kernel.api.Statement)6 ReadOperations (org.neo4j.kernel.api.ReadOperations)4 DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)4 PropertyItem (org.neo4j.storageengine.api.PropertyItem)4 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)2 TransactionHook (org.neo4j.kernel.api.TransactionHook)2 Property (org.neo4j.kernel.api.properties.Property)2 NodeItem (org.neo4j.storageengine.api.NodeItem)2 RelationshipItem (org.neo4j.storageengine.api.RelationshipItem)2 StorageProperty (org.neo4j.storageengine.api.StorageProperty)2 StorageStatement (org.neo4j.storageengine.api.StorageStatement)2 StoreReadLayer (org.neo4j.storageengine.api.StoreReadLayer)2 ReadableTransactionState (org.neo4j.storageengine.api.txstate.ReadableTransactionState)2 Transaction (org.neo4j.graphdb.Transaction)1 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)1 DoubleLatch (org.neo4j.test.DoubleLatch)1