0
votes

I'm trying to get multiple values by running an OrientDb command from Java. Specifically I am trying to get a list of Vertices that are linked to a vertex and the @rid of the Edges.

E.g If vertex V1 is linked to vertex V2 by edge E1, my query for V1 should return @rid of E1 and V2.

I can do that in Orient Studio by running the query:

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

How can I code the above query in Java? All the examples are showing only single value results like:

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

1 Answers

0
votes

I have this simple structure:

enter image description here

to get the RIDS, you can use this code:

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

    }

}

Output:

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