Search in sources :

Example 6 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 7 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 8 with DataWriteOperations

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

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

the class KernelTransactionSecurityContextTest method shouldAllowWriteAccessInWriteOnlyMode.

@Test
public void shouldAllowWriteAccessInWriteOnlyMode() throws Throwable {
    // Given
    KernelTransactionImplementation tx = newTransaction(AnonymousContext.writeOnly());
    // When
    DataWriteOperations writes = tx.acquireStatement().dataWriteOperations();
    // Then
    assertNotNull(writes);
}
Also used : DataWriteOperations(org.neo4j.kernel.api.DataWriteOperations) Test(org.junit.Test)

Example 10 with DataWriteOperations

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

the class TransactionHookIT method shouldRecieveTxStateOnCommit.

@Test
public void shouldRecieveTxStateOnCommit() throws Exception {
    // Given
    TransactionHook hook = mock(TransactionHook.class);
    kernel.registerTransactionHook(hook);
    // When
    DataWriteOperations ops = dataWriteOperationsInNewTransaction();
    ops.nodeCreate();
    commit();
    // Then
    verify(hook).beforeCommit(any(ReadableTransactionState.class), any(KernelTransaction.class), any(StoreReadLayer.class), any(StorageStatement.class));
    verify(hook).afterCommit(any(ReadableTransactionState.class), any(KernelTransaction.class), any(TransactionHook.Outcome.class));
    verifyNoMoreInteractions(hook);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionHook(org.neo4j.kernel.api.TransactionHook) StorageStatement(org.neo4j.storageengine.api.StorageStatement) DataWriteOperations(org.neo4j.kernel.api.DataWriteOperations) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) ReadableTransactionState(org.neo4j.storageengine.api.txstate.ReadableTransactionState) Test(org.junit.Test)

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