raycons
raycons

Reputation: 835

OrientDB get label from vertex and get relationship from vertex

I have two separate questions:

How can I get the label of a vertex object. I tried vertex.getId() .getClass() and similar but nothing is even close to the label I set to the vertex.

and, how can I get a relationship which connects any vertices of a set of vertices.

Iterable<Vertex> startNodes = getVertexList(relationshipStorage.getStartNode(), graph);
                Iterable<Vertex> endNodes = getVertexList(relationshipStorage.getEndNode(), graph);

                List<Edge> list = StreamSupport.stream(startNodes.spliterator(), false)
                        .flatMap(vertex1 -> StreamSupport.stream(vertex1.getEdges(Direction.OUT, relationshipId).spliterator(), false))
                        .filter(edge -> StreamSupport.stream(endNodes.spliterator(), false).anyMatch(vertex -> edge.getVertex(Direction.OUT).equals(vertex)))
                        .collect(Collectors.toList());

I am currently streaming through all the start vertices and looking if a relationship leaving them matches one of the end vertices. Isn't there nothing more nicer?

Upvotes: 0

Views: 143

Answers (1)

Alessandro Rota
Alessandro Rota

Reputation: 3570

You could use

vertex.getProperty("@class");

to get the name of the class of your vertex.

Upvotes: 1

Related Questions