diff --git a/pom.xml b/pom.xml
index 1d5ce0f..9d5b7d5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
dev.struchkov.haiti.filter
haiti-filter-quarkus-reactive
- 0.2.0
+ 0.3.0
jar
Haiti Filter Reactive Quarkus
@@ -18,14 +18,22 @@
https://raw.githubusercontent.com/haiti-projects/haiti-filter-reactive-quarkus/master/LICENSE
+
+ GitHub
+ https://github.com/haiti-projects/haiti-filter-reactive-quarkus/issues
+
- 11
- 11
+ 11
+ ${java.version}
+ ${java.version}
+ UTF-8
+ UTF-8
2.5.1.Final
- 0.2.0
+ 0.3.0
+ 3.9.0
1.6.8
3.2.1
3.3.1
@@ -54,21 +62,24 @@
io.smallrye.reactive
smallrye-mutiny-vertx-pg-client
+
+
+
+ org.postgresql
+ postgresql
+ 42.3.1
+
+
+ jakarta.xml.bind
+ jakarta.xml.bind-api
+
+
+ org.jetbrains
+ annotations
+ 20.1.0
+
-
- scm:git:https://github.com/haiti-projects/haiti-filter-reactive-quarkus.git
- https://github.com/haiti-projects/haiti-filter-reactive-quarkus
- scm:git:https://github.com/haiti-projects/haiti-filter-reactive-quarkus.git
-
-
-
-
- ossrh
- https://s01.oss.sonatype.org/content/repositories/snapshots
-
-
-
@@ -83,6 +94,15 @@
true
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${plugin.maven.compiler.ver}
+
+
+ ${java.version}
+
+
org.apache.maven.plugins
maven-source-plugin
@@ -136,10 +156,14 @@
org.apache.maven.plugins
maven-compiler-plugin
-
-
- 11
-
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
@@ -170,6 +194,20 @@
+
+ scm:git:https://github.com/haiti-projects/haiti-filter-reactive-quarkus.git
+ https://github.com/haiti-projects/haiti-filter-reactive-quarkus
+ scm:git:https://github.com/haiti-projects/haiti-filter-reactive-quarkus.git
+
+
+
+
+
+ ossrh
+ https://s01.oss.sonatype.org/content/repositories/snapshots
+
+
+
uPagge
diff --git a/src/main/java/dev/struchkov/haiti/filter/quarkus/CriteriaFilter.java b/src/main/java/dev/struchkov/haiti/filter/quarkus/CriteriaFilter.java
index 0af0b65..b379d7f 100644
--- a/src/main/java/dev/struchkov/haiti/filter/quarkus/CriteriaFilter.java
+++ b/src/main/java/dev/struchkov/haiti/filter/quarkus/CriteriaFilter.java
@@ -1,30 +1,30 @@
package dev.struchkov.haiti.filter.quarkus;
-import dev.struchkov.haiti.filter.Filter;
-import dev.struchkov.haiti.filter.FilterQuery;
import dev.struchkov.haiti.filter.jooq.CriteriaJooqFilter;
-import dev.struchkov.haiti.filter.jooq.JoinTable;
+import dev.struchkov.haiti.filter.jooq.CriteriaJooqQuery;
import dev.struchkov.haiti.filter.jooq.SortContainer;
import dev.struchkov.haiti.filter.jooq.SortType;
import dev.struchkov.haiti.filter.jooq.page.PageableOffset;
import dev.struchkov.haiti.filter.jooq.page.PageableSeek;
-import io.smallrye.mutiny.Multi;
+import io.smallrye.mutiny.Uni;
import io.vertx.mutiny.pgclient.PgPool;
import io.vertx.mutiny.sqlclient.Row;
-import lombok.NonNull;
import org.jooq.DSLContext;
import org.jooq.Query;
import org.jooq.conf.ParamType;
+import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
+import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
-public class CriteriaFilter implements Filter {
+public class CriteriaFilter {
private final PgPool pgPool;
private final CriteriaJooqFilter jooqFilter;
private final Function mapper;
+ private PageableOffset offset;
private CriteriaFilter(PgPool pgPool, String table, DSLContext dslContext, Function mapper) {
dslContext.settings().withParamType(ParamType.NAMED_OR_INLINED);
@@ -37,81 +37,89 @@ public class CriteriaFilter implements Filter {
return new CriteriaFilter<>(pgPool, table, dslContext, mapper);
}
- @Override
- public Filter and(FilterQuery filterQuery) {
+ public CriteriaFilter and(CriteriaJooqQuery filterQuery) {
jooqFilter.and(filterQuery);
return this;
}
- @Override
- public Filter and(Consumer query) {
+ public CriteriaFilter and(Consumer query) {
jooqFilter.and(query);
return this;
}
- @Override
- public Filter or(FilterQuery filterQuery) {
+
+ public CriteriaFilter or(CriteriaJooqQuery filterQuery) {
jooqFilter.or(filterQuery);
return this;
}
- @Override
- public Filter or(Consumer query) {
+ public CriteriaFilter or(Consumer query) {
jooqFilter.or(query);
return this;
}
- @Override
- public Filter not(FilterQuery filterQuery) {
- jooqFilter.not(filterQuery);
- return this;
- }
-
- @Override
- public Filter not(Consumer query) {
- jooqFilter.not(query);
- return this;
- }
-
- public CriteriaFilter page(@NonNull PageableOffset offset) {
+ public CriteriaFilter page(PageableOffset offset) {
jooqFilter.page(offset);
+ this.offset = offset;
return this;
}
- public CriteriaFilter page(@NonNull PageableSeek seek) {
+ public CriteriaFilter page(PageableSeek seek) {
jooqFilter.page(seek);
return this;
}
- public CriteriaFilter join(@NonNull JoinTable... joinTables) {
- jooqFilter.join(joinTables);
- return this;
- }
-
- public CriteriaFilter sort(@NonNull SortContainer container) {
+ public CriteriaFilter sort(SortContainer container) {
jooqFilter.sort(container);
return this;
}
- public CriteriaFilter sort(@NonNull String field, SortType sortType) {
+ public CriteriaFilter sort(String field, SortType sortType) {
jooqFilter.sort(field, sortType);
return this;
}
- public CriteriaFilter sort(@NonNull String field) {
+ public CriteriaFilter sort(String field) {
jooqFilter.sort(field);
return this;
}
- @Override
- public Multi build() {
+ public Uni> build() {
final Query query = jooqFilter.build();
return pgPool.preparedQuery(query.getSQL())
.execute()
- .onItem()
- .transformToMulti(rows -> Multi.createFrom().items(
+ .map(rows ->
StreamSupport.stream(rows.spliterator(), false)
- ))
- .map(mapper);
+ .map(mapper)
+ .collect(Collectors.toList())
+ );
}
+
+ public Uni count() {
+ final Query query = jooqFilter.count();
+ return pgPool.preparedQuery(query.getSQL())
+ .execute()
+ .map(t -> t.iterator().next().getLong("count"));
+ }
+
+ public Uni> filterResult() {
+ final Uni count = count();
+ final Uni> content = build();
+ return Uni.combine().all()
+ .unis(count, content)
+ .asTuple()
+ .map(
+ t -> {
+ final Long totalElements = t.getItem1();
+ final List results = t.getItem2();
+ return FilterResult.builder(
+ totalElements, results.size(), results
+ )
+ .page(offset.getPageNumber())
+ .totalPages(totalElements / results.size())
+ .build();
+ }
+ );
+ }
+
}
diff --git a/src/main/java/dev/struchkov/haiti/filter/quarkus/FilterResult.java b/src/main/java/dev/struchkov/haiti/filter/quarkus/FilterResult.java
new file mode 100644
index 0000000..3b754ce
--- /dev/null
+++ b/src/main/java/dev/struchkov/haiti/filter/quarkus/FilterResult.java
@@ -0,0 +1,88 @@
+package dev.struchkov.haiti.filter.quarkus;
+
+import dev.struchkov.haiti.utils.Assert;
+
+import java.util.List;
+
+public class FilterResult {
+
+ private final Long totalElements;
+ private final Integer elements;
+ private Long totalPages;
+ private Integer page;
+ private final List content;
+
+ private FilterResult(Builder builder) {
+ this.totalElements = builder.totalElements;
+ this.elements = builder.elements;
+ this.totalPages = builder.totalPages;
+ this.page = builder.page;
+ this.content = builder.content;
+ }
+
+ public Long getTotalElements() {
+ return totalElements;
+ }
+
+ public Integer getElements() {
+ return elements;
+ }
+
+ public Long getTotalPages() {
+ return totalPages;
+ }
+
+ public Integer getPage() {
+ return page;
+ }
+
+ public List getContent() {
+ return content;
+ }
+
+ public static Builder builder(
+ Long totalElements,
+ Integer elements,
+ List content
+ ) {
+ Assert.isNotNull(totalElements, elements, content);
+ return new FilterResult.Builder<>(totalElements, elements, content);
+ }
+
+ public static class Builder {
+ private final Long totalElements;
+ private final Integer elements;
+ private final List content;
+ private Long totalPages;
+ private Integer page;
+
+ private Builder(Long totalElements, Integer elements, List content) {
+ this.totalElements = totalElements;
+ this.elements = elements;
+ this.content = content;
+ }
+
+ public Builder totalPages(Long totalPages) {
+ this.totalPages = totalPages;
+ return this;
+ }
+
+ public Builder page(Integer page) {
+ this.page = page;
+ return this;
+ }
+
+ public FilterResult build() {
+ return new FilterResult<>(this);
+ }
+
+ }
+
+ public FilterResult replaceContent(List list) {
+ return FilterResult.builder(totalElements, elements, list)
+ .page(page)
+ .totalPages(totalPages)
+ .build();
+ }
+
+}