Awkward behaviour of GraphQuery

12 views
Skip to first unread message

Abhishek Jha

unread,
Apr 24, 2014, 4:56:32 AM4/24/14
to orient-...@googlegroups.com
Hey , 

I am using ORIENTDB - 1.7.RC2
Blueprint - 2.6.0 - SNAPSHOT

When I am doing this : 

OrientGraphQuery graphQuery = (OrientGraphQuery) graph.query();
Vertex base = null;
        if(!graphQuery.labels(associationEntity.getType().toString()).has("value",associationEntity.getValue()).vertices().iterator().hasNext()) {
            base = graph.addVertex("class:"+associationEntity.getType().toString(),"value",associationEntity.getValue());
        }
        else {
            base = graphQuery.labels(associationEntity.getType().toString()).has("value", associationEntity.getValue()).vertices().iterator().next();
        }

OrientGraphQuery newGraphQuery = (OrientGraphQuery) graph.query();
            Vertex connected = null;
            if(!newGraphQuery.labels(connectedVertexes.getType().toString()).has("value",connectedVertexes.getValue()).vertices().iterator().hasNext()) {
                connected = graph.addVertex("class:"+connectedVertexes.getType().toString(),"value",connectedVertexes.getValue());
            }
            else {
                connected = newGraphQuery.labels(connectedVertexes.getType().toString()).has("value",connectedVertexes.getValue()).vertices().iterator().next();
            }

As you can see for both the vertices I am using different instance of GraphQuery. Then results are : 

As you can see vertices aren't repeated.

But then if i change it to, 

OrientGraphQuery graphQuery = (OrientGraphQuery) graph.query();
Vertex base = null;
        if(!graphQuery.labels(associationEntity.getType().toString()).has("value",associationEntity.getValue()).vertices().iterator().hasNext()) {
            base = graph.addVertex("class:"+associationEntity.getType().toString(),"value",associationEntity.getValue());
        }
        else {
            base = graphQuery.labels(associationEntity.getType().toString()).has("value", associationEntity.getValue()).vertices().iterator().next();
        }


            Vertex connected = null;
            if(!graphQuery.labels(connectedVertexes.getType().toString()).has("value",connectedVertexes.getValue()).vertices().iterator().hasNext()) {
                connected = graph.addVertex("class:"+connectedVertexes.getType().toString(),"value",connectedVertexes.getValue());
            }
            else {
                connected = graphQuery.labels(connectedVertexes.getType().toString()).has("value",connectedVertexes.getValue()).vertices().iterator().next();
            }

Basically if i use same instance of graph query, then results are : 


Here you can see vertices are coming as different. Basically not that I wanted, because I want that if vertex exists, I should use it rather than creating a copy of it in graph.

Please Help !!!
Reply all
Reply to author
Forward
0 new messages