2017-01-07 22 views
1

我在嵌入模式下使用neo4j。因此,对于服务器上的数据库中的一些操作,我正试图执行groovy脚本。 Groovy脚本运行成功,没有任何错误,但是当我检查neo4j-communinty工具时,它不会创建任何新记录。Neo4j:Groovy脚本没有插入任何东西

脚本

/** 
* Created by prabjot on 7/1/17. 
*/ 
@Grab(group="org.neo4j", module="neo4j-kernel", version="2.3.6") 
@Grab(group="org.neo4j", module="neo4j-lucene-index", version="2.3.6") 
@Grab(group='org.neo4j', module='neo4j-shell', version='2.3.6') 
@Grab(group='org.neo4j', module='neo4j-cypher', version='2.3.6') 
import org.neo4j.graphdb.factory.GraphDatabaseFactory 
import org.neo4j.graphdb.Node 
import org.neo4j.graphdb.Result 
import org.neo4j.graphdb.Transaction 
class Neo4jEmbeddedAccess { 

    public static void main(String[] args) { 
     def map=[:] 
     map.put("allow_store_upgrade","true") 
     map.put("remote_shell_enabled","true") 
     def db = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder("/opt/neo4j-community-3.0.4/data/databases/graph.db") 
       .setConfig(map) 
       .newGraphDatabase() 
     Transaction tx =db.beginTx() 
     Node person = db.createNode(); 
     person.setProperty("name","prabjot") 
    print("id---->" + person.id); 
     Result result = db.execute("Match (country:Country) where id(country)=73 SET country.modified=true return country") 
     print(result) 
     tx.success(); 

     println """starting embedded graph db 
use bin/neo4j-shell from a new distribution to connect 
we're keeping the graphdb open for 120 secs""" 
     db.shutdown() 
    } 

请帮我在做什么错在这里,我检查了我的数据库位置,但同我正在使用的脚本和工具。

感谢

回答

2

你忘tx.close(),它提交事务

Sucess不仅标志着它作为成功

+0

Thanku它工作正常。但是我担心一个问题,如果我想改变数据库中的某些东西,我应该关闭应用程序,我认为这是不可能的,因为它给我锁定文件错误。所以你可以建议我如何在使用嵌入模式时修复生产中的错误数据。 –