From 468310dab4b5a7148a121a44a772bf8a858da2f7 Mon Sep 17 00:00:00 2001 From: u$f Date: Tue, 10 Sep 2024 22:55:30 +0200 Subject: [PATCH] edit --- .../java/org/usf/jquery/core/CaseColumn.java | 2 +- .../org/usf/jquery/web/ArgumentParsers.java | 2 +- .../jquery/web/RequestParameterResolver.java | 6 ++-- .../org/usf/jquery/web/ViewDecorator.java | 33 ++++++++----------- 4 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/usf/jquery/core/CaseColumn.java b/src/main/java/org/usf/jquery/core/CaseColumn.java index 8c896c1..33ef4e9 100644 --- a/src/main/java/org/usf/jquery/core/CaseColumn.java +++ b/src/main/java/org/usf/jquery/core/CaseColumn.java @@ -50,7 +50,7 @@ public void views(Collection views) { e.views(views); } } - + @Override public String toString() { return sql(addWithValue()); diff --git a/src/main/java/org/usf/jquery/web/ArgumentParsers.java b/src/main/java/org/usf/jquery/web/ArgumentParsers.java index 0b80f01..6fd6d28 100644 --- a/src/main/java/org/usf/jquery/web/ArgumentParsers.java +++ b/src/main/java/org/usf/jquery/web/ArgumentParsers.java @@ -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 list = new ArrayList<>(); diff --git a/src/main/java/org/usf/jquery/web/RequestParameterResolver.java b/src/main/java/org/usf/jquery/web/RequestParameterResolver.java index 3b110d1..6d833f6 100644 --- a/src/main/java/org/usf/jquery/web/RequestParameterResolver.java +++ b/src/main/java/org/usf/jquery/web/RequestParameterResolver.java @@ -32,15 +32,15 @@ public QueryBuilder requestQuery(@NonNull RequestQueryParam ant, @NonNull Map(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()); diff --git a/src/main/java/org/usf/jquery/web/ViewDecorator.java b/src/main/java/org/usf/jquery/web/ViewDecorator.java index 0d2b638..e7c7aaa 100644 --- a/src/main/java/org/usf/jquery/web/ViewDecorator.java +++ b/src/main/java/org/usf/jquery/web/ViewDecorator.java @@ -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; @@ -54,7 +52,7 @@ default ViewBuilder builder() { return this::buildView; } - default CriteriaBuilder criteria(String name) { //!aggregation + default CriteriaBuilder criteria(String name) { return null; //no criteria by default } @@ -127,18 +125,15 @@ default void parseViews(QueryBuilder query, Map parameters) { } default void parseColumns(QueryBuilder query, Map 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-> { @@ -150,7 +145,7 @@ default void parseColumns(QueryBuilder query, Map 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)); } } @@ -192,12 +187,12 @@ private static Integer requirePositiveInt(String key, Map 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 flatParameters(String... arr) { //number local separator return Stream.of(arr).flatMap(v-> Stream.of(v.split(","))); - } -} + } +} \ No newline at end of file