我一直在尝试浏览文档。我只是想找到一个简单的示例,以便将2个顶点相互连接时进行标识(如标题中所述)。这适用于使用tinkerpop API蓝图2.6的OrientDB 3。 例如: 顶点v1; 顶点v2;
boolean connected = false;
connected = <somefunction returns true/false if v1 and v2 connected by an edge>;
如果有人看到过这样的东西,可以请提供一个例子吗?
答案 0 :(得分: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());
}
}
希望对您有帮助
致谢
答案 1 :(得分: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())) {
}