Search in sources :

Example 51 with Statement

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

the class KernelIT method addingNewLabelToNodeShouldRespondTrue.

@Test
public void addingNewLabelToNodeShouldRespondTrue() 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 added = statement.dataWriteOperations().nodeAddLabel(node.getId(), labelId);
    tx.close();
    // THEN
    assertFalse("Shouldn't have been added now", added);
}
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 52 with Statement

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

the class KernelIT method deletingNodeWithLabelsShouldHaveRemovalReflectedInLabelScans.

@Test
public void deletingNodeWithLabelsShouldHaveRemovalReflectedInLabelScans() throws Exception {
    // GIVEN
    Transaction tx = db.beginTx();
    Label label = label("labello");
    Node node = db.createNode(label);
    tx.success();
    tx.close();
    // AND GIVEN I DELETE IT
    tx = db.beginTx();
    node.delete();
    tx.success();
    tx.close();
    // WHEN
    tx = db.beginTx();
    Statement statement = statementContextSupplier.get();
    int labelId = statement.readOperations().labelGetForName(label.name());
    PrimitiveLongIterator nodes = statement.readOperations().nodesGetForLabel(labelId);
    Set<Long> nodeSet = PrimitiveLongCollections.toSet(nodes);
    tx.success();
    tx.close();
    // THEN
    assertThat(nodeSet, equalTo(Collections.<Long>emptySet()));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) Test(org.junit.Test)

Example 53 with Statement

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

the class KernelIT method schemaStateContains.

private boolean schemaStateContains(String key) {
    try (Transaction tx = db.beginTx()) {
        Statement statement = statementContextSupplier.get();
        final AtomicBoolean result = new AtomicBoolean(true);
        statement.readOperations().schemaStateGetOrCreate(key, s -> {
            result.set(false);
            return null;
        });
        tx.success();
        return result.get();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement)

Example 54 with Statement

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

the class KernelIT method deletingNodeWithLabelsShouldHaveThoseLabelRemovalsReflectedInTransaction.

@Test
public void deletingNodeWithLabelsShouldHaveThoseLabelRemovalsReflectedInTransaction() throws Exception {
    // GIVEN
    Transaction tx = db.beginTx();
    Label label = label("labello");
    Node node = db.createNode(label);
    tx.success();
    tx.close();
    tx = db.beginTx();
    Statement statement = statementContextSupplier.get();
    // WHEN
    statement.dataWriteOperations().nodeDelete(node.getId());
    // Then
    int labelId = statement.readOperations().labelGetForName(label.name());
    try {
        statement.readOperations().nodeGetLabels(node.getId());
        fail();
    } catch (EntityNotFoundException e) {
    // Ok
    }
    try {
        statement.readOperations().nodeHasLabel(node.getId(), labelId);
        fail();
    } catch (EntityNotFoundException e) {
    // Ok
    }
    Set<Long> nodes = PrimitiveLongCollections.toSet(statement.readOperations().nodesGetForLabel(labelId));
    statement.close();
    tx.success();
    tx.close();
    assertEquals(emptySetOf(Long.class), nodes);
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) Test(org.junit.Test)

Example 55 with Statement

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

the class KernelIT method labelShouldBeRemovedAfterCommit.

@Test
public void labelShouldBeRemovedAfterCommit() throws Exception {
    // GIVEN
    Transaction tx = db.beginTx();
    Statement statement = statementContextSupplier.get();
    Node node = db.createNode();
    int labelId1 = statement.tokenWriteOperations().labelGetOrCreateForName("labello1");
    statement.dataWriteOperations().nodeAddLabel(node.getId(), labelId1);
    statement.close();
    tx.success();
    tx.close();
    // WHEN
    tx = db.beginTx();
    statement = statementContextSupplier.get();
    statement.dataWriteOperations().nodeRemoveLabel(node.getId(), labelId1);
    statement.close();
    tx.success();
    tx.close();
    // THEN
    tx = db.beginTx();
    statement = statementContextSupplier.get();
    Set<Integer> labels = PrimitiveIntCollections.toSet(statement.readOperations().nodeGetLabels(node.getId()));
    statement.close();
    tx.success();
    tx.close();
    assertThat(labels, equalTo(Collections.<Integer>emptySet()));
}
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)

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