0
votes

I have a titan server running with following configurations

  1. Titan Graph with Cassandra as storage backend
  2. Gremlin Server with WebSocketChannelizer
  3. Titan version :titan-1.0.0-hadoop1

And I have a Java Application with Gremlin Driver 3.0.1-incubating which can open a client to connect to the remote gremlin server.

I am able to submit gremlin queries to create vertex and to get the results back with queries like g.V().

CompletableFuture<ResultSet> submitAsync = client.submitAsync("g.V()");
List<Result> list = submitAsync.get().all().get();

Now I want to convert these list into List<Person>

Is there any Object Mapper available for gremlin driver/gremlin server ?

2

2 Answers

1
votes

There is no such mapper that I am aware of. Keep an eye on this issue:

https://issues.apache.org/jira/browse/TINKERPOP3-575

When that completes then existing ORMs will work over Gremlin Server. For now, you would have to do your own conversion of a Vertex to "person". Usually though, the pattern is to not necessarily return raw vertices but to return some transformation of those vertices to a Map construct that you can work with more generically on the client.

1
votes

Yes, there is. Please have a look at Peapod library on Github. You can use it to create your own classes to map all vertices and edges. Peapod uses code generation to implement the framed vertex and edge classes.

So for example,

@Vertex
public abstract class Person {
  public abstract String getName();
  public abstract void setName(String name);

  public abstract List<Knows> getKnows();
  public abstract Knows getKnows(Person person);
  public abstract Knows addKnows(Person person);
  public abstract Knows removeKnows(Person person);
}

@Edge
public abstract class Knows {
  public abstract void setYears(int years);
  public abstract int getYears();
}

And then, you can use it like this:

public void testClassic() {
    Graph g = TinkerFactory.createClassic();
    FramedGraph graph = new FramedGraph(g, Person.class.getPackage());

    Person marko = graph.v(1, Person.class);
    assertEquals("marko", marko.getName());

    Person vadas = graph.v(2, Person.class);
    Person josh = graph.v(4, Person.class);

    List<Person> result = graph.V(Person.class).has("name", "josh").toList();
    assertThat(result, contains(josh));

    assertThat(marko.getKnows(), containsInAnyOrder(vadas, josh));
}

Enjoy.

And by the way, have a look here for other useful Tinkerpop awesome unofficial libraries.

DISCLAIMER: I'm a contributor to Peapod and owner of awesome-tinkerpop library.