【发布时间】:2016-04-11 05:00:46
【问题描述】:
我将更新 list 属性的整个值并在 Titan 1.0 中为其设置一个新值,对于单一基数我可以使用 vertex.property("single_property",new_value) 并覆盖整个值,但对于 List 类型的基数,新值将被添加到属性中(它不会覆盖整个值)。此外,如果我删除该属性并添加一个新值,在同一事务中似乎整个操作将被 Titan 忽略!因此,我的问题是如何以适当的方式更新列表属性的整个值?
关于phani提供的解决方案,以下代码对我不起作用,插入部分起作用,但删除部分不起作用。
keywords = keywordExtractor.getKeywords(getId(nextVertex))
if (keywords.size() > 0) {
nextVertex.property(VertexProperty.Cardinality.single, "post_keyword", keywords.get(0));
keywords.remove(0);
for (String keyword : keywords) {
nextVertex.property(VertexProperty.Cardinality.list, "post_keyword", keyword);
}
}
nextVertex.graph().tx().commit();
以下提供的 Jason 提供的解决方案也不起作用。问题出在删除部分。
keywords = keywordExtractor.getKeywords(getId(nextVertex))
if (keywords.size() > 0) {
nextVertex.graph().traversal().V(nextVertex).properties("post_keyword").drop().iterate();
for (String keyword : keywords) {
nextVertex.property("post_keyword", keyword);
}
}
nextVertex.graph().tx().commit();
我也确实研究了以下解决方案;也没有用。
keywords = keywordExtractor.getKeywords(getId(nextVertex))
if (keywords.size() > 0) {
Iterator<VertexProperty<Object>> iter = nextVertex.properties("post_keyword");
while(iter.hasNext()){
iter.next().remove();
}
for (String keyword : keywords) {
nextVertex.property("post_keyword", keyword);
}
}
nextVertex.graph().tx().commit();
【问题讨论】:
标签: java graph-databases titan