2016-01-29 119 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