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());
}