0

我是 OrientDB 和蓝图的新手。我正在尝试使用 OrientDB Java API 执行简单的 MATCH 查询。下面是我的代码:

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

}

当我运行时,它在 Vertices 中给了我 null。简单Select * from Person的工作正常并且不返回空顶点。我使用的是 2.2.22 版本的 OrientDB。

任何链接或提示将不胜感激。谢谢!

4

1 回答 1

3

以下链接很有用http://useof.org/java-open-source/com.orientechnologies.orient.core.metadata.schema.OSchemaProxy

实际上我们需要$elements在 Match 查询中返回。

以下代码有效:

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

希望它会帮助某人。谢谢!

于 2017-07-17T09:24:22.867 回答