Skip to content

Commit

Permalink
edit
Browse files Browse the repository at this point in the history
  • Loading branch information
usfalami committed Sep 10, 2024
1 parent 4a36cde commit 94310f0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/usf/jquery/core/QueryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ public QueryBuilder joins(@NonNull ViewJoin... joins) {
return this;
}

public QueryBuilder limit(int limit) {
public QueryBuilder limit(Integer limit) {
this.limit = limit;
return this;
}

public QueryBuilder offset(int offset) {
public QueryBuilder offset(Integer offset) {
this.offset = offset;
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/usf/jquery/web/RequestEntryChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
import static org.usf.jquery.web.EntryParseException.cannotParseEntryException;
import static org.usf.jquery.web.NoSuchResourceException.noSuchResourceException;
import static org.usf.jquery.web.Parameters.DISTINCT;
import static org.usf.jquery.web.Parameters.OFFSET;
import static org.usf.jquery.web.Parameters.FILTER;
import static org.usf.jquery.web.Parameters.JOIN;
import static org.usf.jquery.web.Parameters.LIMIT;
import static org.usf.jquery.web.Parameters.OFFSET;
import static org.usf.jquery.web.Parameters.ORDER;
import static org.usf.jquery.web.Parameters.PARTITION;
import static org.usf.jquery.web.Parameters.QUERY;
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/org/usf/jquery/web/ViewDecorator.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import static java.util.Map.entry;
import static java.util.Objects.nonNull;
import static java.util.Objects.requireNonNull;
import static java.util.Optional.empty;
import static java.util.Optional.ofNullable;
import static java.util.stream.Collectors.toUnmodifiableMap;
import static org.usf.jquery.core.SqlStringBuilder.quote;
Expand All @@ -28,7 +27,6 @@
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Stream;

import org.usf.jquery.core.ColumnProxy;
Expand Down Expand Up @@ -113,7 +111,7 @@ default QueryBuilder query(Map<String, String[]> parameterMap) {
parseViews(query, parameterMap);
parseColumns(query, parameterMap);
parseOrders(query, parameterMap);
parseJoin(query, parameterMap);
parseJoins(query, parameterMap);
parseLimit(query, parameterMap);
parseOffset(query, parameterMap);
parseFilters(query, parameterMap); //remove all entries before parse filters
Expand Down Expand Up @@ -163,7 +161,7 @@ default void parseOrders(QueryBuilder query, Map<String, String[]> parameters) {
.forEach(e-> query.orders(e.evalOrder(this)));
}
}
default void parseJoin(QueryBuilder query, Map<String, String[]> parameters) {
default void parseJoins(QueryBuilder query, Map<String, String[]> parameters) {
if(parameters.containsKey(JOIN)) {
Stream.of(parameters.remove(JOIN))
.flatMap(c-> parseEntries(c).stream())
Expand All @@ -172,11 +170,11 @@ default void parseJoin(QueryBuilder query, Map<String, String[]> parameters) {
}

default void parseLimit(QueryBuilder query, Map<String, String[]> parameters) {
requirePositiveInt(LIMIT, parameters).ifPresent(query::limit);
query.limit(requirePositiveInt(LIMIT, parameters));
}

default void parseOffset(QueryBuilder query, Map<String, String[]> parameters) {
requirePositiveInt(OFFSET, parameters).ifPresent(query::offset);
query.offset(requirePositiveInt(OFFSET, parameters));
}

default void parseFilters(QueryBuilder query, Map<String, String[]> parameters) {
Expand All @@ -188,15 +186,15 @@ default void parseFilters(QueryBuilder query, Map<String, String[]> parameters)
.forEach(query::filters);
}

private static Optional<Integer> requirePositiveInt(String key, Map<String, String[]> parameters) {
private static Integer requirePositiveInt(String key, Map<String, String[]> parameters) {
if(parameters.containsKey(key)) {
var v = parseInt(requireNArgs(1, parameters.remove(key), ()-> key)[0]);
if(v >= 0) {
return Optional.of(v);
return v;
}
throw new IllegalArgumentException(key + " cannot be negative");
}
return empty();
return null;
}

static Stream<String> flatParameters(String... arr) { //number local separator
Expand Down

0 comments on commit 94310f0

Please sign in to comment.