質問

In my project I'm using Neo4j's Core-API through GraphDatabaseService. In Tests we have an EmbeddedGraphDatabase where everything works as expected. I then wrote some tests to see how my implementation behaves on a RestGraphDatabase, just to find out, that most of it fails! (The GraphDatabaseService is obtained by GraphDatabaseFactory of the Rest-API, so without an instanceof check I do not know which one it is) Some examples:

If I use GlobalGraphOperations everything will fail, because GlopalGraphOperations are not supported by the RestGraphDatabase. (Strange enough that GlobalGraphOperations.at doesn't throw but all methods from GlobalGraphOperations).

Then I thought "ok I'll use Cypher to get the same behavior." I tryed to implement a Method like this:

public getNodesWithLabel(String label, GraphDatabaseService graphService){
    try(Transaction tx graphService.beginTx()){
        ExecutionEngine ee = new ExecutionEngine(graphService);
        //throws NullPOinterExeption in execute method
        ExecutionResult result = ee.execute("MATCH (n:" + label + ") RETURN n");
        result.columnAs("n");
        //... mapping of Nodes
    }
}

Searching through the API I see, that there is a RestCypherQueryEngine which is initialized via a RestAPIFascade. Problem here is, that the methods are not interchangeable, do not implement the same interface, and the return types are completeley different (i.e. ExecutionResult vs QueryResult)

So my question is: Is there a way, to get the same behavior from Neo4j where the used technology (Rest vs. Embedded) doesn't matter? Some kind of a technology independed Wrapper will suit my needs.

by the way, I'm using Neo4j in Version 2

役に立ちましたか?

解決

Just don't do it. What it would do (if it worked) would be to execute every call to the database over the wire, ever read and write of nodes, rels and properties. You don't want to do that.

Use this instead.

queryEngine = new RestCypherQueryEngine(restGraphDb.getRestAPI());
queryEngine.query(query, params)

This sends the queries to the server and runs them there.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top