Search in sources :

Example 56 with OrientVertex

use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.

the class OSQLFunctionShortestPath method walkLeft.

protected List<ORID> walkLeft(final OSQLFunctionShortestPath.OShortestPathContext ctx) {
    ArrayDeque<OrientVertex> nextLevelQueue = new ArrayDeque<OrientVertex>();
    while (!ctx.queueLeft.isEmpty()) {
        ctx.current = ctx.queueLeft.poll();
        Iterable<Vertex> neighbors;
        if (ctx.edgeType == null) {
            neighbors = ctx.current.getVertices(ctx.directionLeft);
        } else {
            neighbors = ctx.current.getVertices(ctx.directionLeft, ctx.edgeTypeParam);
        }
        for (Vertex neighbor : neighbors) {
            final OrientVertex v = (OrientVertex) neighbor;
            final ORID neighborIdentity = v.getIdentity();
            if (ctx.rightVisited.contains(neighborIdentity)) {
                ctx.previouses.put(neighborIdentity, ctx.current.getIdentity());
                return computePath(ctx.previouses, ctx.nexts, neighborIdentity);
            }
            if (!ctx.leftVisited.contains(neighborIdentity)) {
                ctx.previouses.put(neighborIdentity, ctx.current.getIdentity());
                nextLevelQueue.offer(v);
                ctx.leftVisited.add(neighborIdentity);
            }
        }
    }
    ctx.queueLeft = nextLevelQueue;
    return null;
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) ORID(com.orientechnologies.orient.core.id.ORID) ArrayDeque(java.util.ArrayDeque)

Example 57 with OrientVertex

use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.

the class OSQLFunctionShortestPath method walkRight.

protected List<ORID> walkRight(final OSQLFunctionShortestPath.OShortestPathContext ctx) {
    final ArrayDeque<OrientVertex> nextLevelQueue = new ArrayDeque<OrientVertex>();
    while (!ctx.queueRight.isEmpty()) {
        ctx.currentRight = ctx.queueRight.poll();
        Iterable<Vertex> neighbors;
        if (ctx.edgeType == null) {
            neighbors = ctx.currentRight.getVertices(ctx.directionRight);
        } else {
            neighbors = ctx.currentRight.getVertices(ctx.directionRight, ctx.edgeTypeParam);
        }
        for (Vertex neighbor : neighbors) {
            final OrientVertex v = (OrientVertex) neighbor;
            final ORID neighborIdentity = v.getIdentity();
            if (ctx.leftVisited.contains(neighborIdentity)) {
                ctx.nexts.put(neighborIdentity, ctx.currentRight.getIdentity());
                return computePath(ctx.previouses, ctx.nexts, neighborIdentity);
            }
            if (!ctx.rightVisited.contains(neighborIdentity)) {
                ctx.nexts.put(neighborIdentity, ctx.currentRight.getIdentity());
                nextLevelQueue.offer(v);
                ctx.rightVisited.add(neighborIdentity);
            }
        }
    }
    ctx.queueRight = nextLevelQueue;
    return null;
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) ORID(com.orientechnologies.orient.core.id.ORID) ArrayDeque(java.util.ArrayDeque)

Example 58 with OrientVertex

use of com.tinkerpop.blueprints.impls.orient.OrientVertex 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)

Example 59 with OrientVertex

use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.

the class OSQLFunctionHeuristicPathFinderAbstract method getNeighbors.

protected Set<OrientVertex> getNeighbors(final OrientVertex node) {
    context.incrementVariable("getNeighbors");
    final Set<OrientVertex> neighbors = new HashSet<OrientVertex>();
    if (node != null) {
        for (Vertex v : node.getVertices(paramDirection, paramEdgeTypeNames)) {
            final OrientVertex ov = (OrientVertex) v;
            if (ov != null)
                neighbors.add(ov);
        }
    }
    return neighbors;
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex)

Example 60 with OrientVertex

use of com.tinkerpop.blueprints.impls.orient.OrientVertex in project orientdb by orientechnologies.

the class OSQLFunctionIn method fetchFromIndex.

private Object fetchFromIndex(OrientBaseGraph graph, OIdentifiable iFrom, Iterable<OIdentifiable> iTo, String[] iEdgeTypes) {
    String edgeClassName = null;
    if (iEdgeTypes == null) {
        edgeClassName = "E";
    } else if (iEdgeTypes.length == 1) {
        edgeClassName = iEdgeTypes[0];
    } else {
        return null;
    }
    OClass edgeClass = graph.getRawGraph().getMetadata().getSchema().getClass(edgeClassName);
    if (edgeClass == null) {
        return null;
    }
    Set<OIndex<?>> indexes = edgeClass.getInvolvedIndexes("in", "out");
    if (indexes == null || indexes.size() == 0) {
        return null;
    }
    OIndex index = indexes.iterator().next();
    OMultiCollectionIterator<OrientVertex> result = new OMultiCollectionIterator<OrientVertex>();
    for (OIdentifiable to : iTo) {
        OCompositeKey key = new OCompositeKey(iFrom, to);
        Object indexResult = index.get(key);
        if (indexResult instanceof OIdentifiable) {
            indexResult = Collections.singleton(indexResult);
        }
        Set<OIdentifiable> identities = new HashSet<OIdentifiable>();
        for (OIdentifiable edge : ((Iterable<OrientEdge>) indexResult)) {
            identities.add((OIdentifiable) ((ODocument) edge.getRecord()).rawField("in"));
        }
        result.add(identities);
    }
    return result;
}
Also used : OIndex(com.orientechnologies.orient.core.index.OIndex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) OMultiCollectionIterator(com.orientechnologies.common.collection.OMultiCollectionIterator) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) HashSet(java.util.HashSet) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)155 Test (org.junit.Test)73 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)42 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)40 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)37 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)35 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)26 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)25 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)25 Vertex (com.tinkerpop.blueprints.Vertex)24 HashMap (java.util.HashMap)20 OBasicCommandContext (com.orientechnologies.orient.core.command.OBasicCommandContext)13 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)13 OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)13 Edge (com.tinkerpop.blueprints.Edge)12 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)10 GraphNoTxAbstractTest (com.orientechnologies.orient.graph.GraphNoTxAbstractTest)9 ORID (com.orientechnologies.orient.core.id.ORID)7 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)7 GraphTxAbstractTest (com.orientechnologies.orient.graph.GraphTxAbstractTest)7