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 94310f0 commit 468310d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/usf/jquery/core/CaseColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void views(Collection<DBView> views) {
e.views(views);
}
}

@Override
public String toString() {
return sql(addWithValue());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/usf/jquery/web/ArgumentParsers.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ArgumentParsers {

private static final JDBCType[] STD_TYPES = {
BIGINT, DOUBLE, DATE, TIMESTAMP,
TIME, TIMESTAMP_WITH_TIMEZONE, VARCHAR }; //varchar !?
TIME, TIMESTAMP_WITH_TIMEZONE, VARCHAR };

public static Object parse(RequestEntryChain entry, ViewDecorator td, JavaType... types) {
List<JavaType> list = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public QueryBuilder requestQuery(@NonNull RequestQueryParam ant, @NonNull Map<St
var t = currentTimeMillis();
log.trace("parsing request...");
parameterMap = new LinkedHashMap<>(parameterMap); //modifiable map + preserve order
if(!parameterMap.containsKey(COLUMN_DISTINCT)) {
parameterMap.computeIfAbsent(COLUMN, k-> ant.defaultColumns());
if(!parameterMap.containsKey(COLUMN)) {
parameterMap.computeIfAbsent(COLUMN_DISTINCT, k-> ant.defaultColumns());
}
if(!isEmpty(ant.ignoreParameters())) {
for(var k : ant.ignoreParameters()) {
parameterMap.remove(k);
}
}
releaseContext(); //safe++
releaseContext(); //safety++
var ctx = ant.database().isEmpty()
? currentContext()
: context(ant.database());
Expand Down
33 changes: 14 additions & 19 deletions src/main/java/org/usf/jquery/web/ViewDecorator.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import static java.util.Objects.requireNonNull;
import static java.util.Optional.ofNullable;
import static java.util.stream.Collectors.toUnmodifiableMap;
import static org.usf.jquery.core.SqlStringBuilder.quote;
import static org.usf.jquery.core.Utils.isEmpty;
import static org.usf.jquery.core.Validation.requireLegalVariable;
import static org.usf.jquery.core.Validation.requireNArgs;
import static org.usf.jquery.web.ColumnMetadata.columnMetadata;
Expand Down Expand Up @@ -54,7 +52,7 @@ default ViewBuilder builder() {
return this::buildView;
}

default CriteriaBuilder<DBFilter> criteria(String name) { //!aggregation
default CriteriaBuilder<DBFilter> criteria(String name) {
return null; //no criteria by default
}

Expand Down Expand Up @@ -127,18 +125,15 @@ default void parseViews(QueryBuilder query, Map<String, String[]> parameters) {
}

default void parseColumns(QueryBuilder query, Map<String, String[]> parameters) {
if(parameters.containsKey(COLUMN) && parameters.containsKey(COLUMN_DISTINCT)) {
throw new IllegalStateException("both parameters are present " + quote(COLUMN_DISTINCT) + " and " + quote(COLUMN));
}
String[] cols;
if(parameters.containsKey(COLUMN_DISTINCT)) {
cols = parameters.remove(COLUMN_DISTINCT);
query.distinct();
}
else {
cols = parameters.remove(COLUMN);
}
if(!isEmpty(cols)) {
if(parameters.containsKey(COLUMN) ^ parameters.containsKey(COLUMN_DISTINCT)) {
String[] cols;
if(parameters.containsKey(COLUMN)) {
cols = parameters.remove(COLUMN);
}
else {
cols = parameters.remove(COLUMN_DISTINCT);
query.distinct();
}
Stream.of(cols)
.flatMap(v-> parseEntries(v).stream())
.map(e-> {
Expand All @@ -150,7 +145,7 @@ default void parseColumns(QueryBuilder query, Map<String, String[]> parameters)
.forEach(query::columns);
}
else {
throw new IllegalArgumentException(format("requrie %s or %s parameter", COLUMN, COLUMN_DISTINCT));
throw new IllegalArgumentException(format("requrie '%s' or '%s' parameter", COLUMN, COLUMN_DISTINCT));
}
}

Expand Down Expand Up @@ -192,12 +187,12 @@ private static Integer requirePositiveInt(String key, Map<String, String[]> para
if(v >= 0) {
return v;
}
throw new IllegalArgumentException(key + " cannot be negative");
throw new IllegalArgumentException(key + " parameter cannot be negative");
}
return null;
}

static Stream<String> flatParameters(String... arr) { //number local separator
return Stream.of(arr).flatMap(v-> Stream.of(v.split(",")));
}
}
}
}

0 comments on commit 468310d

Please sign in to comment.