繁体   English   中英

如何在Arangodb中创建边缘标签?

[英]How to create edge label in Arangodb?

java-driver 4.1.10我已经创建了名为mydatabase1的数据库,我已经使用Java创建了一个图,所以我的问题是如何使用Java代码设置边缘标签?

如果要在边缘文档中使用“边缘标签”来表示字段,则可以在调用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);

除了使用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);

或创建自己的POJO代表您的优势。 边缘至少需要字段_from_to 如果不想命名POJO _from和_to中的字段,则可以在Type.TO的两个String字段上使用注释DocumentField ,其值分别为Type.FROMType.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM