About Luanne Misquitta
In Part 1, we talked about setting up a connection to the Neo4j Server using the Java REST Binding. Let’s now go into some details about transactions, batching, and what the REST requests really look like.Make sure you turn on logging (set system property org.neo4j.rest.logging_filter to true) as described in Part 1.
We will change our code to execute these Neo4j API calls.
Example 1:
Transaction tx = graphDb.beginTx(); Map props=new HashMap(); props.put("id", 100); props.put("name","firstNode"); Node node=graphDb.createNode(props); props.put("id",200); props.put("name","secondNode"); Node node2=graphDb.createNode(props); node.createRelationshipTo(node2, DynamicRelationshipType.withName("KNOWS")); tx.success(); tx.finish(); result=engine.query("start n=node(*) return count(n) as total", Collections.EMPTY_MAP); Iterator iterator=result.iterator(); if(iterator.hasNext()) { Map row= iterator.next(); out.print("Total nodes: " + row.get("total")); } Source : http://www.javacodegeeks.com/2013/08/neo4j-java-rest-binding-part-2-batching.html