Tom Quarendon
Tom Quarendon

Reputation: 5716

OrientDB Graph API: process results of SQL query

I'm exploring ways of interacting with OrientDB graphs. I'm writing java code, so I'm using some kind of java API. Since tinkerpop is described as the "JDBC" of graph databases, I naively assumed there would be an equivalent of executing a query and then processing the result set.

From a graph, I can call something like:

graph.command(new OCommandSQL("SELECT FROM class")).execute();

Then what? The "execute" method returns an Object, not very helpful. By printing out the class name of the result object, it seems to be a "OrientDynaElementIterable", whatever that is.

So I'm not sure I understand how I run a query and then iterate over the results. In general I actually don't understand tinkerpop, as I'm dealing with a load of OrientDB specific classes that are curiously part of the tinkerpop specification, so how does that make my code portable across graph databases?

Upvotes: 1

Views: 468

Answers (1)

Davide Lorenzo MARINO
Davide Lorenzo MARINO

Reputation: 26946

From a graph command you retrieve an Iterable of Vertex.

for (Vertex v : (Iterable<Vertex>) graph.command
                       (new OCommandSQL("SELECT FROM class").execute()) {
     // Do something with vertex v
}

The documentation can be retrieved here where you can find the following example

for (Vertex v : (Iterable<Vertex>) graph.command(
            new OCommandSQL("SELECT EXPAND( out('bought') ) FROM Customer WHERE name = 'Jay'")).execute()) {
    System.out.println("- Bought: " + v);
}

Upvotes: 1

Related Questions