[英]How to create edge label in Arangodb?
java-driver 4.1.10我已经创建了名为mydatabase1的数据库,我已经使用Java创建了一个图,所以我的问题是如何使用Java代码设置边缘标签?
If you mean with "edge label" a field in an edge-document, you can set it when you call insertEdge
like in the code below. 如果要在边缘文档中使用“边缘标签”来表示字段,则可以在调用
insertEdge
时进行设置,如下面的代码所示。
ArangoDB arangoDB = new ArangoDB.Builder().build();
// create database
arangoDB.createDatabase("myDatabase");
// create named graph
Set<EdgeDefinition> edgeDefinitions = Collections.singleton(
new EdgeDefinition().collection("myEdgeCollection").from("myVertexCollection").to("myVertexCollection"));
arangoDB.db("myDatabase").createGraph("myGraph", edgeDefinitions);
// create from vertex
BaseDocument from = new BaseDocument("myFromKey");
arangoDB.db("myDatabase").graph("myGraph").vertexCollection("myVertexCollection").insertVertex(from);
// create to vertex
BaseDocument to = new BaseDocument("myToKey");
arangoDB.db("myDatabase").graph("myGraph").vertexCollection("myVertexCollection").insertVertex(to);
// create edge
BaseEdgeDocument edge = new BaseEdgeDocument("myVertexCollection/myFromKey",
"myVertexCollection/myToKey");
edge.addAttribute("label", "value");
edge.addAttribute("whatever", 42);
arangoDB.db("myDatabase").graph("myGraph").edgeCollection("myEdgeCollection").insertEdge(edge);
Instead of using BaseEdgeDocument
you can also use Map<String, Object>
除了使用
BaseEdgeDocument
还可以使用Map<String, Object>
Map<String, Object> edge = new HashMap<String, Object>();
edge.put("_from", "myVertexCollection/myFromKey");
edge.put("_to", "myVertexCollection/myToKey");
edge.put("label", "value");
edge.put("whatever", 42);
arangoDB.db("myDatabase").graph("myGraph").edgeCollection("myEdgeCollection").in sertEdge(edge);
or create your own POJO representing your edge. 或创建自己的POJO代表您的优势。 The edge needs at least the fields
_from
and _to
. 边缘至少需要字段
_from
和_to
。 If you don't want to name the fields in your POJO _from and _to, you can use the annotation DocumentField
with the values Type.FROM
and Type.TO
on two String
fields of your choice. 如果不想命名POJO _from和_to中的字段,则可以在
Type.TO
的两个String
字段上使用注释DocumentField
,其值分别为Type.FROM
和Type.TO
public class MyEdge {
@DocumentField(Type.FROM)
private String from;
@DocumentField(Type.TO)
private String to;
public MyEdge() {}
..setter & getter
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.