Share Pastebin
Guest
Public paste!

Stefan

By: a guest | Feb 9th, 2010 | Syntax: Java | Size: 1.22 KB | Hits: 16 | Expires: Never
Copy text to clipboard
  1. import org.neo4j.kernel.EmbeddedGraphDatabase;
  2. import org.neo4j.graphdb.GraphDatabaseService;
  3. import org.neo4j.graphdb.Transaction;
  4. import org.neo4j.graphdb.DynamicRelationshipType;
  5. import org.neo4j.graphdb.Node;
  6. import org.neo4j.graphdb.Relationship;
  7.  
  8. class neo {
  9.  
  10.         public static void main(String[] args) {
  11.  
  12.                 GraphDatabaseService graphDatabaseService = new EmbeddedGraphDatabase("/tmp/neo4jdb");
  13.                 Transaction tx = graphDatabaseService.beginTx();
  14.                 try {
  15.                         Node root = graphDatabaseService.getReferenceNode();
  16.                         Node node = graphDatabaseService.createNode();
  17.                         long id = node.getId();
  18.    
  19.                         node.createRelationshipTo(root, DynamicRelationshipType.withName("dummy"));
  20.    
  21.                         for (Relationship rel : root.getRelationships()) {
  22.                                 System.out.format("rel %s: %s -> %s %s\n", rel, rel.getStartNode(), rel.getEndNode(), rel.getType().name());
  23.                         }
  24.  
  25.                         node.delete(); // this should throw a RuntimeException                 
  26.  
  27.                         node = graphDatabaseService.getNodeById(id);
  28.                         System.out.format("node is still there %s\n", node);
  29.  
  30.                         tx.failure();
  31.                         System.out.println("no exception occured");
  32.                 } catch (Throwable e) {
  33.                         e.printStackTrace();
  34.                 } finally {
  35.                         tx.finish();
  36.                         graphDatabaseService.shutdown();
  37.                 }
  38.         }
  39. }