ArangoDB创建Java中非空的图?

时间:2018-10-07 07:59:03

标签: java arangodb

我从ArangoGraphTest.java复制了以下代码:

private static final String GRAPH_NAME = "db_collection_test";
private static final String EDGE_COL_1 = "db_edge1_collection_test";
private static final String EDGE_COL_2 = "db_edge2_collection_test";
private static final String EDGE_COL_3 = "db_edge3_collection_test";
private static final String VERTEX_COL_1 = "db_vertex1_collection_test";
private static final String VERTEX_COL_2 = "db_vertex2_collection_test";
private static final String VERTEX_COL_3 = "db_vertex3_collection_test";
private static final String VERTEX_COL_4 = "db_vertex4_collection_test";
public static void testGraphCreate() {
    final ArangoDB arangoDB = new ArangoDB.Builder().user("root").password("root").build();
    final Collection<EdgeDefinition> edgeDefinitions = new ArrayList<EdgeDefinition>();
    edgeDefinitions.add(new EdgeDefinition().collection(EDGE_COL_1).from(VERTEX_COL_1).to(VERTEX_COL_2));
    edgeDefinitions
            .add(new EdgeDefinition().collection(EDGE_COL_2).from(VERTEX_COL_2).to(VERTEX_COL_1, VERTEX_COL_3));
    final GraphCreateOptions options = new GraphCreateOptions();
    ArangoDatabase db = arangoDB.db("TestArangoDB");
    db.createGraph(GRAPH_NAME, edgeDefinitions, options);

} 

运行此代码后,预期的图形db_collection_test出现在Web界面中,但显示“您的图形为空”。这是预期的吗?如果是这样,如何从Java创建非空图?

1 个答案:

答案 0 :(得分:0)

此代码仅在数据库中创建集合。除非您填充数据,否则不会有任何数据。您应根据需要创建所有顶点和边。 尝试使用此代码段创建一些数据:

BaseDocument myObject = new BaseDocument();
myObject.setKey("myKey");
myObject.addAttribute("a", "Foo");
myObject.addAttribute("b", 42);
try {
  arangoDB.db(dbName).collection(collectionName).insertDocument(myObject);
  System.out.println("Document created");
} catch (ArangoDBException e) {
  System.err.println("Failed to create document. " + e.getMessage());
}