简体   繁体   English

Neo4j数据库更新命令在递归功能中不起作用(Neo4j中的AutoCommit)

[英]Neo4j database update command not working in recursive function(AutoCommit in Neo4j)

I am trying to update my neo4j Graph database with a query. 我正在尝试使用查询更新neo4j Graph数据库。

int recursiveFunction()
{
     try(Transaction tx1 = graphDb.beginTx();)
     {
     int val=recursiveFunction()
     if(val==0)
     {
                    try(Transaction tx1 = graphDb.beginTx();)
                    {
                        System.out.println("Competed node "+applicationName);
                        String updateQuery="    match(p:Problem) where p.value=\""+applicationName+"\"  set p.completed=1  return p";   
                        ExecutionResult updateExecResult = execEngine2.execute(updateQuery);
                        System.out.println("Updated complete flag for "+applicationName);
                        System.out.println("new value of updated is + "+updateExecResult.dumpToString());
                        tx1.success();
                        tx1.close();
                    }
                    catch(Exception e)
                    {
                        System.out.println("error in query");
                        e.printStackTrace();
                    }
    }
    catch(Exception e)
    {
     }
}

The value gets updated and it is been shown correctly when i do the results.dumpToString(). 该值被更新,并且在我执行result.dumpToString()时正确显示。 But when i continue again in the loop and come back again ,the value is not updated.Is it because i am doing the commit incorrectly.My issue is even if the value is getting updated inside the recursive function after that the changes are not getting reflected.Is there a way of AUTOCOMMIT in neo4j. 但是当我再次继续循环并再次返回时,值未更新。是因为我做错了提交。我的问题是即使递归函数中的值在更新后也没有更新在neo4j中是否有一种自动提交的方式。

Your code will never even compile. 您的代码将永远无法编译。

You should not name your transaction variables the same, the inner tx1 shadows the outer tx1 您不应将事务变量命名为相同的名称,内部tx1外部tx1

And the construct try () {} already does a close automatically, so you close your inner tx twice . 并且try(){}构造已经自动关闭,因此您两次关闭了内部tx。

And your outer tx get's never committed, because you never call tx1.success() on it. 而且您的外部tx get不会提交,因为您永远不会在其上调用tx1.success()

The inner transactions, don't actually commit, they are just placebo transactions, which make sure you can nest functions. 内部事务实际上并没有提交,它们只是安慰剂事务,可确保您可以嵌套函数。

You function also never aborts, because you can it indefinitely. 您的功能也永远不会中止,因为您可以无限期地中止操作。

int recursiveFunction() {
    try(Transaction tx1 = graphDb.beginTx()) {
       // todo abort-condition
       int val=recursiveFunction()
       if(val==0) {
          try(Transaction tx2 = graphDb.beginTx()) {
            String updateQuery="    match(p:Problem) where p.value=\""+applicationName+"\"  set p.completed=1  return p";   
            ExecutionResult updateExecResult = execEngine2.execute(updateQuery);
            tx2.success();
          } catch(Exception e2) {
            e2.printStackTrace();
          }
       }
       tx1.success();
    } catch(Exception e1) {
        e1.printStackTrace();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM