public void demonstrateLogging() {
performMutations(database);
}
private void performMutations(GraphDatabaseService database) {
SimpleTransactionExecutor executor = new SimpleTransactionExecutor(database);
//create nodes
executor.executeInTransaction(new VoidReturningCallback() {
@Override
protected void doInTx(GraphDatabaseService database) {
database.createNode(label("SomeLabel1"));
Node node1 = database.createNode(label("SomeLabel2"));
node1.setProperty("name", "One");
Node node2 = database.createNode();
node2.setProperty("name", "Two");
Node node3 = database.createNode();
node3.setProperty("name", "Three");
}
});
//create relationship
executor.executeInTransaction(new VoidReturningCallback() {
@Override
protected void doInTx(GraphDatabaseService database) {
Node one = database.getNodeById(1);
Node two = database.getNodeById(2);
Relationship relationship = one.createRelationshipTo(two, withName("TEST"));
relationship.setProperty("level", 2);
two.createRelationshipTo(one, withName("TEST"));
}
});
//change and delete nodes
executor.executeInTransaction(new VoidReturningCallback() {
@Override
protected void doInTx(GraphDatabaseService database) {
database.getNodeById(3).delete();
database.getNodeById(1).setProperty("name", "New One");
database.getNodeById(1).setProperty("numbers", new int[]{1, 2, 3});
database.getNodeById(2).addLabel(label("NewLabel"));
}
});
//change and delete relationships
executor.executeInTransaction(new VoidReturningCallback() {
@Override
protected void doInTx(GraphDatabaseService database) {
database.getNodeById(2).getSingleRelationship(withName("TEST"), OUTGOING).delete();
database.getNodeById(1).getSingleRelationship(withName("TEST"), OUTGOING).setProperty("level", 3);