Search in sources :

Example 21 with Statement

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

the class BuiltInProceduresIT method listAllLabels.

@Test
public void listAllLabels() throws Throwable {
    // Given
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    long nodeId = statement.dataWriteOperations().nodeCreate();
    int labelId = statement.tokenWriteOperations().labelGetOrCreateForName("MyLabel");
    statement.dataWriteOperations().nodeAddLabel(nodeId, labelId);
    commit();
    // When
    RawIterator<Object[], ProcedureException> stream = procedureCallOpsInNewTx().procedureCallRead(procedureName("db", "labels"), new Object[0]);
    // Then
    assertThat(asList(stream), contains(equalTo(new Object[] { "MyLabel" })));
}
Also used : Statement(org.neo4j.kernel.api.Statement) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 22 with Statement

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

the class KernelIT method removingExistingLabelFromNodeShouldRespondTrue.

@Test
public void removingExistingLabelFromNodeShouldRespondTrue() throws Exception {
    // GIVEN
    Transaction tx = db.beginTx();
    Node node = db.createNode();
    Statement statement = statementContextSupplier.get();
    int labelId = statement.tokenWriteOperations().labelGetOrCreateForName("mylabel");
    statement.dataWriteOperations().nodeAddLabel(node.getId(), labelId);
    statement.close();
    tx.success();
    tx.close();
    // WHEN
    tx = db.beginTx();
    statement = statementContextSupplier.get();
    boolean removed = statement.dataWriteOperations().nodeRemoveLabel(node.getId(), labelId);
    // THEN
    assertTrue("Should have been removed now", removed);
    tx.close();
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 23 with Statement

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

the class LabelIT method shouldListAllLabels.

@Test
public void shouldListAllLabels() throws Exception {
    // given
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    int label1Id = statement.tokenWriteOperations().labelGetOrCreateForName("label1");
    int label2Id = statement.tokenWriteOperations().labelGetOrCreateForName("label2");
    // when
    Iterator<Token> labelIdsBeforeCommit = statement.readOperations().labelsGetAllTokens();
    // then
    assertThat(asCollection(labelIdsBeforeCommit), hasItems(new Token("label1", label1Id), new Token("label2", label2Id)));
    // when
    commit();
    ReadOperations readOperations = readOperationsInNewTransaction();
    Iterator<Token> labelIdsAfterCommit = readOperations.labelsGetAllTokens();
    // then
    assertThat(asCollection(labelIdsAfterCommit), hasItems(new Token("label1", label1Id), new Token("label2", label2Id)));
}
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 24 with Statement

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

the class PropertyIT method nodeHasNotPropertyIfUnset.

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

Example 25 with Statement

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

Aggregations

Statement (org.neo4j.kernel.api.Statement)158 Test (org.junit.Test)76 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)56 Transaction (org.neo4j.graphdb.Transaction)44 ReadOperations (org.neo4j.kernel.api.ReadOperations)40 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)30 EntityNotFoundException (org.neo4j.kernel.api.exceptions.EntityNotFoundException)23 NotFoundException (org.neo4j.graphdb.NotFoundException)21 Node (org.neo4j.graphdb.Node)20 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)19 PropertyNotFoundException (org.neo4j.kernel.api.exceptions.PropertyNotFoundException)13 KeyReadOperations (org.neo4j.kernel.impl.api.operations.KeyReadOperations)11 ArrayList (java.util.ArrayList)10 DependencyResolver (org.neo4j.graphdb.DependencyResolver)10 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)10 Label (org.neo4j.graphdb.Label)9 KernelAPI (org.neo4j.kernel.api.KernelAPI)9 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)9 InvalidTransactionTypeKernelException (org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException)8 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)8