Hi,

I can't get Vertex's getVertices() method to work correctly from inside an 
OSQLAsynchQuery. It never returns any vertices, even when the vertex has 
edges connected to it. With OSQLSynchQuery, everything works. Moreover, if 
I do an OSQLSynchQuery first, and *then* and OSQLAsynchQuery with the same 
vertex, it suddenly works (possibly because some type of caching?).

This looks remarkably similar to this old OrientDB issue 
<https://github.com/orientechnologies/orientdb/issues/2028>, but since that 
one was closed ages ago, I guess my problem must be something else. Is it a 
bug, or am I doing something wrong?

Here is a short example program:

package odbtest;

import com.orientechnologies.orient.core.command.OCommandResultListener;
import com.orientechnologies.orient.core.sql.query.OSQLAsynchQuery;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;

public class Foo {

    public static void TestSynchQuery(OrientGraph graph, String query) {
        System.out.println("\n\nTesting OSQLSynchQuery:");

        Iterable<Vertex> vs = graph.command(
                new OSQLSynchQuery<Vertex>(query)
        ).execute();

        for (Vertex v1 : vs) {
            System.out.println("v1: " + v1);
            for (Vertex v2 : v1.getVertices(Direction.OUT)) {
                System.out.println("   v2: " + v2);
            }
        }
    }

    public static void TestAsynchQuery(OrientGraph graph, String query) {
        System.out.println("\n\nTesting OSQLASynchQuery:");

        graph.command(
                new OSQLAsynchQuery<Vertex>(
                        query,
                        new OCommandResultListener() {
                            @Override public boolean result(Object o) {
                                Vertex v1 = graph.getVertex(o);
                                System.out.println("v1: " + v1);
                                for (Vertex v2 : v1.getVertices(Direction.OUT)) 
{
                                    System.out.println("   v2: " + v2);
                                }
                                return true;
                            }

                            @Override public void end() { }
                        })
        ).execute();
    }

    public static void main(String[] args) {
        final OrientGraph graph = new OrientGraph("remote:localhost/Test", 
"root", "root");

        // Create vertice and edge types
        graph.createVertexType("MyVertexType-1");
        graph.createVertexType("MyVertexType-2");
        graph.createEdgeType("MyEdgeType");

        // Add two vertices with an edge between them.
        OrientVertex v1 = graph.addVertex("class:MyVertexType-1");
        OrientVertex v2 = graph.addVertex("class:MyVertexType-2");
        graph.addEdge("class:MyEdgeType", v1, v2, null);

        graph.commit();

        // Testing asynch query for the first time. Doesn't work:
        TestAsynchQuery(graph, "select from MyVertexType-1");

        // Testing synch query for the first time. Works:
        TestSynchQuery(graph, "select from MyVertexType-1");

        // Testing asynch query for the second time. This time it works:
        TestAsynchQuery(graph, "select from MyVertexType-1");
    }

} 

Here's the program output:

Testing OSQLASynchQuery:
v1: v(MyVertexType-1)[#33:0]


Testing OSQLSynchQuery:
v1: v(MyVertexType-1)[#33:0]
   v2: v(MyVertexType-2)[#34:0]


Testing OSQLASynchQuery:
v1: v(MyVertexType-1)[#33:0]
   v2: v(MyVertexType-2)[#34:0]

As you can see, the first time TestAsynchQuery is called, no connected 
vertices are found. The second time it is called, after doing the 
corresponding synch query in between, OrientDB correctly finds the 
connected vertex.

Best wishes,
Tord

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to