2016-10-13 2 views
1

자바 콘솔에서 두 정점 사이의 가장 짧은 경로에 인쇄하고 싶습니다. 나는 아무것도 인쇄 할 수 없거나 그렇게 할 수있는 방법이 있다면 감사 할 것입니다.orientdb를 사용하여 자바 콘솔에 최단 경로 인쇄

String subquery = "Select shortestpath(17:10, 17:14, BOTH) "; 
Iterable<OrientVertex> result = orientDBGraph.command(new OSQLSynchQuery<OrientVertex>(subquery)).execute(); 
Assert.assertTrue(result.iterator().hasNext()); 
System.out.println(result); 

for (OrientVertex d : result) { 
    System.out.println("Shortest path from " + ((OrientVertex) d.getProperty("$current")).getProperty("name") + " and " 
    + ((Iterable<OrientVertex>) d.getProperty("$target")).iterator().next().getProperty("name") + " is: " 
    + d.getProperty("path")); 
} 
+0

사용중인 버전은 무엇? 전체 코드와 출력을 게시 할 수 있습니까? 오류가 있습니까? –

답변

3

enter image description here

코드 :

import com.orientechnologies.orient.core.sql.OCommandSQL; 
import com.tinkerpop.blueprints.impls.orient.OrientGraph; 
import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory; 
import com.tinkerpop.blueprints.impls.orient.OrientVertex; 

public class test { 

    public static void main(String[] args) { 
     // TODO Auto-generated method stub 

     String dbName = "ytrewa"; 

     OrientGraphFactory dbfactory = new OrientGraphFactory("remote:127.0.0.1:2424/"+dbName, "root", "root").setupPool(1, 50); 

     OrientGraph g = dbfactory.getTx(); 

     try { 
      String query = "select expand(shortestPath) from (select shortestPath(#9:0,#9:1,BOTH))"; 
      Iterable<OrientVertex> res = g.command(new OCommandSQL(query)).execute(); 

      while(res.iterator().hasNext()){ 
       OrientVertex v = res.iterator().next(); 
       System.out.println("rid: "+v.getId().toString()); 
      } 

     } finally { 
      g.shutdown(); 
     } 

    } 

} 

출력 :

rid: #9:0 
rid: #10:0 
rid: #12:0 
rid: #9:1 
+0

도움을 주셔서 감사합니다. 귀하의 코드로 해보려고했지만 아무 것도 나오지 않습니다. 전체 프로 시저를 넣을 수 있습니다 어쩌면 내 일부 오류를 찾으십시오 – Alexa

+1

전체 코드를 추가했습니다. 내 질문은 귀하의 질문과 약간 다릅니다. –