【发布时间】:2014-03-14 16:26:19
【问题描述】:
在我的项目中,我通过GraphDatabaseService 使用 Neo4j 的 Core-API。在测试中,我们有一个EmbeddedGraphDatabase,一切都按预期工作。然后我写了一些测试来看看我的实现在RestGraphDatabase 上的表现如何,只是为了发现大部分都失败了!
(GraphDatabaseService是通过Rest-API的GraphDatabaseFactory获取的,所以没有instanceof的检查不知道是哪个)
一些例子:
如果我使用GlobalGraphOperations,一切都会失败,因为RestGraphDatabase 不支持 GlopalGraphOperations。 (奇怪的是GlobalGraphOperations.at 没有抛出,而是来自 GlobalGraphOperations 的所有方法)。
然后我想“好吧,我将使用 Cypher 来获得相同的行为。” 我试图实现这样的方法:
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
}
}
搜索我看到的 API,有一个 RestCypherQueryEngine,它是通过 RestAPIFascade 初始化的。这里的问题是,方法不可互换,不实现相同的接口,返回类型完全不同(即ExecutionResult vs QueryResult)
所以我的问题是:有没有办法从 Neo4j 获得相同的行为,而使用的技术(Rest 与 Embedded)无关紧要?某种独立于技术的 Wrapper 将满足我的需求。
顺便说一句,我使用的是版本 2 中的 Neo4j
【问题讨论】:
标签: java rest neo4j cypher embedded-database