Database Reference
In-Depth Information
ExecutionResult result =
engine.execute(cypherQuery);
Iterator<Object> iter =
result.columnAs("RootNode");
//Check to see that we do not have empty Iterator
if(iter==null || iter.isEmpty()){
return null;
}
return (Node) iter.next();
}}
}
The preceding code extends
ServerPlugin
, which manages the lifecycle of
our custom plugin and adds it as an extension to the already exposed REST end-
points.
There are a few important points that we need to remember or implement while
creating the server plugin:
◦ We need to ensure that our plugin produces or returns an instance or list
of node, relationship, or path, or an instance of
org.neo4j.server.rest.repr.Representation
that can be
iterated. For example, the preceding code returns
Iterable<Path>
.
◦ It specifies request parameters using the
@Parameter
annotation. Sim-
ilar to what we used in the preceding code
@Parameter (name =
"name")
. You can skip this annotation if your service does not need any
user inputs.
◦ Specify the point of extension as we specified in the preceding code us-
ing the
@Name
annotation.
◦ Specify the discovery point type in the
@PluginTarget
annotation
and the
@Source
parameter, which are of the same type.
◦ Needless to mention, we also need to define the application logic, which
in the preceding code is defined in the
startTraversing
method.
5. Add the
META-INF
and
services
directories under
<$Spring-Neo4j>/
src/main/resources
.
6. Add a new file
org.neo4j.server.plugins.ServerPlugin
under
<$Spring-Neo4j>/src/main/resources/META-INF/services
.
The content of this file should be the fully qualified name of your plugin:
org.neo4j.custom.server.plugins.GraphTraversal
.