Vertex vertex = graph.addVertex();
vertex.property("ID", "123"); //Creates ID property with value 123
创造 property . 要查询属性:
vertex.property("ID"); //Returns the property object
vertex.value("ID"); //Returns "123"
vertex.values(); //Returns all the values of all the properties
当您难以理解Titan API时 . 我建议看TinkerPop API . Titan实现了它,所以所有tinkerpop命令都适用于titan图形 .
0
我也在使用带有cassandra存储后端的 titan 1.0.0 图形数据库,从0.5.4版本升级后也遇到了同样的问题 . 我发现使用此方法将任何 Collection 对象( Set 或 List )添加到顶点属性的简单通用解决方案 .
public static void setMultiElementProperties(TitanElement element, String key, Collection collection) {
if (element != null && key != null && collection != null) {
// Put item from collection to the property of type Cardinality.LIST or Cardinality.SET
for (Object item : collection) {
if (item != null)
element.property(key, item);
}
}
}
与 Java 8 syntacs相同的方法实现:
public static void setMultiElementProperties(TitanElement element, String key, Collection collection) {
if (element != null && key != null && collection != null) {
// Put item from collection to the property of type Cardinality.LIST or Cardinality.SET
collection.stream().filter(item -> item != null).forEach(item -> element.property(key, item));
}
}
2 回答
一个例子将有助于:
创造 property . 要查询属性:
当您难以理解Titan API时 . 我建议看TinkerPop API . Titan实现了它,所以所有tinkerpop命令都适用于titan图形 .
我也在使用带有cassandra存储后端的 titan 1.0.0 图形数据库,从0.5.4版本升级后也遇到了同样的问题 . 我发现使用此方法将任何
Collection
对象(Set
或List
)添加到顶点属性的简单通用解决方案 .与 Java 8 syntacs相同的方法实现:
TitanElement
object是TitanVertex
和TitanEdge
对象的父对象,因此您可以将顶点或边传递给此方法 . 当然,您需要首先使用 Cardinality.Set 或 Cardinality.List 使用TitanManagement声明元素属性以使用多值属性 .要从element属性中检索集合,您可以简单地使用:
这是Java 8迭代它的方法: