From 75de6bf766cf07fa69e775f03a27c8e6fe147f6d Mon Sep 17 00:00:00 2001 From: yangziwen Date: Mon, 9 Mar 2020 17:26:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9F=A5=E8=AF=A2=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E5=8E=BB=E9=87=8D=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- quick-dao-core/pom.xml | 2 +- .../yangziwen/quickdao/core/Criterion.java | 25 ++++++++++++++++--- quick-dao-example/pom.xml | 2 +- quick-dao-mybatis/pom.xml | 2 +- quick-dao-spring-jdbc/pom.xml | 2 +- quick-dao-sql2o/pom.xml | 2 +- 7 files changed, 28 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 672b303..a7dcb6b 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 io.github.yangziwen quick-dao - 0.0.12 + 0.0.13-SNAPSHOT pom quick-dao http://maven.apache.org diff --git a/quick-dao-core/pom.xml b/quick-dao-core/pom.xml index 375eb80..801a7fd 100644 --- a/quick-dao-core/pom.xml +++ b/quick-dao-core/pom.xml @@ -7,7 +7,7 @@ io.github.yangziwen quick-dao - 0.0.12 + 0.0.13-SNAPSHOT quick-dao-core quick-dao-core diff --git a/quick-dao-core/src/main/java/io/github/yangziwen/quickdao/core/Criterion.java b/quick-dao-core/src/main/java/io/github/yangziwen/quickdao/core/Criterion.java index 176da96..d59c4d0 100644 --- a/quick-dao-core/src/main/java/io/github/yangziwen/quickdao/core/Criterion.java +++ b/quick-dao-core/src/main/java/io/github/yangziwen/quickdao/core/Criterion.java @@ -1,5 +1,7 @@ package io.github.yangziwen.quickdao.core; +import java.util.Objects; + import org.apache.commons.lang3.StringUtils; import io.github.yangziwen.quickdao.core.util.StringWrapper; @@ -23,6 +25,9 @@ public class Criterion { @Getter private Operator operator = Operator.eq; + @Getter + private boolean valid; + Criterion(String name, Criteria criteria) { this(name, criteria, true); } @@ -30,17 +35,31 @@ public class Criterion { Criterion(String name, Criteria criteria, boolean valid) { this.name = StringUtils.replacePattern(name, "\\s+", ""); this.criteria = criteria; - if (valid) { - criteria.getCriterionList().add(this); - } + this.valid = valid; } Criteria op(Operator operator, Object value) { this.operator = operator; this.value = value; + if (valid && !isRedundant()) { + criteria.getCriterionList().add(this); + } return this.criteria; } + private boolean isRedundant() { + for (Criterion criterion : criteria.getCriterionList()) { + if (Objects.equals(criterion.getName(), getName()) + && Objects.equals(criterion.getJsonField(), getJsonField()) + // be aware that the value comparation is based on the shallow equals + && Objects.equals(criterion.getValue(), getValue()) + && Objects.equals(criterion.getOperator(), getOperator())) { + return true; + } + } + return false; + } + public Criterion jsonField(String jsonField) { this.jsonField = StringUtils.replacePattern(jsonField, "\\s+", ""); return this; diff --git a/quick-dao-example/pom.xml b/quick-dao-example/pom.xml index 8e6342f..1fac4b1 100644 --- a/quick-dao-example/pom.xml +++ b/quick-dao-example/pom.xml @@ -7,7 +7,7 @@ io.github.yangziwen quick-dao - 0.0.12 + 0.0.13-SNAPSHOT quick-dao-example quick-dao-example diff --git a/quick-dao-mybatis/pom.xml b/quick-dao-mybatis/pom.xml index 13f0990..ff291b4 100644 --- a/quick-dao-mybatis/pom.xml +++ b/quick-dao-mybatis/pom.xml @@ -7,7 +7,7 @@ io.github.yangziwen quick-dao - 0.0.12 + 0.0.13-SNAPSHOT quick-dao-mybatis quick-dao-mybatis diff --git a/quick-dao-spring-jdbc/pom.xml b/quick-dao-spring-jdbc/pom.xml index 9c97e3a..71d0d30 100644 --- a/quick-dao-spring-jdbc/pom.xml +++ b/quick-dao-spring-jdbc/pom.xml @@ -7,7 +7,7 @@ io.github.yangziwen quick-dao - 0.0.12 + 0.0.13-SNAPSHOT quick-dao-spring-jdbc quick-dao-spring-jdbc diff --git a/quick-dao-sql2o/pom.xml b/quick-dao-sql2o/pom.xml index 75b02ca..e0129b9 100644 --- a/quick-dao-sql2o/pom.xml +++ b/quick-dao-sql2o/pom.xml @@ -7,7 +7,7 @@ io.github.yangziwen quick-dao - 0.0.12 + 0.0.13-SNAPSHOT quick-dao-sql2o quick-dao-sql2o