Database Reference
In-Depth Information
this.graphDb = graphDb;
}
//Implementation Logic for exposing this as a GET
response
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response nodeIDs() {
Map<String, String> nodeIDs = new
HashMap<String,String>();
try (Transaction tx = graphDb.beginTx()) {
//Get all Node ID's and put them into the MAP.
//Key of Map needs to be appended by Node_ID,
so that every entry is Unique
for (Node node :
GlobalGraphOperations.at(graphDb).getAllNodes()) {
nodeIDs.put("Node_ID_"+Long.toString(node.getId()),Long.;
toString(node.getId()))}
tx.success();
}
//Converting the Map Object into JSON String
JSONObject jsonObj = new JSONObject(nodeIDs);
//Returning a Success Status, along with the JSON
response.
return Response.status(Status.OK)
.entity(jsonObj.toString().getBytes(Charset
.forName("UTF-8"))).build();
}
}
The preceding code uses the @Context annotation to inject the dependency of
GraphDatabaseService , which fetches all the nodes from the Neo4j data-
base and wraps them into a JSON object. Finally, the code transforms JSON into
string and returns it back to the user as a response.
3. Open the console, browse <$Spring-Neo4j> , and execute the following com-
mand to compile the code:
Search WWH ::




Custom Search