Search code examples
orientdb

How to query vertex as OrientVertex


I need update vertex and return it as ODocument. First, i query it, then update properties, and finally return it as ODocument.

But I only able to retrieve Vertex, not OrientVertex:

Vertex vPlace = graph.getVertices("id",id).iterator().next();

I found example in http://orientdb.com/docs/2.2/Graph-Blueprints.html:

Iterable<OrientVertex> results = g.query().has("name", EQUALS, "fast");

but it does not compile: "EQUALS" not found. How to query vertex as OrientVertex?


Solution

  • is this useful for you?

    String dbName = "testDB";
    
    OrientGraphFactory dbfactory = new OrientGraphFactory("remote:127.0.0.1:2424/"+dbName, "root", "root").setupPool(1, 50);
    
    OrientGraph db = dbfactory.getTx();
    
    try {
        String query = "select from V where name = ?";
    
        Iterable<OrientVertex> result = db.command(new OCommandSQL(query)).execute("testName");
    
        while(result.iterator().hasNext()){
            OrientVertex d = result.iterator().next();
    
            //do something with d
            System.out.println(d.getProperty("name"));
    
        }
    
    } catch (Exception e) {
                // TODO: handle exception
                System.out.println(e);
    }