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;
}
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;
}
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);
}
}
Aggregations