2017-07-17 1 views
0

Je suis nouveau sur OrientDB et blueprint. J'essaie d'exécuter une requête MATCH simple en utilisant l'API OrientDB Java. Ci-dessous mon code:Orientdb Match avec OCommandSQL renvoie des sommets nuls

import com.orientechnologies.orient.core.sql.OCommandSQL; 
import com.tinkerpop.blueprints.TransactionalGraph; 
import com.tinkerpop.blueprints.Vertex; 
import com.tinkerpop.blueprints.impls.orient.OrientGraph; 

public class OrientApp { 

@SuppressWarnings("unchecked") 
public static void main(String[] args) { 

    TransactionalGraph graph = new OrientGraph("remote:localhost/GratefulDeadConcerts", "admin", "admin"); 
    /* 
    * Iterable<Vertex> vertices = (Iterable<Vertex>) (((OrientGraph) graph) 
    * .command(new OCommandSQL(
    * "MATCH {class: Person, as: liker} -likes- {class:Person, as: like},{as:liker} -living_in- {class: City, where: (name='Bangalore')},{as:like} -living_in- {class: City, where: (name='Delhi')} RETURN liker.name,like.name" 
    *)) .execute()); 
    */ 

    Iterable<Vertex> vertices = (Iterable<Vertex>) (((OrientGraph) graph) 
      .command(new OCommandSQL("MATCH {class: Person, as: person} RETURN person")).execute()); 

    /* 
    * Iterable<Vertex> vertices = (Iterable<Vertex>) (((OrientGraph) graph) 
    * .command(new OCommandSQL("select * from person")).execute()); 
    */for (Vertex v : vertices) { 
     System.out.println(v); 
    } 
    System.out.println(graph); 
} 

}

Quand je lance il me donne nulle dans vertices. Le Select * from Person fonctionne très bien et renvoie des sommets non nuls. J'utilise la version 2.2.22 d'OrientDB.

Tous les liens ou astuces seront appréciés. Merci!

Répondre

3

lien suivant est utile http://useof.org/java-open-source/com.orientechnologies.orient.core.metadata.schema.OSchemaProxy

En fait, nous avons besoin de revenir $elements dans la requête match.

code suivant travaillé:

import com.orientechnologies.orient.core.sql.OCommandSQL; 
import com.tinkerpop.blueprints.TransactionalGraph; 
import com.tinkerpop.blueprints.Vertex; 
import com.tinkerpop.blueprints.impls.orient.OrientGraph; 

public class OrientApp { 

@SuppressWarnings("unchecked") 
public static void main(String[] args) { 

    TransactionalGraph graph = new OrientGraph("remote:localhost/GratefulDeadConcerts", "admin", "admin"); 
    Iterable<Vertex> vertices = (Iterable<Vertex>) (((OrientGraph) graph) 
      .command(new OCommandSQL("MATCH {class: Person, as: person, where: (age>10)} RETURN $elements")) 
      .execute()); 

    for (Vertex v : vertices) { 
     System.out.println(v.getProperty("age").toString()); 
    } 
    System.out.println(graph); 
} 
} 

espère que ça va aider quelqu'un. Merci!