From 052034237991df34a1c1a64b42481cd83485e8cc Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Fri, 18 Feb 2022 17:11:48 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=BC?= =?UTF-8?q?=D0=BD=D0=BE=D0=B6=D0=B5=D1=81=D1=82=D0=B2=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D0=B9=20groupBy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../haiti/filter/jooq/CriteriaJooqFilter.java | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/main/java/dev/struchkov/haiti/filter/jooq/CriteriaJooqFilter.java b/src/main/java/dev/struchkov/haiti/filter/jooq/CriteriaJooqFilter.java index b82609e..6eadfe8 100644 --- a/src/main/java/dev/struchkov/haiti/filter/jooq/CriteriaJooqFilter.java +++ b/src/main/java/dev/struchkov/haiti/filter/jooq/CriteriaJooqFilter.java @@ -47,10 +47,10 @@ public class CriteriaJooqFilter { private final Table generalTable; private final DSLContext dsl; + private final List sorts = new ArrayList<>(); private PageableOffset offset; private PageableSeek seek; - private List sorts = new ArrayList<>(); - private String groupByField; + private final List groupByFields = new ArrayList<>(); protected CriteriaJooqFilter(String table, DSLContext dsl) { this.generalTable = DSL.table(table); @@ -133,7 +133,21 @@ public class CriteriaJooqFilter { public CriteriaJooqFilter groupBy(String field) { if (field != null) { - this.groupByField = field; + groupByFields.add(field); + } + return this; + } + + public CriteriaJooqFilter groupBy(String... fields) { + if (fields != null && fields.length > 0) { + groupByFields.addAll(Arrays.asList(fields)); + } + return this; + } + + public CriteriaJooqFilter groupBy(Collection fields) { + if (fields != null && !fields.isEmpty()) { + groupByFields.addAll(fields); } return this; } @@ -174,15 +188,19 @@ public class CriteriaJooqFilter { } private SelectLimitStep getOrderBy(SelectHavingStep groupBy) { - if (sorts != null && !sorts.isEmpty()) { + if (!sorts.isEmpty()) { return groupBy.orderBy(getOrderBy()); } return groupBy; } private SelectHavingStep getGroupBy(SelectConditionStep where) { - if (groupByField != null) { - return where.groupBy(field(groupByField)); + if (!groupByFields.isEmpty()) { + return where.groupBy( + groupByFields.stream() + .map(DSL::field) + .collect(Collectors.toList()) + ); } return where; }