Search in sources :

Example 1 with Vertex

use of org.vertexium.Vertex in project vertexium by visallo.

the class SetClauseExecutor method executeSetNodeLabels.

private void executeSetNodeLabels(VertexiumCypherQueryContext ctx, CypherSetNodeLabels setItem, VertexiumCypherScope.Item item) {
    Object left = ctx.getExpressionExecutor().executeExpression(ctx, setItem.getLeft(), item);
    VertexiumCypherTypeErrorException.assertType(left, Vertex.class, null);
    if (left == null) {
        return;
    }
    Vertex vertex = (Vertex) left;
    ExistingElementMutation<Vertex> m = vertex.prepareMutation();
    for (CypherLabelName labelName : setItem.getRight()) {
        ctx.setLabelProperty(m, labelName.getValue());
    }
    ctx.saveVertex(m);
}
Also used : Vertex(org.vertexium.Vertex)

Example 2 with Vertex

use of org.vertexium.Vertex in project vertexium by visallo.

the class LabelsFunction method invoke.

@Override
public Object invoke(VertexiumCypherQueryContext ctx, CypherAstBase[] arguments, ExpressionScope scope) {
    CypherAstBase lookup = arguments[0];
    Object item = ctx.getExpressionExecutor().executeExpression(ctx, lookup, scope);
    if (item == null) {
        throw new VertexiumException("Could not find Vertex using " + lookup);
    }
    if (item instanceof Vertex) {
        Vertex vertex = (Vertex) item;
        return ctx.getVertexLabels(vertex);
    }
    if (item instanceof Edge) {
        Edge edge = (Edge) item;
        return Lists.newArrayList(edge.getLabel());
    }
    throw new VertexiumCypherTypeErrorException(item, Vertex.class, Edge.class);
}
Also used : Vertex(org.vertexium.Vertex) VertexiumCypherTypeErrorException(org.vertexium.cypher.exceptions.VertexiumCypherTypeErrorException) CypherAstBase(org.vertexium.cypher.ast.model.CypherAstBase) Edge(org.vertexium.Edge) VertexiumException(org.vertexium.VertexiumException)

Example 3 with Vertex

use of org.vertexium.Vertex in project vertexium by visallo.

the class LazyVertexMap method get.

public Object get(String vertexId) {
    if (vertexId.endsWith("*")) {
        String vertexIdPrefix = vertexId.substring(0, vertexId.length() - 1);
        Iterable<Vertex> vertices = getGraph().getVerticesWithPrefix(vertexIdPrefix, getGraph().getDefaultFetchHints(), getTime(), getAuthorizations());
        List<String> results = new ArrayList<>();
        for (Vertex v : vertices) {
            results.add(v.getId());
        }
        return new LazyVertexList(results);
    } else {
        Vertex v = getGraph().getVertex(vertexId, getGraph().getDefaultFetchHints(), getTime(), getAuthorizations());
        if (v == null) {
            return null;
        }
        return new LazyVertex(vertexId);
    }
}
Also used : Vertex(org.vertexium.Vertex) ArrayList(java.util.ArrayList)

Aggregations

Vertex (org.vertexium.Vertex)3 ArrayList (java.util.ArrayList)1 Edge (org.vertexium.Edge)1 VertexiumException (org.vertexium.VertexiumException)1 CypherAstBase (org.vertexium.cypher.ast.model.CypherAstBase)1 VertexiumCypherTypeErrorException (org.vertexium.cypher.exceptions.VertexiumCypherTypeErrorException)1