Search in sources :

Example 1 with GremlinGroovyScriptEngine

use of org.apache.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 2 with GremlinGroovyScriptEngine

use of org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine in project orientdb by orientechnologies.

the class OGremlinEngineThreadLocal method get.

public ScriptEngine get(final OrientBaseGraph iGraph) {
    ScriptEngine engine = super.get();
    if (engine != null) {
        final OrientBaseGraph currGraph = (OrientBaseGraph) engine.getBindings(ScriptContext.ENGINE_SCOPE).get("g");
        if (currGraph == iGraph || (currGraph != null && currGraph.getRawGraph().getURL().equals(iGraph.getRawGraph().getURL()))) {
            // REUSE IT
            engine.getBindings(ScriptContext.ENGINE_SCOPE).put("g", iGraph);
            return engine;
        }
    }
    // CREATE A NEW ONE
    engine = new GremlinGroovyScriptEngine();
    engine.getBindings(ScriptContext.ENGINE_SCOPE).put("g", iGraph);
    set(engine);
    return engine;
}
Also used : GremlinGroovyScriptEngine(com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) ScriptEngine(javax.script.ScriptEngine) GremlinGroovyScriptEngine(com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine)

Example 3 with GremlinGroovyScriptEngine

use of org.apache.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)2 Function (com.google.common.base.Function)1 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)1 GremlinGroovyScriptEngine (com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine)1 HashSet (java.util.HashSet)1 Bindings (javax.script.Bindings)1 ScriptEngine (javax.script.ScriptEngine)1 ScriptException (javax.script.ScriptException)1 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)1 CompilerCustomizerProvider (org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider)1 DefaultImportCustomizerProvider (org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider)1