Search in sources :

Example 16 with ReadOperations

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

the class PropertyIT method nodeHasPropertyIfSet.

@Test
public void nodeHasPropertyIfSet() throws Exception {
    // GIVEN
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    long nodeId = statement.dataWriteOperations().nodeCreate();
    // WHEN
    int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("clown");
    statement.dataWriteOperations().nodeSetProperty(nodeId, stringProperty(propertyKeyId, "bozo"));
    // THEN
    assertThat(statement.readOperations().nodeHasProperty(nodeId, propertyKeyId), is(true));
    assertThat(statement.readOperations().nodeGetProperty(nodeId, propertyKeyId), notNullValue());
    // WHEN
    commit();
    ReadOperations readOperations = readOperationsInNewTransaction();
    // THEN
    assertThat(readOperations.nodeHasProperty(nodeId, propertyKeyId), is(true));
    assertThat(readOperations.nodeGetProperty(nodeId, propertyKeyId), notNullValue());
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 17 with ReadOperations

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

the class PropertyIT method shouldSetNodePropertyValue.

@Test
public void shouldSetNodePropertyValue() throws Exception {
    // GIVEN
    String value = "bozo";
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    long nodeId = statement.dataWriteOperations().nodeCreate();
    // WHEN
    int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("clown");
    statement.dataWriteOperations().nodeSetProperty(nodeId, stringProperty(propertyKeyId, value));
    // THEN
    assertEquals(value, statement.readOperations().nodeGetProperty(nodeId, propertyKeyId));
    // WHEN
    commit();
    ReadOperations readOperations = readOperationsInNewTransaction();
    // THEN
    assertEquals(value, readOperations.nodeGetProperty(nodeId, propertyKeyId));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 18 with ReadOperations

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

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

the class PropertyIT method shouldListAllPropertyKeys.

@Test
public void shouldListAllPropertyKeys() throws Exception {
    // given
    dbWithNoCache();
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    int prop1 = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("prop1");
    int prop2 = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("prop2");
    // when
    Iterator<Token> propIdsBeforeCommit = statement.readOperations().propertyKeyGetAllTokens();
    // then
    assertThat(asCollection(propIdsBeforeCommit), hasItems(new Token("prop1", prop1), new Token("prop2", prop2)));
    // when
    commit();
    ReadOperations readOperations = readOperationsInNewTransaction();
    Iterator<Token> propIdsAfterCommit = readOperations.propertyKeyGetAllTokens();
    // then
    assertThat(asCollection(propIdsAfterCommit), hasItems(new Token("prop1", prop1), new Token("prop2", prop2)));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Statement(org.neo4j.kernel.api.Statement) Token(org.neo4j.storageengine.api.Token) Test(org.junit.Test)

Example 20 with ReadOperations

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

the class PropertyIT method shouldRemoveSetNodePropertyAcrossTransactions.

@Test
public void shouldRemoveSetNodePropertyAcrossTransactions() throws Exception {
    // GIVEN
    int propertyKeyId;
    long nodeId;
    {
        Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
        nodeId = statement.dataWriteOperations().nodeCreate();
        propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("clown");
        statement.dataWriteOperations().nodeSetProperty(nodeId, stringProperty(propertyKeyId, "bozo"));
        commit();
    }
    {
        Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
        // WHEN
        Object previous = statement.dataWriteOperations().nodeRemoveProperty(nodeId, propertyKeyId).value();
        // THEN
        assertEquals("bozo", previous);
        assertThat(statement.readOperations().nodeGetProperty(nodeId, propertyKeyId), nullValue());
        // WHEN
        commit();
    }
    // THEN
    ReadOperations readOperations = readOperationsInNewTransaction();
    assertThat(readOperations.nodeGetProperty(nodeId, propertyKeyId), nullValue());
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Aggregations

ReadOperations (org.neo4j.kernel.api.ReadOperations)73 Test (org.junit.Test)52 Statement (org.neo4j.kernel.api.Statement)37 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)22 SchemaWriteOperations (org.neo4j.kernel.api.SchemaWriteOperations)9 KeyReadOperations (org.neo4j.kernel.impl.api.operations.KeyReadOperations)8 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)7 NotFoundException (org.neo4j.graphdb.NotFoundException)5 Transaction (org.neo4j.graphdb.Transaction)5 HashMap (java.util.HashMap)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 DataWriteOperations (org.neo4j.kernel.api.DataWriteOperations)4 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)4 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)3 Label (org.neo4j.graphdb.Label)3 RelationshipType (org.neo4j.graphdb.RelationshipType)3 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)3