我刚刚开始使用Titan而不是Cassandra。我对Titan和图形数据库概念都很陌生,只是按照github和wiki上的说明进行操作。
Configuration conf = new BaseConfiguration();
conf.setProperty("storage.backend", "cassandra");
conf.setProperty("storage.hostname", "127.0.0.1");
TitanGraph g = TitanFactory.open(conf);
这是我打开图形的方法。
我知道默认的键空间是“titan”。我在默认的键空间中创建了一些节点和关系。我对顶点进行了索引,并查询了节点,能够遍历结果。
现在我的问题是:
1)如何设置新的键空间?
我尝试使用属性
conf.setProperty("storage.keyspace ", "newkeyspace");
很不幸,当我检查cassandra keyspace时,我只找到了titan
。没有名为newkeyspace
的keyspace。可能的原因是什么?
2) 如何持久化已创建的图形?
例如,
g.createKeyIndex("name", Vertex.class);
Vertex juno = g.addVertex(null);
juno.setProperty("name", "juno");
juno.setProperty("type", "node");
Vertex juno1 = g.addVertex(null);
juno1.setProperty("name", "juno");
juno1.setProperty("type", "node1");
这是一个示例图表。一旦我发出以下格式的查询:
Iterator<Vertex> junoIterator = g.getVertices("name", "juno")
.iterator();
while (junoIterator.hasNext()) {
Vertex vertex = (Vertex) junoIterator.next();
System.out.println(vertex.getProperty("type"));
}
我的期望结果是
node
node1
如果我注释掉以下部分,同样的查询应该可以正常工作 -
/*g.createKeyIndex("name", Vertex.class);
Vertex juno = g.addVertex(null);
juno.setProperty("name", "juno");
juno.setProperty("type", "node");
Vertex juno1 = g.addVertex(null);
juno1.setProperty("name", "juno");
juno1.setProperty("type", "node1");*/
这里,我认为节点、关系和索引已经建立并持久化在某个数据存储中。我的理解是否正确?
请您指导。