2017-07-17 66 views
0

我是OrientDB和藍圖的新手。我正在嘗試使用OrientDB Java API執行簡單的MATCH查詢。下面是我的代碼:Orientdb與OCommandSQL匹配返回null頂點

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); 
} 

}

當我運行它給我的頂點空。簡單的Select * from Person工作正常,並返回非零頂點。我正在使用OrientDB的2.2.22版本。

任何鏈接或提示將不勝感激。謝謝!

回答

3

下面的鏈接是非常有用的http://useof.org/java-open-source/com.orientechnologies.orient.core.metadata.schema.OSchemaProxy

其實我們需要在比賽上的查詢返回$elements

下面的代碼工作:

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); 
} 
} 

希望它會幫助別人。謝謝!