'implementing a spring boot application with Janus Graph DB

I have requirement which can be fulfilled by using a GraphDb and i have chosen JanusGraph, as it is open-source & free, but i couldn't find any credible material on how to connect&operate on "JanusGraph" using Spring Boot, I have tried exploring by myself but couldn't find any decent materials for spring-JanusGraph implementation.

Any suggestions on how to proceed with the implementation is appreciated.

Thanks In Advance.



Solution 1:[1]

If I may suggest, go with maven. add dependencies like

  1. janusgraph-core
  2. janusgraph-barkeleyje (or which one ever is it you are using)

and don't forget to create DB configuration file

this link might be helpful if you are using berkeleyDB (Embedded). https://linuxtut.com/en/9efdc2fca7e773d7689d/

for example , a simple maven dependency section will look like

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>




    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>


    <dependency>
        <groupId>org.janusgraph</groupId>
        <artifactId>janusgraph-core</artifactId>
        <version>0.6.1</version>
    </dependency>
    <dependency>
        <groupId>org.janusgraph</groupId>
        <artifactId>janusgraph-berkeleyje</artifactId>
        <version>0.6.1</version>
    </dependency>

</dependencies>

and a simple configuration file like

gremlin.graph=org.janusgraph.core.JanusGraphFactory
storage.backend=berkeleyje
storage.directory=../db/berkeley 

a simple endpoint to test it

@GetMapping("/test")
String all() {
    Graph graph = JanusGraphFactory.open("conf/berkeleydb.properties");//where ever it is stored
    GraphTraversalSource g = graph.traversal();
    //Add one vertex
    g.addV("person").property("name", "bob").property("age", 272).iterate();
    //Confirm change
    g.tx().commit();
    //Try issuing a query to retrieve the value
    List<Map<Object, Object>> result = g.V().valueMap("name", "age").toList();
    //The return value is[{name: ["bob"], age: [27]}]Should be returned
    for(Map<Object, Object> vertex : result){
        //vertex is{name:["bob"], age: [27]}Should be
        ArrayList<String> names = (ArrayList<String>)vertex.get("name");  // ["bob"]Get
        ArrayList<Integer> ages = (ArrayList<Integer>)vertex.get("age");  // [27]Get
        String name = names.get(0);  //"bob"Get
        Integer age = ages.get(0);  //Get 27
        System.out.printf("name: %s, age: %s\n", name, age);
    }
    //Try issuing a query to retrieve the number of vertices
    Long count = g.V().count().next();
    System.out.printf("vertex count is %d\n", count);

    try {
        graph.close();
    } catch (Exception ex) {
        //deal with it
    }

return " some result ";

}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Harsh