Reputation: 3
I am trying to create my own procedure in Java in order to use it for Neo4j.I wanted to know how we can execute Cypher code in Java ?
I tried to use graphDB.execute() function but it doesn't work. I just want to execute a basic code in Java by using Neo4j libraries. Example of a basic code I want to execute:
[EDIT]
public class Test
{
@Context public GraphDatabaseService graphDb;
@UserFunction
public Result test() {
Result result = graphDb.execute("MATCH (n:Actor)\n" +
"RETURN n.name AS name\n" +
"UNION ALL MATCH (n:Movie)\n" +
"RETURN n.title AS name", new HashMap<String, Object>());
return result;
}
}
Upvotes: 0
Views: 264
Reputation: 30407
If you want to display nodes (as in the graphical result view in the browser), then you have to return the nodes themselves (and/or relationships and/or paths), not the properties alone (names and titles). You'll also need this to be a procedure, not a function. Procedures can yield streams of nodes, functions can only return single values.
Change this to a procedure, and change your return type to be something like Stream<NodeResult>
where NodeResult is a POJO that has a public Node field.
You'll need to change your return accordingly.
Upvotes: 1