Book Image

Neo4j High Performance

By : Sonal Raj
Book Image

Neo4j High Performance

By: Sonal Raj

Overview of this book

Table of Contents (15 chapters)
Neo4j High Performance
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Working of your code


Let's take a look at a simple Hello World application code for Neo4j and understand what goes on under the hood when you try to perform some simple operations on Neo4j through the Java API. Here is the code for a sample app:

import org.neo4j.graphdb.*;
import org.neo4j.kernel.EmbeddedGraphDatabase;

/**
* Example class that constructs a simple graph with
* message attributes and then prints them.
*/

public class NeoOneMinute {
  public enum MyRelationshipTypes implements RelationshipType {
    KNOWS
  }

  public static void main(String[] args) {
    GraphDatabaseService graphDb = new EmbeddedGraphDatabase("var/base");
    Transaction tx = graphDb.beginTx();
    try {
      Node node1 = graphDb.createNode();
      Node node2 = graphDb.createNode();
      Relationship someRel =  node1.createRelationshipTo(node2, MyRelationshipTypes.KNOWS);

      node1.setProperty("message", "Hello, ");
      node2.setProperty("message", "world!");
      someRel.setProperty("message"...