Monday 7 February 2022

JanusGraph: get incoming vertex of the edge

‘inVertex’ method return the incoming vertex of the edge.

 

Example

JanusGraphVertex janusGraphVertex = janusGraphEdge.inVertex();

 

Find the below working application.

 

EdgeIncomingVertex.java

package com.sample.app.edges;

import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphEdge;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.JanusGraphVertex;

public class EdgeIncomingVertex {
	public static void main(String args[]) {

		try (JanusGraph janusGraph = JanusGraphFactory.open("/Users/Shared/janus.properties")) {
			// Create a person vertex
			JanusGraphVertex krishnaVertex = janusGraph.addVertex("person");
			krishnaVertex.property("name", "Krishna");
			krishnaVertex.property("age", 31);
			krishnaVertex.property("gender", 'M');

			// Create a person vertex
			JanusGraphVertex ramVertex = janusGraph.addVertex("person");
			ramVertex.property("name", "Ram");
			ramVertex.property("age", 34);
			ramVertex.property("gender", 'M');

			JanusGraphEdge janusGraphEdge = ramVertex.addEdge("knows", krishnaVertex, "from", 2017, "colleague", "N");

			janusGraph.tx().commit();

			JanusGraphVertex janusGraphVertex = janusGraphEdge.inVertex();
			System.out.println("Incoming vertex is : " + janusGraphVertex.property("name").value());

		} finally {
			System.out.println("\nDone!!!");
		}

	}
}

Output

Incoming vertex is : Krishna

Done!!!



Previous                                                 Next                                                 Home

No comments:

Post a Comment