0

我一直在尝试查看文档。我只是想找一个简单的例子来识别标题中提到的两个顶点是否相互连接。这适用于使用 tinkerpop API 蓝图 2.6 的 OrientDB 3。例如:顶点 v1;顶点v2;

boolean connected = false;

connected = <somefunction returns true/false if v1 and v2 connected by an edge>;

如果有人看到过这样的事情,可以举个例子吗?

4

2 回答 2

1

尝试这个:

String db_name = "dbname";
String path = "remote:localhost/" + db_name;

OrientDB orientDB = new OrientDB("remote:localhost", "username", "password", OrientDBConfig.defaultConfig());

try(ODatabaseSession db = orientDB.open(db_name,"username","password")) 
{
    ORID theEdge = new ORecordId("edge_rid");
    OEdge e = db.load(theEdge);

    ORID theVertex = new ORecordId("v1_rid");
    OVertex v1 = db.load(theVertex);

    ORID theVertex2 = new ORecordId("v2_rid");
    OVertex v2 = db.load(theVertex2);

    boolean connected = false;
    OVertex from = e.getFrom();
    OVertex to = e.getTo();

    if(from.getIdentity().equals(v1) && to.getIdentity().equals(v2))
    {
        connected = true;
    }

    if(connected)
    {
        System.out.println("Vertex v1: " + from.getIdentity());
        System.out.println("Vertex v2: " + to.getIdentity());
    }
}



希望能帮助到你

问候

于 2018-09-26T08:50:27.267 回答
0

您需要迭代一个顶点(v1)边并检查它是否连接到另一个顶点(v2):

OrientVertex v1,v2; 
for (Edge e : (Iterable<Edge>)() ->  v1.edges(Direction.OUT)) 
    if (e.vertices(Direction.IN).next().id().equals(v2.id())) {
    }
于 2018-09-28T17:34:19.577 回答