use of com.tinkerpop.blueprints.impls.orient.OrientElementIterable in project orientdb by orientechnologies.
the class OSQLFunctionGremlin method execute.
public Object execute(Object iThis, final OIdentifiable iCurrentRecord, Object iCurrentResult, final Object[] iParams, final OCommandContext iContext) {
final ODatabaseDocumentTx db = OGremlinHelper.getGraphDatabase(ODatabaseRecordThreadLocal.INSTANCE.get());
result = new ArrayList<Object>();
OGremlinHelper.execute(db, (String) iParams[0], null, (Map) iContext.getVariables(), result, new OGremlinHelper.OGremlinCallback() {
@Override
public boolean call(final ScriptEngine iEngine, final OrientBaseGraph iGraph) {
if (iCurrentRecord == null)
// IGNORE PRE-PROCESSING
return true;
final ODocument document = (ODocument) iCurrentRecord;
OClass clazz = ODocumentInternal.getImmutableSchemaClass(document);
if (clazz != null && clazz.isSubClassOf(OrientEdgeType.CLASS_NAME)) {
// EDGE TYPE, CREATE THE BLUEPRINTS'S WRAPPER
OrientEdge graphElement = (OrientEdge) new OrientElementIterable<OrientEdge>(iGraph, Arrays.asList(new ODocument[] { document })).iterator().next();
iEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("current", graphElement);
// FRAMES LIKE SYNTAX
iEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("it", graphElement);
} else {
// VERTEX TYPE, CREATE THE BLUEPRINTS'S WRAPPER
OrientVertex graphElement = (OrientVertex) new OrientElementIterable<OrientVertex>(iGraph, Arrays.asList(new ODocument[] { document })).iterator().next();
iEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("current", graphElement);
// FRAMES LIKE SYNTAX
iEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("it", graphElement);
}
return true;
}
}, null);
return result;
}
Aggregations