release-0.3.0
This commit is contained in:
parent
cb8dcd8fa4
commit
d3bb1c75f1
80
pom.xml
80
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>dev.struchkov.haiti.filter</groupId>
|
||||
<artifactId>haiti-filter-quarkus-reactive</artifactId>
|
||||
<version>0.2.0</version>
|
||||
<version>0.3.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Haiti Filter Reactive Quarkus</name>
|
||||
@ -18,14 +18,22 @@
|
||||
<url>https://raw.githubusercontent.com/haiti-projects/haiti-filter-reactive-quarkus/master/LICENSE</url>
|
||||
</license>
|
||||
</licenses>
|
||||
<issueManagement>
|
||||
<system>GitHub</system>
|
||||
<url>https://github.com/haiti-projects/haiti-filter-reactive-quarkus/issues</url>
|
||||
</issueManagement>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<java.version>11</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
<quarkus.platform.version>2.5.1.Final</quarkus.platform.version>
|
||||
<haiti.filter.jooq.version>0.2.0</haiti.filter.jooq.version>
|
||||
<haiti.filter.jooq.version>0.3.0</haiti.filter.jooq.version>
|
||||
|
||||
<plugin.maven.compiler.ver>3.9.0</plugin.maven.compiler.ver>
|
||||
<plugin.nexus.staging.ver>1.6.8</plugin.nexus.staging.ver>
|
||||
<plugin.maven.source.ver>3.2.1</plugin.maven.source.ver>
|
||||
<plugin.maven.javadoc.ver>3.3.1</plugin.maven.javadoc.ver>
|
||||
@ -54,21 +62,24 @@
|
||||
<groupId>io.smallrye.reactive</groupId>
|
||||
<artifactId>smallrye-mutiny-vertx-pg-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--Все зависимости ниже необходимы только для нативной сборки Quarkus-->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.xml.bind</groupId>
|
||||
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>20.1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:https://github.com/haiti-projects/haiti-filter-reactive-quarkus.git</connection>
|
||||
<url>https://github.com/haiti-projects/haiti-filter-reactive-quarkus</url>
|
||||
<developerConnection>scm:git:https://github.com/haiti-projects/haiti-filter-reactive-quarkus.git</developerConnection>
|
||||
</scm>
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>ossrh</id>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
@ -83,6 +94,15 @@
|
||||
<autoReleaseAfterClose>true</autoReleaseAfterClose>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${plugin.maven.compiler.ver}</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
@ -136,10 +156,14 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>11</source>
|
||||
<target>11</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
@ -170,6 +194,20 @@
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:https://github.com/haiti-projects/haiti-filter-reactive-quarkus.git</connection>
|
||||
<url>https://github.com/haiti-projects/haiti-filter-reactive-quarkus</url>
|
||||
<developerConnection>scm:git:https://github.com/haiti-projects/haiti-filter-reactive-quarkus.git
|
||||
</developerConnection>
|
||||
</scm>
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>ossrh</id>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<id>uPagge</id>
|
||||
|
@ -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<T> implements Filter {
|
||||
public class CriteriaFilter<T> {
|
||||
|
||||
private final PgPool pgPool;
|
||||
private final CriteriaJooqFilter jooqFilter;
|
||||
private final Function<Row, T> mapper;
|
||||
private PageableOffset offset;
|
||||
|
||||
private CriteriaFilter(PgPool pgPool, String table, DSLContext dslContext, Function<Row, T> mapper) {
|
||||
dslContext.settings().withParamType(ParamType.NAMED_OR_INLINED);
|
||||
@ -37,81 +37,89 @@ public class CriteriaFilter<T> implements Filter {
|
||||
return new CriteriaFilter<>(pgPool, table, dslContext, mapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter and(FilterQuery filterQuery) {
|
||||
public CriteriaFilter<T> and(CriteriaJooqQuery filterQuery) {
|
||||
jooqFilter.and(filterQuery);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter and(Consumer<FilterQuery> query) {
|
||||
public CriteriaFilter<T> and(Consumer<CriteriaJooqQuery> query) {
|
||||
jooqFilter.and(query);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter or(FilterQuery filterQuery) {
|
||||
|
||||
public CriteriaFilter<T> or(CriteriaJooqQuery filterQuery) {
|
||||
jooqFilter.or(filterQuery);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter or(Consumer<FilterQuery> query) {
|
||||
public CriteriaFilter<T> or(Consumer<CriteriaJooqQuery> query) {
|
||||
jooqFilter.or(query);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter not(FilterQuery filterQuery) {
|
||||
jooqFilter.not(filterQuery);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter not(Consumer<FilterQuery> query) {
|
||||
jooqFilter.not(query);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CriteriaFilter<T> page(@NonNull PageableOffset offset) {
|
||||
public CriteriaFilter<T> page(PageableOffset offset) {
|
||||
jooqFilter.page(offset);
|
||||
this.offset = offset;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CriteriaFilter<T> page(@NonNull PageableSeek seek) {
|
||||
public CriteriaFilter<T> page(PageableSeek seek) {
|
||||
jooqFilter.page(seek);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CriteriaFilter<T> join(@NonNull JoinTable... joinTables) {
|
||||
jooqFilter.join(joinTables);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CriteriaFilter<T> sort(@NonNull SortContainer container) {
|
||||
public CriteriaFilter<T> sort(SortContainer container) {
|
||||
jooqFilter.sort(container);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CriteriaFilter<T> sort(@NonNull String field, SortType sortType) {
|
||||
public CriteriaFilter<T> sort(String field, SortType sortType) {
|
||||
jooqFilter.sort(field, sortType);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CriteriaFilter<T> sort(@NonNull String field) {
|
||||
public CriteriaFilter<T> sort(String field) {
|
||||
jooqFilter.sort(field);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Multi<T> build() {
|
||||
public Uni<List<T>> 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<Long> count() {
|
||||
final Query query = jooqFilter.count();
|
||||
return pgPool.preparedQuery(query.getSQL())
|
||||
.execute()
|
||||
.map(t -> t.iterator().next().getLong("count"));
|
||||
}
|
||||
|
||||
public Uni<FilterResult<T>> filterResult() {
|
||||
final Uni<Long> count = count();
|
||||
final Uni<List<T>> content = build();
|
||||
return Uni.combine().all()
|
||||
.unis(count, content)
|
||||
.asTuple()
|
||||
.map(
|
||||
t -> {
|
||||
final Long totalElements = t.getItem1();
|
||||
final List<T> results = t.getItem2();
|
||||
return FilterResult.builder(
|
||||
totalElements, results.size(), results
|
||||
)
|
||||
.page(offset.getPageNumber())
|
||||
.totalPages(totalElements / results.size())
|
||||
.build();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,88 @@
|
||||
package dev.struchkov.haiti.filter.quarkus;
|
||||
|
||||
import dev.struchkov.haiti.utils.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FilterResult<T> {
|
||||
|
||||
private final Long totalElements;
|
||||
private final Integer elements;
|
||||
private Long totalPages;
|
||||
private Integer page;
|
||||
private final List<T> content;
|
||||
|
||||
private FilterResult(Builder<T> 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<T> getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public static <T> Builder<T> builder(
|
||||
Long totalElements,
|
||||
Integer elements,
|
||||
List<T> content
|
||||
) {
|
||||
Assert.isNotNull(totalElements, elements, content);
|
||||
return new FilterResult.Builder<>(totalElements, elements, content);
|
||||
}
|
||||
|
||||
public static class Builder<T> {
|
||||
private final Long totalElements;
|
||||
private final Integer elements;
|
||||
private final List<T> content;
|
||||
private Long totalPages;
|
||||
private Integer page;
|
||||
|
||||
private Builder(Long totalElements, Integer elements, List<T> content) {
|
||||
this.totalElements = totalElements;
|
||||
this.elements = elements;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public Builder<T> totalPages(Long totalPages) {
|
||||
this.totalPages = totalPages;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> page(Integer page) {
|
||||
this.page = page;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FilterResult<T> build() {
|
||||
return new FilterResult<>(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public <D> FilterResult<D> replaceContent(List<D> list) {
|
||||
return FilterResult.<D>builder(totalElements, elements, list)
|
||||
.page(page)
|
||||
.totalPages(totalPages)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user