Orient DB Java Api返回多个值

时间:2016-01-29 19:36:23

标签: orientdb

我正在尝试通过从Java运行OrientDb命令来获取多个值。具体来说,我试图获得一个链接到顶点和边缘@rid的顶点列表。

例如,如果顶点V1通过边缘E1链接到顶点V2,则我对V1的查询应该返回E1和V2的@rid

我可以通过运行查询在Orient Studio中执行此操作:

select @rid, expand(in) from ExampleEdge where out = '#14:33'

如何在Java中编写上述查询?所有示例仅显示单值结果,如:

Iterable<Vertex> vertexes = graph.command(new OCommandSQL("select expand(in()) from node where @rid = '#14:33'")).execute();    

1 个答案:

答案 0 :(得分:0)

我有这个简单的结构:

enter image description here

获取RIDS,您可以使用此代码:

String yourRid = "#12:0";
Iterable<Vertex> targets = g.command(new OSQLSynchQuery<Vertex>("select from ?")).execute(yourRid);

for (Vertex target : targets) {

Iterable<Edge> r = target.getEdges(Direction.IN, "exampleEdge");
List<Edge> results = new ArrayList<Edge>();
CollectionUtils.addAll(results, r.iterator());

    System.out.println("Starting Vertex: "+yourRid);
    System.out.println();

    for (Edge result:results){

        System.out.println("Edge "+result.getId()+" connected with Vertex "+result.getVertex(Direction.OUT).getId());

    }

}

<强>输出

Starting Vertex: #12:0

Edge #13:3 connected with Vertex #12:1
Edge #13:4 connected with Vertex #12:2
Edge #13:5 connected with Vertex #12:3