Search in sources :

Example 16 with DataWriteOperations

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

the class PropertyIT method shouldRollbackSetNodePropertyValue.

@Test
public void shouldRollbackSetNodePropertyValue() throws Exception {
    // GIVEN
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    long nodeId = statement.dataWriteOperations().nodeCreate();
    int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("clown");
    commit();
    // WHEN
    DataWriteOperations dataWriteOperations = dataWriteOperationsInNewTransaction();
    dataWriteOperations.nodeSetProperty(nodeId, stringProperty(propertyKeyId, "bozo"));
    rollback();
    // THEN
    ReadOperations readOperations = readOperationsInNewTransaction();
    assertThat(readOperations.nodeHasProperty(nodeId, propertyKeyId), is(false));
    assertThat(readOperations.nodeGetProperty(nodeId, propertyKeyId), 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 17 with DataWriteOperations

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

the class PropertyIT method shouldUpdateNodePropertyValue.

@Test
public void shouldUpdateNodePropertyValue() throws Exception {
    // GIVEN
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    long nodeId = statement.dataWriteOperations().nodeCreate();
    int propertyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("clown");
    statement.dataWriteOperations().nodeSetProperty(nodeId, stringProperty(propertyId, "bozo"));
    commit();
    // WHEN
    DataWriteOperations dataWriteOperations = dataWriteOperationsInNewTransaction();
    dataWriteOperations.nodeSetProperty(nodeId, Property.intProperty(propertyId, 42));
    commit();
    // THEN
    ReadOperations readOperations = readOperationsInNewTransaction();
    assertEquals(42, readOperations.nodeGetProperty(nodeId, propertyId));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) DataWriteOperations(org.neo4j.kernel.api.DataWriteOperations) Statement(org.neo4j.kernel.api.Statement) 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