2016-12-30 44 views
1

我使用Ne04j V3.1.0与Java驱动程序提交。我有麻烦的更新语句(CYPHER SET)的一个显式事务中的结果存在。从交易中返回的值显示变化,但交易结束后的变化似乎消失了。我知道,更新对结果处理敏感Neo4j的Java驱动程序交易似乎没

[http://neo4j.com/docs/developer-manual/current/drivers/process-results/][1]

,所以我一直在我大约消耗所有的结果和关闭我的课程代码攻击性。

我写了一个测试程序来演示该问题:

package uk.co.scapps.createdirs.neo; 

import org.apache.logging.log4j.LogManager; 
import org.apache.logging.log4j.Logger; 
import org.neo4j.driver.v1.AuthTokens; 
import org.neo4j.driver.v1.Driver; 
import org.neo4j.driver.v1.GraphDatabase; 
import org.neo4j.driver.v1.Record; 
import org.neo4j.driver.v1.Session; 
import org.neo4j.driver.v1.StatementResult; 
import org.neo4j.driver.v1.Transaction; 


public class Trans { 
    static Driver driver = GraphDatabase.driver("bolt://localhost", AuthTokens.basic("neo4j", "neo4k")); 
    static Session session = driver.session(); 
    final static Logger logger = LogManager.getLogger(); 

    public static void main(String[] args) { 
     session = driver.session(); 
     StatementResult results ; 
     session = driver.session(); 
     try (Transaction tx = session.beginTransaction()) { 
      results = tx.run("MATCH (n:THING) RETURN n.name as name"); 
      while (results.hasNext()) { 
       Record record = results.next(); 
       System.out.println("in the txn before the update: " + record.get("name").toString()); 
      }   
      results.consume(); 
      results = tx.run("MATCH (n:THING {name: 'a'}) SET n.name = 'asdasd' RETURN n.name as name"); 
      while (results.hasNext()) { 
       Record record = results.next(); 
       System.out.println("results returned from the update: " + record.get("name").toString()); 
      }   
      results.consume(); 
      results = tx.run("MATCH (n:THING) RETURN n.name as name"); 
      while (results.hasNext()) { 
       Record record = results.next(); 
       System.out.println("after the update but still in the txn: " + record.get("name").toString()); 
      }   
      results.consume(); 
      tx.close(); 
      session.close(); 
     } 
     session = driver.session(); 
     results = session.run("MATCH (n:THING) RETURN n.name as name"); 
     while (results.hasNext()) { 
      Record record = results.next(); 
      System.out.println("after the txn: " + record.get("name").toString()); 
     }   
     results.consume(); 
     session.close(); 
    } 
} 

这里是输出:

in the txn before the update: "a" 
in the txn before the update: "b" 
in the txn before the update: "c" 
results returned from the update: "asdasd" 
after the update but still in the txn: "asdasd" 
after the update but still in the txn: "b" 
after the update but still in the txn: "c" 
after the txn: "a" 
after the txn: "b" 
after the txn: "c" 

我还没有包括的代码,但我写了一个非事务(隐含的事务)程序的版本,它按预期工作。

我将不胜感激任何帮助。

回答

1

我未能执行txn.success()

+0

你可能要考虑删除的问题,或者接受你自己的答案。 – InverseFalcon