From 6fa1d598490d891e134344ef5d80c694351560a9 Mon Sep 17 00:00:00 2001 From: scx567888 Date: Tue, 3 Sep 2024 16:51:14 +0800 Subject: [PATCH] v3.0.7 (#32) --- pom.xml | 2 +- scx-common/pom.xml | 2 +- scx-config/pom.xml | 2 +- scx-core/pom.xml | 2 +- .../main/java/cool/scx/core/ScxVersion.java | 2 +- scx-data-jdbc/pom.xml | 2 +- scx-data-mysql-x/pom.xml | 2 +- scx-data/pom.xml | 2 +- .../main/java/cool/scx/data/query/Logic.java | 15 +-- .../main/java/cool/scx/data/query/Query.java | 14 --- .../java/cool/scx/data/query/QueryImpl.java | 103 +++++++++--------- .../java/cool/scx/data/query/QueryLike.java | 38 ------- scx-ext/pom.xml | 2 +- scx-jdbc-mysql/pom.xml | 2 +- scx-jdbc-sqlite/pom.xml | 2 +- scx-jdbc/pom.xml | 2 +- scx-logging/pom.xml | 2 +- scx-socket/pom.xml | 2 +- scx-web/pom.xml | 2 +- 19 files changed, 74 insertions(+), 126 deletions(-) diff --git a/pom.xml b/pom.xml index 5d406eb7..e1d562d6 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ scx pom - 3.0.6 + 3.0.7 SCX https://github.com/scx567888/scx diff --git a/scx-common/pom.xml b/scx-common/pom.xml index 4b35da8a..d8844fd3 100644 --- a/scx-common/pom.xml +++ b/scx-common/pom.xml @@ -6,7 +6,7 @@ cool.scx scx - 3.0.6 + 3.0.7 scx-common diff --git a/scx-config/pom.xml b/scx-config/pom.xml index e4aeee6c..028a5697 100644 --- a/scx-config/pom.xml +++ b/scx-config/pom.xml @@ -6,7 +6,7 @@ cool.scx scx - 3.0.6 + 3.0.7 scx-config diff --git a/scx-core/pom.xml b/scx-core/pom.xml index 29f3af7d..43c1f389 100644 --- a/scx-core/pom.xml +++ b/scx-core/pom.xml @@ -6,7 +6,7 @@ cool.scx scx - 3.0.6 + 3.0.7 scx-core diff --git a/scx-core/src/main/java/cool/scx/core/ScxVersion.java b/scx-core/src/main/java/cool/scx/core/ScxVersion.java index c55e49d9..4a924fa0 100644 --- a/scx-core/src/main/java/cool/scx/core/ScxVersion.java +++ b/scx-core/src/main/java/cool/scx/core/ScxVersion.java @@ -13,7 +13,7 @@ public class ScxVersion { /** * SCX 版本号 */ - public static final String SCX_VERSION = "3.0.6"; + public static final String SCX_VERSION = "3.0.7"; /** * 在控制台上打印 banner diff --git a/scx-data-jdbc/pom.xml b/scx-data-jdbc/pom.xml index c64a2b37..d0060de9 100644 --- a/scx-data-jdbc/pom.xml +++ b/scx-data-jdbc/pom.xml @@ -6,7 +6,7 @@ cool.scx scx - 3.0.6 + 3.0.7 scx-data-jdbc diff --git a/scx-data-mysql-x/pom.xml b/scx-data-mysql-x/pom.xml index b4cfbe7f..6c4021d6 100644 --- a/scx-data-mysql-x/pom.xml +++ b/scx-data-mysql-x/pom.xml @@ -6,7 +6,7 @@ cool.scx scx - 3.0.6 + 3.0.7 scx-data-mysql-x diff --git a/scx-data/pom.xml b/scx-data/pom.xml index 4cf374b5..53b83b08 100644 --- a/scx-data/pom.xml +++ b/scx-data/pom.xml @@ -6,7 +6,7 @@ cool.scx scx - 3.0.6 + 3.0.7 scx-data diff --git a/scx-data/src/main/java/cool/scx/data/query/Logic.java b/scx-data/src/main/java/cool/scx/data/query/Logic.java index 17bb742c..25e251ef 100644 --- a/scx-data/src/main/java/cool/scx/data/query/Logic.java +++ b/scx-data/src/main/java/cool/scx/data/query/Logic.java @@ -2,7 +2,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.function.Predicate; import static cool.scx.data.query.WhereType.*; @@ -26,19 +25,21 @@ public Object[] clauses() { public Logic add(Object... logicCauses) { for (var logicCause : logicCauses) { + if (logicCause == null) { + continue; + } + if (logicCause instanceof Object[] objs) { + add(objs); + continue; + } if (logicCause instanceof Where w && w.info().replace()) { - removeIf(c -> c instanceof Where w1 && w1.name().equals(w.name())); + clauses.removeIf(c -> c instanceof Where w1 && w1.name().equals(w.name())); } clauses.add(logicCause); } return this; } - public Logic removeIf(Predicate filter) { - clauses.removeIf(filter); - return this; - } - public Logic clear() { clauses.clear(); return this; diff --git a/scx-data/src/main/java/cool/scx/data/query/Query.java b/scx-data/src/main/java/cool/scx/data/query/Query.java index c0d01b21..61019292 100644 --- a/scx-data/src/main/java/cool/scx/data/query/Query.java +++ b/scx-data/src/main/java/cool/scx/data/query/Query.java @@ -1,7 +1,5 @@ package cool.scx.data.query; -import java.util.function.Predicate; - public interface Query { Query where(Object... whereClauses); @@ -14,18 +12,6 @@ public interface Query { Query limit(long numberOfRows); - Query addWhere(Object... whereClauses); - - Query addGroupBy(Object... groupByClauses); - - Query addOrderBy(Object... orderByClauses); - - Query removeWhereIf(Predicate filter); - - Query removeGroupByIf(Predicate filter); - - Query removeOrderByIf(Predicate filter); - Object[] getWhere(); Object[] getGroupBy(); diff --git a/scx-data/src/main/java/cool/scx/data/query/QueryImpl.java b/scx-data/src/main/java/cool/scx/data/query/QueryImpl.java index fd5bd072..3cdb7646 100644 --- a/scx-data/src/main/java/cool/scx/data/query/QueryImpl.java +++ b/scx-data/src/main/java/cool/scx/data/query/QueryImpl.java @@ -2,7 +2,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.function.Predicate; /** * 默认实现 @@ -78,57 +77,6 @@ public QueryImpl limit(long limit) { return this; } - @Override - public QueryImpl addWhere(Object... whereClauses) { - for (var whereClause : whereClauses) { - if (whereClause instanceof Where w && w.info().replace()) { - removeWhereIf(c -> c instanceof Where w1 && w1.name().equals(w.name())); - } - where.add(whereClause); - } - return this; - } - - @Override - public QueryImpl addGroupBy(Object... groupByClauses) { - for (var groupByClause : groupByClauses) { - if (groupByClause instanceof GroupBy w && w.info().replace()) { - removeGroupByIf(c -> c instanceof GroupBy w1 && w1.name().equals(w.name())); - } - groupBy.add(groupByClause); - } - return this; - } - - @Override - public QueryImpl addOrderBy(Object... orderByClauses) { - for (var orderByClause : orderByClauses) { - if (orderByClause instanceof OrderBy w && w.info().replace()) { - removeOrderByIf(c -> c instanceof OrderBy w1 && w1.name().equals(w.name())); - } - orderBy.add(orderByClause); - } - return this; - } - - @Override - public Query removeWhereIf(Predicate filter) { - where.removeIf(filter); - return this; - } - - @Override - public Query removeGroupByIf(Predicate filter) { - groupBy.removeIf(filter); - return this; - } - - @Override - public Query removeOrderByIf(Predicate filter) { - orderBy.removeIf(filter); - return this; - } - @Override public Object[] getWhere() { return where.toArray(); @@ -184,4 +132,55 @@ public QueryImpl clearLimit() { return this; } + private QueryImpl addWhere(Object... whereClauses) { + for (var whereClause : whereClauses) { + if (whereClause == null) { + continue; + } + if (whereClause instanceof Object[] objs) { + addWhere(objs); + continue; + } + if (whereClause instanceof Where w && w.info().replace()) { + where.removeIf(c -> c instanceof Where w1 && w1.name().equals(w.name())); + } + where.add(whereClause); + } + return this; + } + + private QueryImpl addGroupBy(Object... groupByClauses) { + for (var groupByClause : groupByClauses) { + if (groupByClause == null) { + continue; + } + if (groupByClause instanceof Object[] objs) { + addGroupBy(objs); + continue; + } + if (groupByClause instanceof GroupBy w && w.info().replace()) { + groupBy.removeIf(c -> c instanceof GroupBy w1 && w1.name().equals(w.name())); + } + groupBy.add(groupByClause); + } + return this; + } + + private QueryImpl addOrderBy(Object... orderByClauses) { + for (var orderByClause : orderByClauses) { + if (orderByClause == null) { + continue; + } + if (orderByClause instanceof Object[] objs) { + addOrderBy(objs); + continue; + } + if (orderByClause instanceof OrderBy w && w.info().replace()) { + orderBy.removeIf(c -> c instanceof OrderBy w1 && w1.name().equals(w.name())); + } + orderBy.add(orderByClause); + } + return this; + } + } diff --git a/scx-data/src/main/java/cool/scx/data/query/QueryLike.java b/scx-data/src/main/java/cool/scx/data/query/QueryLike.java index 8af036fc..53ca0407 100644 --- a/scx-data/src/main/java/cool/scx/data/query/QueryLike.java +++ b/scx-data/src/main/java/cool/scx/data/query/QueryLike.java @@ -1,7 +1,5 @@ package cool.scx.data.query; -import java.util.function.Predicate; - @SuppressWarnings("unchecked") public abstract class QueryLike> implements Query { @@ -44,42 +42,6 @@ public QL limit(long numberOfRows) { return (QL) this; } - @Override - public QL addWhere(Object... whereClauses) { - query().addWhere(whereClauses); - return (QL) this; - } - - @Override - public QL addGroupBy(Object... groupByClauses) { - query().addGroupBy(groupByClauses); - return (QL) this; - } - - @Override - public QL addOrderBy(Object... orderByClauses) { - query().addOrderBy(orderByClauses); - return (QL) this; - } - - @Override - public QL removeWhereIf(Predicate filter) { - query().removeWhereIf(filter); - return (QL) this; - } - - @Override - public QL removeGroupByIf(Predicate filter) { - query().removeGroupByIf(filter); - return (QL) this; - } - - @Override - public QL removeOrderByIf(Predicate filter) { - query().removeOrderByIf(filter); - return (QL) this; - } - @Override public Object[] getWhere() { return query().getWhere(); diff --git a/scx-ext/pom.xml b/scx-ext/pom.xml index 85daf47e..dbc704ee 100644 --- a/scx-ext/pom.xml +++ b/scx-ext/pom.xml @@ -6,7 +6,7 @@ cool.scx scx - 3.0.6 + 3.0.7 scx-ext diff --git a/scx-jdbc-mysql/pom.xml b/scx-jdbc-mysql/pom.xml index fe174053..bfa1393a 100644 --- a/scx-jdbc-mysql/pom.xml +++ b/scx-jdbc-mysql/pom.xml @@ -6,7 +6,7 @@ cool.scx scx - 3.0.6 + 3.0.7 scx-jdbc-mysql diff --git a/scx-jdbc-sqlite/pom.xml b/scx-jdbc-sqlite/pom.xml index acf82ac9..765ce387 100644 --- a/scx-jdbc-sqlite/pom.xml +++ b/scx-jdbc-sqlite/pom.xml @@ -6,7 +6,7 @@ cool.scx scx - 3.0.6 + 3.0.7 scx-jdbc-sqlite diff --git a/scx-jdbc/pom.xml b/scx-jdbc/pom.xml index 1489abcd..80f38872 100644 --- a/scx-jdbc/pom.xml +++ b/scx-jdbc/pom.xml @@ -6,7 +6,7 @@ cool.scx scx - 3.0.6 + 3.0.7 scx-jdbc diff --git a/scx-logging/pom.xml b/scx-logging/pom.xml index aa593019..c2edd6a0 100644 --- a/scx-logging/pom.xml +++ b/scx-logging/pom.xml @@ -6,7 +6,7 @@ cool.scx scx - 3.0.6 + 3.0.7 scx-logging diff --git a/scx-socket/pom.xml b/scx-socket/pom.xml index 39b8b934..4baa1f93 100644 --- a/scx-socket/pom.xml +++ b/scx-socket/pom.xml @@ -6,7 +6,7 @@ cool.scx scx - 3.0.6 + 3.0.7 scx-socket diff --git a/scx-web/pom.xml b/scx-web/pom.xml index b046218a..e2e882f6 100644 --- a/scx-web/pom.xml +++ b/scx-web/pom.xml @@ -6,7 +6,7 @@ cool.scx scx - 3.0.6 + 3.0.7 scx-web