Search in sources :

Example 51 with OrientVertex

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

the class OSQLFunctionLabel method getLabel.

private Object getLabel(final OrientBaseGraph graph, final OIdentifiable iCurrentRecord) {
    final ODocument rec = iCurrentRecord.getRecord();
    OImmutableClass immutableClass = ODocumentInternal.getImmutableSchemaClass(rec);
    if (immutableClass.isVertexType()) {
        // VERTEX
        final OrientVertex vertex = graph.getVertex(iCurrentRecord);
        return vertex.getLabel();
    } else if (immutableClass.isEdgeType()) {
        // EDGE
        final OrientEdge edge = graph.getEdge(iCurrentRecord);
        return edge.getLabel();
    } else
        throw new OCommandExecutionException("Invalid record: is neither a vertex nor an edge. Found class: " + immutableClass);
}
Also used : OImmutableClass(com.orientechnologies.orient.core.metadata.schema.OImmutableClass) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 52 with OrientVertex

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

the class OSQLFunctionMove method v2v.

protected Object v2v(final OrientBaseGraph graph, final OIdentifiable iRecord, final Direction iDirection, final String[] iLabels) {
    final ODocument rec = iRecord.getRecord();
    OImmutableClass immutableClass = ODocumentInternal.getImmutableSchemaClass(rec);
    if (immutableClass != null && immutableClass.isVertexType()) {
        // VERTEX
        final OrientVertex vertex = graph.getVertex(rec);
        if (vertex != null)
            return vertex.getVertices(iDirection, iLabels);
    }
    return null;
}
Also used : OImmutableClass(com.orientechnologies.orient.core.metadata.schema.OImmutableClass) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 53 with OrientVertex

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

the class OSQLFunctionPathFinder method execute.

protected LinkedList<OrientVertex> execute(final OCommandContext iContext) {
    context = iContext;
    unSettledNodes = new HashSet<OrientVertex>();
    distance = new HashMap<ORID, Float>();
    predecessors = new HashMap<ORID, OrientVertex>();
    distance.put(paramSourceVertex.getIdentity(), MIN);
    unSettledNodes.add(paramSourceVertex);
    int maxDistances = 0;
    int maxSettled = 0;
    int maxUnSettled = 0;
    int maxPredecessors = 0;
    while (continueTraversing()) {
        final OrientVertex node = getMinimum(unSettledNodes);
        unSettledNodes.remove(node);
        findMinimalDistances(node);
        if (distance.size() > maxDistances)
            maxDistances = distance.size();
        if (unSettledNodes.size() > maxUnSettled)
            maxUnSettled = unSettledNodes.size();
        if (predecessors.size() > maxPredecessors)
            maxPredecessors = predecessors.size();
        if (!isVariableEdgeWeight() && distance.containsKey(paramDestinationVertex.getIdentity()))
            // FOUND
            break;
        if (!OCommandExecutorAbstract.checkInterruption(context))
            break;
    }
    context.setVariable("maxDistances", maxDistances);
    context.setVariable("maxSettled", maxSettled);
    context.setVariable("maxUnSettled", maxUnSettled);
    context.setVariable("maxPredecessors", maxPredecessors);
    distance = null;
    return getPath();
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) ORID(com.orientechnologies.orient.core.id.ORID)

Example 54 with OrientVertex

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

the class OSQLFunctionPathFinder method getPath.

/*
   * This method returns the path from the source to the selected target and NULL if no path exists
   */
public LinkedList<OrientVertex> getPath() {
    final LinkedList<OrientVertex> path = new LinkedList<OrientVertex>();
    OrientVertex step = paramDestinationVertex;
    // Check if a path exists
    if (predecessors.get(step.getIdentity()) == null)
        return null;
    path.add(step);
    while (predecessors.get(step.getIdentity()) != null) {
        step = predecessors.get(step.getIdentity());
        path.add(step);
    }
    // Put it into the correct order
    Collections.reverse(path);
    return path;
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) LinkedList(java.util.LinkedList)

Example 55 with OrientVertex

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

the class OSQLFunctionPathFinder method getNeighbors.

protected Set<OrientVertex> getNeighbors(final Vertex node) {
    context.incrementVariable("getNeighbors");
    final Set<OrientVertex> neighbors = new HashSet<OrientVertex>();
    if (node != null) {
        for (Vertex v : node.getVertices(paramDirection)) {
            final OrientVertex ov = (OrientVertex) v;
            if (ov != null && isNotSettled(ov))
                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) HashSet(java.util.HashSet)

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