2016-01-29 47 views
0

我试图通过从Java运行OrientDb命令来获取多个值。具体而言,我试图获取链接到顶点和边的@rid的顶点列表。Orient DB Java Api返回多个值

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

我能做到这一点在东方工作室通过运行查询:

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();  

回答

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 
+0

嗨,你有没有机会尝试代码? – LucaS

+0

我能够使用getEdges(Direction.IN,..)和getEdges(Direction.OUT,..)获取边。谢谢回复。 – Sanal