Search code examples
orientdbtinkerpop3

OrientDB java API with tinkerpop 3


what is the best API for Orient to Java for 3.0 snapshot?and how do I 1. connect 2. execute CRUD 3. execute native queries (SQL/Javascript).

Started with orientdb-gremlin but not yet upto speed, so wanted to check with community.

Thanks Hari


Solution

  • This is an example of db connection and execution of an SQL query:

    public static void main(String[] args) {
    
        String DBname="Test";
        String currentPath="remote:localhost/"+DBname;
    
        OServerAdmin serverAdmin;
        try {
            serverAdmin = new OServerAdmin(currentPath).connect("root", "root"); 
            if(serverAdmin.existsDatabase()){  
    
                OrientGraph g=new OrientGraph(currentPath); 
    
                Iterable<Vertex> result=g.command(new OCommandSQL("select from Person")).execute(); 
                for(Vertex v:result){ 
                    String rid=v.getId().toString();
                    String name=v.getProperty("name");
                    String surname=v.getProperty("surname");
                    System.out.println(rid + " " + name + " " + surname);  
                }
    
                g.shutdown(); 
    
            }
            serverAdmin.close(); 
        } catch (IOException e) {
            e.printStackTrace(); 
        }   
    }
    

    Hope it helps.

    Regards,

    Michela