Reputation: 493
I'm writing an unmanaged extension and I'm having problem accessing indexes with JAVA API.
The code:
package org.neo4j.parent.parentextension;
import org.codehaus.jackson.map.ObjectMapper;
import org.neo4j.cypher.javacompat.ExecutionEngine;
import org.neo4j.cypher.javacompat.ExecutionResult;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.index.Index;
import org.neo4j.graphdb.index.IndexManager;
import org.neo4j.graphdb.Node;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@Path("/parent")
public class ParentDistance {
@GET
@Path("/helloworld")
public String helloWorld() {
return "Hello World!";
}
@GET
@Path("/common/{acc1}/{acc2}")
public String getCommon(@PathParam("acc1") String acc1, @PathParam("acc2") String acc2, @Context GraphDatabaseService db) throws IOException {
return db.index().nodeIndexNames().toString();
}
}
helloworld call does work and also other methods that execute a Cypher query. But, as soon as any IndexManager or index is called in any method, anything below stops working. Any hint what to look for?
Thanks!
Upvotes: 1
Views: 76
Reputation: 41706
What do you mean by "stops working".
Any exceptions in the logs?
With Neo4j 2.0 you have to do wrap read operations within transactions.
Like this:
@GET
@Path("/common/{acc1}/{acc2}")
public String getCommon(@PathParam("acc1") String acc1, @PathParam("acc2") String acc2, @Context GraphDatabaseService db) throws IOException {
try (Transaction tx = db.beginTx()) {
String result = db.index().nodeIndexNames().toString();
tx.success();
}
}
Upvotes: 1