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