Skip to content

Using Gremlin through Groovy

okram edited this page Jan 16, 2011 · 36 revisions

Gremlin works by using the metaprogramming facilities provided by Groovy. There is single Groovy class called Gremlin.groovy. To use Gremlin while in Groovy, simply do Gremlin.load() (be sure Gremlin is in the classpath).

Groovy Shell

Gremlin shell (gremlin.sh) is basically the Groovy shell| wrapped to have the Gremlin look and feel. For example, do \h at the gremlin> prompt.

marko:~$ groovysh 
Groovy Shell (1.7.2, JVM: 1.6.0_22)
Type 'help' or '\h' for help.
-------------------------------------------------------------------------------
groovy:000> com.tinkerpop.gremlin.Gremlin.load()

Groovy Classes

If you are using Groovy classes, its trivial to access Gremlin. In this way, your Java code and your Gremlin/Groovy code seamless interact through standard class mechanisms.

class SimpleExample {
  public List exampleMethod() {
    Gremlin.load()
    Graph g = TinkerGraphFactory.createTinkerGraph()
    def results = []
    g.v(1).outE.inV >> results
    return results;
  }
}