Maik Wosnitzka

Java-Graph-Persistence

I am developing a framework for graph databases, like Amazon Neptune.

The Java-Graph-Persistence framework aims to simplify using graph databases which are accessible with Gremlin for Java applications. To achive that, annotations are provided to define how POJOs are to be represented in the graph database and how they are connected.

Thanks to that definition, objects can be stored in and read from the database: An automatic query builder will create Gremlin queries to add, update and delete graph elements. Custom gremlin queries can be executed and return the result as mapped POJOs elements, which contain all information as requested by the query.

Example usage of the framework

Define a Person as a vertex. A person can have a property called name as well as a birthplace.

@Getter
@Setter
public class Person extends GraphVertex {

  @Property
  private String name;

  @Edge
  private Place birthPlace;

}
		

The birthplace is declared as Place vertex and holds a property name.

@Getter
@Setter
public class Place extends GraphVertex {

  @Property
  private String name;

}
		

Now, let us autogenerate and execute our gremlin queries to add some data!

// Prepare entities
Person myPerson = new Person("Maik");
Place myPlace = new Place("Cologne");
myPerson.setBirthPlace(myPlace);

// Generate queries
GraphTraversalQueryBuilder queryBuilder = new GraphTraversalQueryBuilder();
List<GraphTraversalQuery> traversalQueries = queryBuilder.add(myPerson);

// use the auto-generated gremlin traversal queries, for example to store them
try (final TinkerGraph graph = TinkerGraph.open()){
    for (GraphTraversalQuery query : traversalQueries){
        query.execute(graph.traversal());
    }
}