Search in sources :

Example 1 with OrientElementIterable

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;
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) ScriptEngine(javax.script.ScriptEngine) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) OGremlinHelper(com.orientechnologies.orient.graph.gremlin.OGremlinHelper) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) OrientElementIterable(com.tinkerpop.blueprints.impls.orient.OrientElementIterable)

Aggregations

ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 OGremlinHelper (com.orientechnologies.orient.graph.gremlin.OGremlinHelper)1 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)1 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)1 OrientElementIterable (com.tinkerpop.blueprints.impls.orient.OrientElementIterable)1 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)1 ScriptEngine (javax.script.ScriptEngine)1