Guest User

Untitled

a guest
Aug 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. import java.io.File;
  2. import org.neo4j.graphdb.GraphDatabaseService;
  3. import org.neo4j.graphdb.Label;
  4. import org.neo4j.graphdb.Node;
  5. import org.neo4j.graphdb.Relationship;
  6. import org.neo4j.graphdb.RelationshipType;
  7. import org.neo4j.graphdb.Transaction;
  8. import org.neo4j.graphdb.factory.GraphDatabaseFactory;
  9.  
  10. public class Operation {
  11.  
  12. //private static final File file =new File();
  13.  
  14. public static void main(String[] args) {
  15.  
  16. GraphDatabaseFactory dbFactory = new GraphDatabaseFactory();
  17. GraphDatabaseService db= dbFactory.newEmbeddedDatabaseBuilder("C:\Users\pritom.mazumdar\Downloads\neo4j-community-3.5.0-alpha07\data\databases\graph.db").newGraphDatabase();
  18. //Transaction tx = db.beginTx();
  19. try (Transaction tx = db.beginTx()) {
  20.  
  21. Node javaNode = db.createNode();
  22. javaNode.setProperty("TutorialID", "JAVA001");
  23. javaNode.setProperty("Title", "Learn Java");
  24. javaNode.setProperty("NoOfChapters", "25");
  25. javaNode.setProperty("Status", "Completed");
  26.  
  27. Node scalaNode = db.createNode();
  28. scalaNode.setProperty("TutorialID", "SCALA001");
  29. scalaNode.setProperty("Title", "Learn Scala");
  30. scalaNode.setProperty("NoOfChapters", "20");
  31. scalaNode.setProperty("Status", "Completed");
  32.  
  33. Relationship relationship = javaNode.createRelationshipTo(scalaNode, (RelationshipType) Label.label("JVM_LANG"));
  34. relationship.setProperty("Id","1234");
  35. relationship.setProperty("OOPS","YES");
  36. relationship.setProperty("FP","YES");
  37.  
  38. tx.success();
  39. }
  40. System.out.println("Done successfully");
  41.  
  42. }
  43.  
  44. }
Add Comment
Please, Sign In to add comment