Search in sources :

Example 1 with GremlinGroovyScriptEngine

use of com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine in project atlas by apache.

the class AtlasJanusGraph method getGremlinScriptEngine.

@Override
public GremlinGroovyScriptEngine getGremlinScriptEngine() {
    Set<String> extraImports = new HashSet<String>();
    extraImports.add(java.util.function.Function.class.getName());
    Set<String> extraStaticImports = new HashSet<String>();
    extraStaticImports.add(P.class.getName() + ".*");
    extraStaticImports.add(__.class.getName() + ".*");
    CompilerCustomizerProvider provider = new DefaultImportCustomizerProvider(extraImports, extraStaticImports);
    GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(provider);
    return scriptEngine;
}
Also used : Function(com.google.common.base.Function) CompilerCustomizerProvider(org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider) GremlinGroovyScriptEngine(org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine) HashSet(java.util.HashSet) DefaultImportCustomizerProvider(org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider)

Example 2 with GremlinGroovyScriptEngine

use of com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine in project incubator-atlas by apache.

the class Titan1Graph method getGremlinScriptEngine.

@Override
public GremlinGroovyScriptEngine getGremlinScriptEngine() {
    Set<String> extraImports = new HashSet<String>();
    extraImports.add(java.util.function.Function.class.getName());
    Set<String> extraStaticImports = new HashSet<String>();
    extraStaticImports.add(P.class.getName() + ".*");
    extraStaticImports.add(__.class.getName() + ".*");
    CompilerCustomizerProvider provider = new DefaultImportCustomizerProvider(extraImports, extraStaticImports);
    GremlinGroovyScriptEngine scriptEngine = new GremlinGroovyScriptEngine(provider);
    return scriptEngine;
}
Also used : Function(com.google.common.base.Function) CompilerCustomizerProvider(org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider) GremlinGroovyScriptEngine(org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine) HashSet(java.util.HashSet) DefaultImportCustomizerProvider(org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider)

Example 3 with GremlinGroovyScriptEngine

use of com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine in project titan by thinkaurelius.

the class ScriptExecutor method evaluate.

protected static void evaluate(final Reader reader, final List<String> arguments) {
    final GremlinGroovyScriptEngine engine = new GremlinGroovyScriptEngine();
    final Bindings bindings = engine.createBindings();
    bindings.put("args", arguments.toArray());
    // TODO: Deprecate this
    if (arguments.size() > 0) {
        for (int i = 0; i < arguments.size(); i++) {
            bindings.put("a" + (i + 1), arguments.get(i));
        }
    }
    try {
        engine.eval(reader, bindings);
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
}
Also used : GremlinGroovyScriptEngine(com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine) Bindings(javax.script.Bindings)

Example 4 with GremlinGroovyScriptEngine

use of com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine in project atlas by apache.

the class AtlasJanusGraph method executeGremlinScript.

private Object executeGremlinScript(String gremlinQuery) throws AtlasBaseException {
    GremlinGroovyScriptEngine scriptEngine = getGremlinScriptEngine();
    try {
        Bindings bindings = scriptEngine.createBindings();
        bindings.put("graph", getGraph());
        bindings.put("g", getGraph().traversal());
        Object result = scriptEngine.eval(gremlinQuery, bindings);
        return result;
    } catch (ScriptException e) {
        throw new AtlasBaseException(AtlasErrorCode.GREMLIN_SCRIPT_EXECUTION_FAILED, e, gremlinQuery);
    } finally {
        releaseGremlinScriptEngine(scriptEngine);
    }
}
Also used : ScriptException(javax.script.ScriptException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) GremlinGroovyScriptEngine(org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine) Bindings(javax.script.Bindings)

Example 5 with GremlinGroovyScriptEngine

use of com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine in project incubator-atlas by apache.

the class Titan1Graph method executeGremlinScript.

private Object executeGremlinScript(String gremlinQuery) throws AtlasBaseException {
    GremlinGroovyScriptEngine scriptEngine = getGremlinScriptEngine();
    try {
        Bindings bindings = scriptEngine.createBindings();
        bindings.put("graph", getGraph());
        bindings.put("g", getGraph().traversal());
        Object result = scriptEngine.eval(gremlinQuery, bindings);
        return result;
    } catch (ScriptException e) {
        throw new AtlasBaseException(AtlasErrorCode.GREMLIN_SCRIPT_EXECUTION_FAILED, gremlinQuery);
    } finally {
        releaseGremlinScriptEngine(scriptEngine);
    }
}
Also used : ScriptException(javax.script.ScriptException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) GremlinGroovyScriptEngine(org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine) Bindings(javax.script.Bindings)

Aggregations

GremlinGroovyScriptEngine (org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine)4 Bindings (javax.script.Bindings)3 Function (com.google.common.base.Function)2 GremlinGroovyScriptEngine (com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine)2 HashSet (java.util.HashSet)2 ScriptException (javax.script.ScriptException)2 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)2 CompilerCustomizerProvider (org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider)2 DefaultImportCustomizerProvider (org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider)2 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)1 ScriptEngine (javax.script.ScriptEngine)1