How to query/search/retrieve an Edge with a pair of Vertices in OrientDB using Java API?

173 views Asked by At

I'm developing a web application using OrientDB and the Java API. I have discovered that it is creating (ie. saving) duplicate Edges with the same Vertices.

How do I query whether an Edge exist (for the same pair of Vertices). (And if they do not exist, I'll then create a new Edge with the pair of Vertices.)

The Edge has been successfully created in the OrientDB with a class name, using:

openGraphNoTx.createEdgeType("Friendship");

The Edge has been successfully added like this:

openGraphTx.addEdge(null, fanV, influencerV, "Friendship");

So, I'd like to query/search with the fanV and influencerV vertices to retrieve any existing Edge if it already exist. How do I do this?

I tried using:

fanV.query() ... and build the query and then fanV.edges()... but can't figure out how to set the query parameters.

fanV.getEdges(Direction.IN, friend.getId().toString()); ... ??? can't fiture out how to set the query parameters.

... but can't figure it out.

Any help on how to search/query/retrieve an Edge in Java would be appreciated. Thanks!

1

There are 1 answers

0
ikevin8me On BEST ANSWER

I found the answer myself:

OrientVertex fanOrientV = transaction.getVertex(fanV.getId());
OrientVertex friendOrientV = transaction.getVertex(friendV.getId());
Iterable<Edge> edgesIterable = fanOrientV.getEdges(friendOrientV, Direction.OUT, "Friendship";

... will retrieve any existing Friendship edge.