Package com.tinkerpop.blueprints

Examples of com.tinkerpop.blueprints.VertexQuery


        // what kind of data the calling client wants back (vertices, edges, count, vertex identifiers)
        ReturnType returnType = queryArguments.getReturnType();
        // the query direction (both, out, in)
        Direction queryDirection = queryArguments.getQueryDirection();

        VertexQuery query = vertex.query().direction(queryDirection);

        JSONArray elementArray = new JSONArray();
        long counter = 0;
        if (returnType == ReturnType.VERTICES || returnType == ReturnType.VERTEX_IDS) {
            Iterable<Vertex> vertexQueryResults = query.vertices();
            for (Vertex v : vertexQueryResults) {
                if (returnType.equals(ReturnType.VERTICES)) {
                    elementArray.put(GraphSONUtility.jsonFromElement(
                            v, getVertexIndexedKeys(), GraphSONMode.NORMAL));
                } else {
                    elementArray.put(v.getId());
                }
                counter++;
            }
        } else if (returnType == ReturnType.EDGES) {
            Iterable<Edge> edgeQueryResults = query.edges();
            for (Edge e : edgeQueryResults) {
                elementArray.put(GraphSONUtility.jsonFromElement(
                        e, getEdgeIndexedKeys(), GraphSONMode.NORMAL));
                counter++;
            }
        } else if (returnType == ReturnType.COUNT) {
            counter = query.count();
        }

        JSONObject response = new JSONObject();
        if (!countOnly) {
            response.put(RESULTS, elementArray);
View Full Code Here


                final E e = currentIterator.next();
                if (this.count > this.lowRange)
                    return e;
            } else {
                final Vertex vertex = this.starts.next();
                VertexQuery query = vertex.query();
                query = query.direction(this.direction);
                if (this.labels.length > 0)
                    query = query.labels(this.labels);
                if (null != this.hasContainers) {
                    for (final HasContainer hasContainer : this.hasContainers) {
                        query = query.has(hasContainer.key, hasContainer.predicate, hasContainer.value);
                    }
                }
                if (null != this.intervalContainers) {
                    for (final IntervalContainer intervalContainer : this.intervalContainers) {
                        query = query.interval(intervalContainer.key, intervalContainer.startValue, intervalContainer.endValue);
                    }
                }
                if (this.branchFactor == Integer.MAX_VALUE) {
                    if (this.highRange != Integer.MAX_VALUE) {
                        int temp = this.highRange - this.count;
                        query = temp > 0 ? query.limit(temp) : query;
                    }
                } else {
                    if (this.highRange == Integer.MAX_VALUE) {
                        query = query.limit(this.branchFactor);
                    } else {
                        int temp = this.highRange - this.count;
                        query = query.limit(temp < this.branchFactor ? temp : this.branchFactor);
                    }
                }
                this.currentIterator = this.elementClass.equals(Vertex.class) ?
                        (Iterator<E>) query.vertices().iterator() :
                        (Iterator<E>) query.edges().iterator();
            }
        }
    }
View Full Code Here

            final Direction queryDirection = queryArguments.getQueryDirection();

            long counter = 0l;
            final JSONArray elementArray = new JSONArray();

            VertexQuery query = vertex.query().direction(queryDirection);
            if (labels != null) {
                query = query.labels(labels);
            }

            // add .has() elements to query
            RequestObjectHelper.buildQueryProperties(theRequestObject, query);

            // need to include limits in addition to standard rexster paging as there is buffering going on via
            // rexstergraph that requires both ... meaning, i might do a vertex query with limit that exceeds my
            // buffer size for rexstergraph.
            final int limitTake = theRequestObject.has(Tokens._TAKE) ? theRequestObject.getInt(Tokens._TAKE) : Integer.MIN_VALUE;
            //final long limitSkip = theRequestObject.has(Tokens._SKIP) ? theRequestObject.getLong(Tokens._SKIP) : Long.MIN_VALUE;
            if (limitTake >= 0) {
                query = query.limit(limitTake);
            }

            if (returnType == ReturnType.VERTICES || returnType == ReturnType.VERTEX_IDS) {
                final Iterable<Vertex> vertexQueryResults = query.vertices();
                for (Vertex v : vertexQueryResults) {
                    if (counter >= start && counter < end) {
                        if (returnType.equals(ReturnType.VERTICES)) {
                            elementArray.put(GraphSONUtility.jsonFromElement(v, returnKeys, mode));
                        } else {
                            elementArray.put(v.getId());
                        }
                    }
                    counter++;
                }
            } else if (returnType == ReturnType.EDGES) {
                final Iterable<Edge> edgeQueryResults = query.edges();
                for (Edge e : edgeQueryResults) {
                    if (counter >= start && counter < end) {
                        elementArray.put(GraphSONUtility.jsonFromElement(e, returnKeys, mode));
                    }
                    counter++;
                }
            } else if (returnType == ReturnType.COUNT) {
                counter = query.count();
            } else {
                final JSONObject error = generateErrorObject(direction + " direction segment was invalid.");
                throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(error).build());
            }
View Full Code Here

    public long count() {
        throw new UnsupportedOperationException();
    }

    public VertexQuery build(final Vertex vertex) {
        VertexQuery query = vertex.query();
        for (final HasContainer hasContainer : this.hasContainers) {
            query = query.has(hasContainer.key, hasContainer.predicate, hasContainer.value);
        }
        return query.limit(this.limit).labels(this.labels).direction(this.direction);
    }
View Full Code Here

TOP

Related Classes of com.tinkerpop.blueprints.VertexQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.