Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class AqlQueryBuilder {
private AqlRootElement root = new AqlRootElement();
private AqlItem sort;
private AqlInclude include;
private int limit;

public AqlQueryBuilder item(AqlItem item) {
root.putAll(item.value());
Expand Down Expand Up @@ -83,15 +84,30 @@ public AqlQueryBuilder desc(String... by) {
return this;
}

public AqlQueryBuilder limit(int limit) {
if (limit > 0) {
this.limit = limit;
}
return this;
}

public String build() {
try {
ObjectMapper mapper = new ObjectMapper();
return "items.find(" + getRootAsString(mapper) + ")" + getIncludeAsString() + getSortAsString(mapper);
return "items.find(" + getRootAsString(mapper) + ")" + getIncludeAsString() + getSortAsString(mapper) + getLimitAsString();
} catch (JsonProcessingException e) {
throw new AqlBuilderException("Error serializing object to json: ", e);
}
}

private String getLimitAsString() {
return hasLimit() ? ".limit(" + limit + ")" : "";
}

private boolean hasLimit() {
return limit > 0;
}

private String getSortAsString(ObjectMapper mapper) throws JsonProcessingException {
return hasSort() ? ".sort(" + mapper.writeValueAsString(sort) + ")" : "";
}
Expand Down