Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Orientdb与OCommandSQL的匹配返回空顶点_Java_Orientdb_Orientdb2.2_Tinkerpop Blueprint - Fatal编程技术网

Java Orientdb与OCommandSQL的匹配返回空顶点

Java Orientdb与OCommandSQL的匹配返回空顶点,java,orientdb,orientdb2.2,tinkerpop-blueprint,Java,Orientdb,Orientdb2.2,Tinkerpop Blueprint,我是OrientDB和blueprint的新手。我正在尝试使用OrientDB Java API执行简单的匹配查询。下面是我的代码: import com.orientechnologies.orient.core.sql.OCommandSQL; import com.tinkerpop.blueprints.TransactionalGraph; import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.i

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

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人员工作正常,返回的顶点不为空。我正在使用OrientDB的2.2.22版本

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

下面的链接很有用

实际上,我们需要在匹配查询中返回$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);
}
}
希望它能帮助别人。谢谢

下面的链接很有用

实际上,我们需要在匹配查询中返回$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);
}
}
希望它能帮助别人。谢谢