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);
}
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()));
}
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();
}
}
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);
}
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()));
}
Aggregations