'janusgraph with createing the same garph in different time
In this case,first , i opende a janusgraph ,created some vertexes and edges and closed it;later,i opened the same janusgraph,create some vertexes and edges and closed it.
After all,i want to find the pathes form a vertex to another ,i find that the two vertexes are not in one path ,because they created in different time;however,if i create them together ,the path is right.
here are some codes for creating:
val grap = JanusGraphFactory.open("d:\\janusgraph\\janusgraph-hbase.properties")
val mgmt = grap.openManagement()
mgmt.makePropertyKey("value").dataType(classOf[String]).make()
mgmt.makeEdgeLabel("deviceid").make()
mgmt.makeVertexLabel("phone").make()
val tx = grap.newTransaction()
val phone1 = tx.addVertex(T.label, "phone", "value", "13700000001")
val phone2 = tx.addVertex(T.label, "phone", "value", "13700000002")
val phone3 = tx.addVertex(T.label, "phone", "value", "13700000003")
val phone4 = tx.addVertex(T.label, "phone", "value", "13700000004")
val phone5 = tx.addVertex(T.label, "phone", "value", "13700000005")
val dev1 = tx.addVertex(T.label, "dev", "value", "dev1")
val dev2 = tx.addVertex(T.label, "dev", "value", "dev2")
val dev3 = tx.addVertex(T.label, "dev", "value", "dev3")*/
phone1.addEdge("phone-dev", dev1, "value", "13700000001_dev1")
phone2.addEdge("phone-dev", dev1, "value", "13700000002_dev1")
phone2.addEdge("phone-dev", dev2, "value", "13700000002_dev2")
phone3.addEdge("phone-dev", dev2, "value", "13700000003_dev2")
phone4.addEdge("phone-dev", dev2, "value", "13700000004_dev2")
phone4.addEdge("phone-dev", dev3, "value", "13700000004_dev3")
tx.commit()
tx.close()
here are codes for finding:
val graph = JanusGraphFactory.open("d:\\janusgraph\\janusgraph-hbase.properties")
//val graph = JanusGraphFactory.open(configuration)
val g = graph.traversal()
val result2 = g.V().hasLabel("phone").repeat(both().simplePath()).until(bothE().count().is(1)).path().by("value").toSet
//val result = g.V().hasLabel("phone").repeat(both().simplePath()).until(bothE().count().is(1)).path().by
val it = result2.iterator()
while (it.hasNext) {
println("path=>" + it.next())
}
System.exit(1)
Solution 1:[1]
JanusGraph have something called Transactional Scope. According to this concept,
All graph elements (vertices, edges, and types) are associated with the transactional scope in which they were retrieved or created. Under TinkerPop’s default transactional semantics, transactions are automatically created with the first operation on the graph and closed explicitly using commit() or rollback(). Once the transaction is closed, all graph elements associated with that transaction become stale and unavailable. However, JanusGraph will automatically transition vertices and types into the new transactional scope as shown in this example:
graph = JanusGraphFactory.open("berkeleyje:/tmp/janusgraph")
juno = graph.addVertex() //Automatically opens a new transaction
graph.tx().commit() //Ends transaction
juno.property("name", "juno") //Vertex is automatically transitioned
Edges, on the other hand, are not automatically transitioned and cannot be accessed outside their original transaction. They must be explicitly transitioned:
e = juno.addEdge("knows", graph.addVertex())
graph.tx().commit() //Ends transaction
e = g.E(e).next() //Need to refresh edge
e.property("time", 99)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | TechFramer - Sanil Bagzai |
