Friday, 4 February 2022

JanusGraph: Get the id of edge

id() method return the unique identifier of the edge.

 

Example

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

 

Find the below working application.

 

GetEdgeId.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 GetEdgeId {
	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();

			Object id = janusGraphEdge.id();
			System.out.println("id : " + id);
		} finally {

			System.out.println("Done!!!");
		}

	}
}

 

Output

id : 1crw8x-1crx1k-azv9-oe08g
Done!!!

 

 

 

 

 

Previous                                                 Next                                                 Home

No comments:

Post a Comment