Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
106 views
in Technique[技术] by (71.8m points)

java - Can Apache Tinkerpop's Neo4jGraph.open() open a database from the file system?

I am using Apache Tinkerpop's Gremlin language to interact with a Neo4J database. I am able to use the Neo4jGraph.open("/path/to/folder") method (from org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jGraph) to create a new local database.

The Neo4J files populate the folder, so I know a database is being created. When I call .open again with the same path from within a unit test, it seems like the database files are being overwritten by a new database instance. Any vertices added previously are no longer in the database. Is it possible to reopen a previously created database with this method, or will a new instance always be generated?

question from:https://stackoverflow.com/questions/65903194/can-apache-tinkerpops-neo4jgraph-open-open-a-database-from-the-file-system

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I would expect Neo4jGraph.open(path) to open an existing graph if present at that path or create a new one if it does not find one. I would not expect it to overwrite. I assume that you are not committing your transaction in your unit test prior to closing your graph:

gremlin> graph = Neo4jGraph.open('/tmp/neo4j')
==>neo4jgraph[community single [/tmp/neo4j]]
gremlin> g = graph.traversal()
==>graphtraversalsource[neo4jgraph[community single [/tmp/neo4j]], standard]
gremlin> g.addV('person').property('name','marko')
==>v[0]
gremlin> graph.close()
==>null
gremlin> graph = Neo4jGraph.open('/tmp/neo4j')
==>neo4jgraph[community single [/tmp/neo4j]]
gremlin> g = graph.traversal()
==>graphtraversalsource[neo4jgraph[community single [/tmp/neo4j]], standard]
gremlin> g.V()
gremlin> g.addV('person').property('name','marko')
==>v[0]
gremlin> g.tx().commit()
==>null
gremlin> graph.close()
==>null
gremlin> graph = Neo4jGraph.open('/tmp/neo4j')
==>neo4jgraph[community single [/tmp/neo4j]]
gremlin> g = graph.traversal()
==>graphtraversalsource[neo4jgraph[community single [/tmp/neo4j]], standard]
gremlin> g.V()
==>v[0]

As you can see, if I close() without g.tx().commit() and then re-open the graph the vertex I added is not present. However, with a call to commit() I can re-open and get my vertex.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...