Monday 7 February 2022

JasunGraph: Relationship types

In JanusGraph, both edge labels and property keys are considered as relationship types. As per the documentation, RelationType names must be unique in a graph database, that means edge labels and property keys may not have the same name.

 

Below snippet is used to get relationship type by name.

RelationType relationType = janusGraphManagement.getRelationType("favoritePlaces");

 

Find the below working application.

 

GetRelationshipTypes.java

package com.sample.app.schema;

import org.janusgraph.core.Cardinality;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.RelationType;
import org.janusgraph.core.schema.JanusGraphManagement;
import org.janusgraph.core.schema.PropertyKeyMaker;

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

		try (JanusGraph janusGraph = JanusGraphFactory.open("/Users/Shared/janus.properties")) {

			JanusGraphManagement janusGraphManagement = janusGraph.openManagement();

			PropertyKeyMaker propertyKeyMaker = janusGraphManagement.makePropertyKey("favoritePlaces");
			propertyKeyMaker.cardinality(Cardinality.SET);
			propertyKeyMaker.dataType(String.class);

			propertyKeyMaker.make();

			janusGraph.tx().commit();

			RelationType relationType = janusGraphManagement.getRelationType("favoritePlaces");

			if (relationType.isPropertyKey()) {
				System.out.println("Given relationship is a property key");
			}

			if (relationType.isEdgeLabel()) {
				System.out.println("Given relationship is an edge label");
			}

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

	}
}

 

Output

Given relationship is a property key

Done!!!

 

 

 

 

 

Previous                                                 Next                                                 Home

No comments:

Post a Comment