【问题标题】:Neo4j - How to handle incompatible RestGraphDatabase callsNeo4j - 如何处理不兼容的 RestGraphDatabase 调用
【发布时间】: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


    【解决方案1】:

    只是不要这样做。它会做什么(如果有效)将通过网络执行对数据库的每次调用,读取和写入节点、rels 和属性。你不想那样做。

    改用这个。

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

    这会将查询发送到服务器并在那里运行它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      • 2022-12-17
      • 1970-01-01
      • 2021-09-26
      • 2018-01-24
      • 2019-02-27
      相关资源
      最近更新 更多