Stefan
By: a guest | Feb 9th, 2010 | Syntax:
Java | Size: 1.22 KB | Hits: 16 | Expires: Never
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.DynamicRelationshipType;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
class neo {
public static void main
(String[] args
) {
GraphDatabaseService graphDatabaseService = new EmbeddedGraphDatabase("/tmp/neo4jdb");
Transaction tx = graphDatabaseService.beginTx();
try {
Node root = graphDatabaseService.getReferenceNode();
Node node = graphDatabaseService.createNode();
long id = node.getId();
node.createRelationshipTo(root, DynamicRelationshipType.withName("dummy"));
for (Relationship rel : root.getRelationships()) {
System.
out.
format("rel %s: %s -> %s %s\n", rel, rel.
getStartNode(), rel.
getEndNode(), rel.
getType().
name());
}
node.delete(); // this should throw a RuntimeException
node = graphDatabaseService.getNodeById(id);
System.
out.
format("node is still there %s\n", node
);
tx.failure();
System.
out.
println("no exception occured");
e.printStackTrace();
} finally {
tx.finish();
graphDatabaseService.shutdown();
}
}
}