diff --git a/example/example-app/example-app-cmd-domain/pom.xml b/example/example-app/example-app-cmd-domain/pom.xml index 8218edef..01f2fdb4 100644 --- a/example/example-app/example-app-cmd-domain/pom.xml +++ b/example/example-app/example-app-cmd-domain/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot example-app - 3.4.21 + 3.4.22 ../pom.xml diff --git a/example/example-app/example-app-cmd-meta/pom.xml b/example/example-app/example-app-cmd-meta/pom.xml index eb40dd1d..44f7df5b 100644 --- a/example/example-app/example-app-cmd-meta/pom.xml +++ b/example/example-app/example-app-cmd-meta/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot example-app - 3.4.21 + 3.4.22 ../pom.xml diff --git a/example/example-app/example-app-query/pom.xml b/example/example-app/example-app-query/pom.xml index 446b4663..1fb62ad8 100644 --- a/example/example-app/example-app-query/pom.xml +++ b/example/example-app/example-app-query/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot example-app - 3.4.21 + 3.4.22 ../pom.xml diff --git a/example/example-app/pom.xml b/example/example-app/pom.xml index 31e3ca2a..7d1663f6 100644 --- a/example/example-app/pom.xml +++ b/example/example-app/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot springboot-example - 3.4.21 + 3.4.22 ../pom.xml pom diff --git a/example/example-domain/example-domain-leave/pom.xml b/example/example-domain/example-domain-leave/pom.xml index 8ebb1b03..6d40841d 100644 --- a/example/example-domain/example-domain-leave/pom.xml +++ b/example/example-domain/example-domain-leave/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot example-domain - 3.4.21 + 3.4.22 ../pom.xml diff --git a/example/example-domain/example-domain-user/pom.xml b/example/example-domain/example-domain-user/pom.xml index 204570a6..9dce9908 100644 --- a/example/example-domain/example-domain-user/pom.xml +++ b/example/example-domain/example-domain-user/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot example-domain - 3.4.21 + 3.4.22 ../pom.xml diff --git a/example/example-domain/pom.xml b/example/example-domain/pom.xml index 9f28c813..76a76c15 100644 --- a/example/example-domain/pom.xml +++ b/example/example-domain/pom.xml @@ -5,7 +5,7 @@ com.codingapi.springboot springboot-example - 3.4.21 + 3.4.22 ../pom.xml 4.0.0 diff --git a/example/example-infra/example-infra-flow/pom.xml b/example/example-infra/example-infra-flow/pom.xml index d8e07b22..b1e87df2 100644 --- a/example/example-infra/example-infra-flow/pom.xml +++ b/example/example-infra/example-infra-flow/pom.xml @@ -5,7 +5,7 @@ com.codingapi.springboot example-infra - 3.4.21 + 3.4.22 ../pom.xml diff --git a/example/example-infra/example-infra-jpa/pom.xml b/example/example-infra/example-infra-jpa/pom.xml index 03a38af9..da036bf6 100644 --- a/example/example-infra/example-infra-jpa/pom.xml +++ b/example/example-infra/example-infra-jpa/pom.xml @@ -5,7 +5,7 @@ com.codingapi.springboot example-infra - 3.4.21 + 3.4.22 ../pom.xml diff --git a/example/example-infra/example-infra-security/pom.xml b/example/example-infra/example-infra-security/pom.xml index 1c75eb51..1612ba64 100644 --- a/example/example-infra/example-infra-security/pom.xml +++ b/example/example-infra/example-infra-security/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot example-infra - 3.4.21 + 3.4.22 ../pom.xml diff --git a/example/example-infra/pom.xml b/example/example-infra/pom.xml index 82bf9418..f8a162d8 100644 --- a/example/example-infra/pom.xml +++ b/example/example-infra/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot springboot-example - 3.4.21 + 3.4.22 ../pom.xml pom diff --git a/example/example-interface/pom.xml b/example/example-interface/pom.xml index 1de3a6b0..22e9ff0e 100644 --- a/example/example-interface/pom.xml +++ b/example/example-interface/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot springboot-example - 3.4.21 + 3.4.22 example-interface diff --git a/example/example-server/pom.xml b/example/example-server/pom.xml index e3c8b7c6..a7ceb983 100644 --- a/example/example-server/pom.xml +++ b/example/example-server/pom.xml @@ -5,7 +5,7 @@ springboot-example com.codingapi.springboot - 3.4.21 + 3.4.22 4.0.0 diff --git a/example/pom.xml b/example/pom.xml index 3368f943..221b5299 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -19,7 +19,7 @@ springboot-example - 3.4.21 + 3.4.22 springboot-example springboot-example project for Spring Boot diff --git a/pom.xml b/pom.xml index f5b20814..2acab6ed 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.codingapi.springboot springboot-parent - 3.4.21 + 3.4.22 https://github.com/codingapi/springboot-framewrok springboot-parent @@ -346,6 +346,7 @@ + diff --git a/springboot-starter-data-authorization/pom.xml b/springboot-starter-data-authorization/pom.xml index 7226b96b..3982cef7 100644 --- a/springboot-starter-data-authorization/pom.xml +++ b/springboot-starter-data-authorization/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot springboot-parent - 3.4.21 + 3.4.22 springboot-starter-data-authorization diff --git a/springboot-starter-data-fast/pom.xml b/springboot-starter-data-fast/pom.xml index 6f31e7ad..f21aa5ff 100644 --- a/springboot-starter-data-fast/pom.xml +++ b/springboot-starter-data-fast/pom.xml @@ -5,7 +5,7 @@ springboot-parent com.codingapi.springboot - 3.4.21 + 3.4.22 4.0.0 diff --git a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/repository/DynamicSQLBuilder.java b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/repository/DynamicSQLBuilder.java index 048c0240..cc496f48 100644 --- a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/repository/DynamicSQLBuilder.java +++ b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/repository/DynamicSQLBuilder.java @@ -17,47 +17,62 @@ class DynamicSQLBuilder { private final PageRequest request; - private final Class clazz; private final List params = new ArrayList<>(); private int paramIndex = 1; + private final StringBuilder hql; + private final StringBuilder countHql ; public DynamicSQLBuilder(PageRequest request, Class clazz) { this.request = request; - this.clazz = clazz; + this.hql = new StringBuilder("FROM " + clazz.getSimpleName() + " WHERE "); + this.countHql = new StringBuilder("SELECT COUNT(1) FROM " + clazz.getSimpleName() + " WHERE "); + this.build(); } + public String getHQL(){ + return this.hql.toString(); + } + + public String getCountHQL(){ + return this.countHql.toString(); + } - public String getHQL() { - StringBuilder hql = new StringBuilder("FROM " + clazz.getSimpleName() + " WHERE "); + private void build() { + StringBuilder querySQL = new StringBuilder(); + StringBuilder orderSQL = new StringBuilder(); RequestFilter requestFilter = request.getRequestFilter(); if (requestFilter.hasFilter()) { List filters = requestFilter.getFilters(); for (int i = 0; i < filters.size(); i++) { Filter filter = filters.get(i); - this.buildSQL(filter, hql); + this.buildSQL(filter, querySQL); if (i != filters.size() - 1) { - hql.append(" AND "); + querySQL.append(" AND "); } } } Sort sort = request.getSort(); if (sort.isSorted()) { - hql.append(" ORDER BY "); + orderSQL.append(" ORDER BY "); List orders = sort.toList(); for (int i = 0; i < orders.size(); i++) { Sort.Order order = orders.get(i); - hql.append(order.getProperty()).append(" ").append(order.getDirection().name()); + orderSQL.append(order.getProperty()).append(" ").append(order.getDirection().name()); if (i != orders.size() - 1) { - hql.append(","); + orderSQL.append(","); } } } + this.hql.append(querySQL); + this.hql.append(orderSQL); + this.countHql.append(querySQL); + log.debug("hql:{}", hql); log.debug("params:{}", params); - return hql.toString(); + } @@ -171,4 +186,5 @@ private void buildSQL(Filter filter, StringBuilder hql) { public Object[] getParams() { return params.toArray(); } + } diff --git a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/repository/FastRepository.java b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/repository/FastRepository.java index e3325ac9..e56218db 100644 --- a/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/repository/FastRepository.java +++ b/springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/repository/FastRepository.java @@ -30,7 +30,7 @@ default Page pageRequest(PageRequest request) { if (request.hasFilter()) { Class clazz = getEntityClass(); DynamicSQLBuilder dynamicSQLBuilder = new DynamicSQLBuilder(request, clazz); - return dynamicPageQuery(dynamicSQLBuilder.getHQL(), request, dynamicSQLBuilder.getParams()); + return dynamicPageQuery(dynamicSQLBuilder.getHQL(), dynamicSQLBuilder.getCountHQL(),request, dynamicSQLBuilder.getParams()); } return findAll((org.springframework.data.domain.PageRequest) request); } diff --git a/springboot-starter-flow/pom.xml b/springboot-starter-flow/pom.xml index ccba4930..945d0499 100644 --- a/springboot-starter-flow/pom.xml +++ b/springboot-starter-flow/pom.xml @@ -6,7 +6,7 @@ springboot-parent com.codingapi.springboot - 3.4.21 + 3.4.22 springboot-starter-flow diff --git a/springboot-starter-security/pom.xml b/springboot-starter-security/pom.xml index 98062cf8..e8d1806c 100644 --- a/springboot-starter-security/pom.xml +++ b/springboot-starter-security/pom.xml @@ -6,7 +6,7 @@ springboot-parent com.codingapi.springboot - 3.4.21 + 3.4.22 springboot-starter-security diff --git a/springboot-starter/pom.xml b/springboot-starter/pom.xml index ed1494fa..6ba86ae2 100644 --- a/springboot-starter/pom.xml +++ b/springboot-starter/pom.xml @@ -5,7 +5,7 @@ com.codingapi.springboot springboot-parent - 3.4.21 + 3.4.22 springboot-starter