diff --git a/pom.xml b/pom.xml
index e64fa1e..896d9c3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
dev.struchkov.haiti.filter
haiti-filter-jooq
- 0.2.0
+ 0.3.0
jar
Haiti Filter JOOQ
@@ -18,6 +18,10 @@
https://raw.githubusercontent.com/haiti-projects/haiti-filter-jooq/master/LICENSE
+
+ GitHub
+ https://github.com/haiti-projects/haiti-filter-jooq/issues
+
11
@@ -36,7 +40,7 @@
dev.struchkov.haiti
haiti-bom
- 0.0.2
+ 1.0.0
pom
import
@@ -46,11 +50,11 @@
dev.struchkov.haiti
- haiti-filter
+ haiti-utils
dev.struchkov.haiti
- haiti-utils
+ haiti-exception
org.jooq
@@ -59,28 +63,6 @@
-
- scm:git:https://github.com/haiti-projects/haiti-filter-jooq.git
- https://github.com/haiti-projects/haiti-filter-jooq
- scm:git:https://github.com/haiti-projects/haiti-filter-jooq.git
-
-
-
-
- ossrh
- https://s01.oss.sonatype.org/content/repositories/snapshots
-
-
-
-
-
- uPagge
- Struchkov Mark
- https://mark.struchkov.dev
- mark@struchkov.dev
-
-
-
@@ -153,6 +135,14 @@
11
+
+ org.apache.maven.plugins
+ maven-source-plugin
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+
@@ -171,15 +161,37 @@
org.apache.maven.plugins
- maven-gpg-plugin
+ maven-javadoc-plugin
org.apache.maven.plugins
- maven-javadoc-plugin
+ maven-gpg-plugin
+
+ scm:git:https://github.com/haiti-projects/haiti-filter-jooq.git
+ https://github.com/haiti-projects/haiti-filter-jooq
+ scm:git:https://github.com/haiti-projects/haiti-filter-jooq.git
+
+
+
+
+ ossrh
+ https://s01.oss.sonatype.org/content/repositories/snapshots
+
+
+
+
+
+ uPagge
+ Struchkov Mark
+ https://mark.struchkov.dev
+ mark@struchkov.dev
+
+
+
\ No newline at end of file
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 9e20e1c..5caec92 100644
--- a/src/main/java/dev/struchkov/haiti/filter/jooq/CriteriaJooqFilter.java
+++ b/src/main/java/dev/struchkov/haiti/filter/jooq/CriteriaJooqFilter.java
@@ -1,12 +1,9 @@
package dev.struchkov.haiti.filter.jooq;
-import dev.struchkov.haiti.filter.Filter;
-import dev.struchkov.haiti.filter.FilterQuery;
import dev.struchkov.haiti.filter.jooq.exception.FilterJooqHaitiException;
import dev.struchkov.haiti.filter.jooq.page.PageableOffset;
import dev.struchkov.haiti.filter.jooq.page.PageableSeek;
import dev.struchkov.haiti.utils.Assert;
-import lombok.NonNull;
import org.jooq.Condition;
import org.jooq.DSLContext;
import org.jooq.Operator;
@@ -21,15 +18,16 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
+import static dev.struchkov.haiti.filter.jooq.exception.FilterJooqHaitiException.filterJooqException;
import static org.jooq.impl.DSL.condition;
import static org.jooq.impl.DSL.field;
-public class CriteriaJooqFilter implements Filter {
+public class CriteriaJooqFilter {
private final List andConditions = new ArrayList<>();
private final List orConditions = new ArrayList<>();
private final List notConditions = new ArrayList<>();
- private final List joinTables = new ArrayList<>();
+// private final List joinTables = new ArrayList<>();
private final String table;
private final DSLContext dsl;
@@ -47,84 +45,83 @@ public class CriteriaJooqFilter implements Filter {
return new CriteriaJooqFilter(table, dsl);
}
- @Override
- public Filter and(FilterQuery filterQuery) {
- generateAnd((CriteriaJooqQuery) filterQuery);
+ public CriteriaJooqFilter and(CriteriaJooqQuery filterQuery) {
+ generateAnd(filterQuery);
return this;
}
- @Override
- public Filter and(Consumer query) {
+ public CriteriaJooqFilter and(Consumer query) {
final CriteriaJooqQuery criteriaQuery = CriteriaJooqQuery.create();
query.accept(criteriaQuery);
generateAnd(criteriaQuery);
return this;
}
- @Override
- public Filter or(FilterQuery filterQuery) {
- generateOr((CriteriaJooqQuery) filterQuery);
+ public CriteriaJooqFilter or(CriteriaJooqQuery filterQuery) {
+ generateOr(filterQuery);
return this;
}
- public Filter or(Consumer query) {
+ public CriteriaJooqFilter or(Consumer query) {
final CriteriaJooqQuery criteriaQuery = CriteriaJooqQuery.create();
query.accept(criteriaQuery);
generateOr(criteriaQuery);
return this;
}
- @Override
- public Filter not(FilterQuery filterQuery) {
- // FIXME: Добавить поддержку
- throw new IllegalStateException("Операция отрицания пока не поддерживается");
- }
+// FIXME: Добавить поддержку
+// public CriteriaJooqFilter not(FilterQuery filterQuery) {
+// throw new IllegalStateException("Операция отрицания пока не поддерживается");
+// }
- @Override
- public Filter not(Consumer query) {
- // FIXME: Добавить поддержку
- throw new IllegalStateException("Операция отрицания пока не поддерживается");
- }
- public Filter page(@NonNull PageableOffset offset) {
- Assert.isNull(seek, () -> new FilterJooqHaitiException("Нельзя установить два типа пагинации одновременно"));
+// FIXME: Добавить поддержку
+// public CriteriaJooqFilter not(Consumer query) {
+// throw new IllegalStateException("Операция отрицания пока не поддерживается");
+// }
+
+ public CriteriaJooqFilter page(PageableOffset offset) {
+ Assert.isNotNull(offset);
+ Assert.isNull(seek, filterJooqException("Нельзя установить два типа пагинации одновременно"));
this.offset = offset;
return this;
}
- public Filter page(@NonNull PageableSeek seek) {
- Assert.isNull(offset, () -> new FilterJooqHaitiException("Нельзя установить два типа пагинации одновременно"));
+ public CriteriaJooqFilter page(PageableSeek seek) {
+ Assert.isNotNull(seek);
+ Assert.isNull(offset, filterJooqException("Нельзя установить два типа пагинации одновременно"));
this.seek = seek;
return this;
}
- public Filter sort(@NonNull SortContainer container) {
+ public CriteriaJooqFilter sort(SortContainer container) {
+ Assert.isNotNull(container);
if (container.getFieldName() != null) {
this.sorts.add(container);
}
return this;
}
- public Filter sort(String field, SortType sortType) {
+ public CriteriaJooqFilter sort(String field, SortType sortType) {
if (field != null) {
this.sorts.add(SortContainer.of(field, sortType));
}
return this;
}
- public Filter sort(String field) {
+ public CriteriaJooqFilter sort(String field) {
if (field != null) {
this.sorts.add(SortContainer.of(field));
}
return this;
}
- public Filter join(@NonNull JoinTable... joinTables) {
- // FIXME: Добавить поддержку
- throw new IllegalStateException("Операция пока не поддерживается");
+// FIXME: Добавить поддержку
+// public CriteriaJooqFilter join(@NonNull JoinTable... joinTables) {
+// throw new IllegalStateException("Операция пока не поддерживается");
// this.joinTables.addAll(Arrays.stream(joinTables).collect(Collectors.toList()));
// return this;
- }
+// }
private void generateAnd(CriteriaJooqQuery criteriaQuery) {
andConditions.addAll(criteriaQuery.getConditions());
@@ -134,8 +131,38 @@ public class CriteriaJooqFilter implements Filter {
orConditions.addAll(criteriaQuery.getConditions());
}
- @Override
public Query build() {
+ final List conditions = getConditions();
+ SelectJoinStep from = dsl.select().from(table);
+// if (!joinTables.isEmpty()) {
+// for (JoinTable joinTable : joinTables) {
+// final String tableName = joinTable.getTableName();
+// final JoinTypeOperation joinType = joinTable.getJoinTypeOperation();
+// final String fieldReference = joinTable.getFieldReference();
+// final String fieldBase = joinTable.getFieldBase();
+// final Condition on = field(fieldReference).eq(field(fieldBase));
+// switch (joinType) {
+// case LEFT:
+// from = from.leftJoin(tableName).on(on);
+// break;
+// case INNER:
+// from = from.innerJoin(tableName).on(on);
+// break;
+// case RIGHT:
+// from = from.rightJoin(tableName).on(on);
+// break;
+// }
+// }
+// }
+ final SelectConditionStep where = from.where(conditions);
+ final SelectSeekStepN extends Record> sort = setSort(where);
+ setPaginationOffset(where);
+ setPaginationSeek(sort);
+
+ return where;
+ }
+
+ private List getConditions() {
final List conditions = new ArrayList<>();
if (!andConditions.isEmpty()) {
conditions.add(condition(Operator.AND, andConditions));
@@ -143,35 +170,38 @@ public class CriteriaJooqFilter implements Filter {
if (!orConditions.isEmpty()) {
conditions.add(condition(Operator.OR, orConditions));
}
- SelectJoinStep from = dsl.select().from(table);
- if (!joinTables.isEmpty()) {
- for (JoinTable joinTable : joinTables) {
- final String tableName = joinTable.getTableName();
- final JoinTypeOperation joinType = joinTable.getJoinTypeOperation();
- final String fieldReference = joinTable.getFieldReference();
- final String fieldBase = joinTable.getFieldBase();
- final Condition on = field(fieldReference).eq(field(fieldBase));
- switch (joinType) {
- case LEFT:
- from = from.leftJoin(tableName).on(on);
- break;
- case INNER:
- from = from.innerJoin(tableName).on(on);
- break;
- case RIGHT:
- from = from.rightJoin(tableName).on(on);
- break;
- }
- }
- }
- final SelectConditionStep where = from.where(conditions);
- final SelectSeekStepN sort = setSort(where);
- setPaginationOffset(where);
- setPaginationSeek(sort);
+ return conditions;
+ }
+
+ public Query count() {
+ final List conditions = getConditions();
+ SelectJoinStep extends Record> from = dsl.selectCount().from(table);
+// if (!joinTables.isEmpty()) {
+// for (JoinTable joinTable : joinTables) {
+// final String tableName = joinTable.getTableName();
+// final JoinTypeOperation joinType = joinTable.getJoinTypeOperation();
+// final String fieldReference = joinTable.getFieldReference();
+// final String fieldBase = joinTable.getFieldBase();
+// final Condition on = field(fieldReference).eq(field(fieldBase));
+// switch (joinType) {
+// case LEFT:
+// from = from.leftJoin(tableName).on(on);
+// break;
+// case INNER:
+// from = from.innerJoin(tableName).on(on);
+// break;
+// case RIGHT:
+// from = from.rightJoin(tableName).on(on);
+// break;
+// }
+// }
+// }
+ final SelectConditionStep extends Record> where = from.where(conditions);
+ setSort(where);
return where;
}
- private SelectSeekStepN setSort(SelectConditionStep where) {
+ private SelectSeekStepN extends Record> setSort(SelectConditionStep extends Record> where) {
if (!sorts.isEmpty()) {
final List> newSorts = new ArrayList<>();
for (SortContainer sort : sorts) {
@@ -188,7 +218,7 @@ public class CriteriaJooqFilter implements Filter {
return null;
}
- private void setPaginationSeek(SelectSeekStepN sort) {
+ private void setPaginationSeek(SelectSeekStepN extends Record> sort) {
if (seek != null) {
Assert.isNotNull(sort, () -> new FilterJooqHaitiException("При использовании пагинации типа seek необходимо указать сортировку"));
final Integer pageSize = seek.getPageSize();
@@ -206,7 +236,7 @@ public class CriteriaJooqFilter implements Filter {
}
}
- private void setPaginationOffset(SelectConditionStep where) {
+ private void setPaginationOffset(SelectConditionStep extends Record> where) {
if (offset != null) {
final int pageNumber = offset.getPageNumber();
final int pageSize = offset.getPageSize();
@@ -214,4 +244,5 @@ public class CriteriaJooqFilter implements Filter {
where.limit(pageSize).offset(offsetNumber);
}
}
+
}
diff --git a/src/main/java/dev/struchkov/haiti/filter/jooq/CriteriaJooqQuery.java b/src/main/java/dev/struchkov/haiti/filter/jooq/CriteriaJooqQuery.java
index 312bccf..5de0b31 100644
--- a/src/main/java/dev/struchkov/haiti/filter/jooq/CriteriaJooqQuery.java
+++ b/src/main/java/dev/struchkov/haiti/filter/jooq/CriteriaJooqQuery.java
@@ -1,7 +1,6 @@
package dev.struchkov.haiti.filter.jooq;
-import dev.struchkov.haiti.filter.FilterQuery;
-import lombok.NonNull;
+import dev.struchkov.haiti.utils.Assert;
import org.jooq.Condition;
import org.jooq.Field;
import org.jooq.impl.DSL;
@@ -14,7 +13,7 @@ import java.util.Set;
import static org.jooq.impl.DSL.condition;
import static org.jooq.impl.DSL.field;
-public class CriteriaJooqQuery implements FilterQuery {
+public class CriteriaJooqQuery {
private final List conditions = new ArrayList<>();
@@ -22,12 +21,12 @@ public class CriteriaJooqQuery implements FilterQuery {
return new CriteriaJooqQuery();
}
- protected List getConditions() {
+ List getConditions() {
return conditions;
}
- @Override
- public > FilterQuery between(@NonNull String field, Y from, Y to) {
+ public > CriteriaJooqQuery between(String field, Y from, Y to) {
+ Assert.isNotNull(field);
if (from != null && to != null) {
Condition condition = DSL.field(field).between(from, to);
conditions.add(condition);
@@ -35,20 +34,8 @@ public class CriteriaJooqQuery implements FilterQuery {
return this;
}
- @Override
- public > FilterQuery greaterThan(@NonNull String field, Y value) {
- // FIXME: Добавить поддержку
- throw new IllegalStateException("Операция пока не поддерживается");
- }
-
- @Override
- public > FilterQuery lessThan(@NonNull String field, Y value) {
- // FIXME: Добавить поддержку
- throw new IllegalStateException("Операция пока не поддерживается");
- }
-
- @Override
- public FilterQuery matchPhrase(@NonNull String field, Object value) {
+ public CriteriaJooqQuery matchPhrase(String field, Object value) {
+ Assert.isNotNull(field);
if (value != null) {
final Condition condition = condition(Map.of(field(field), value));
conditions.add(condition);
@@ -56,24 +43,23 @@ public class CriteriaJooqQuery implements FilterQuery {
return this;
}
- @Override
- public FilterQuery matchPhrase(@NonNull String field, Set values) {
+ public CriteriaJooqQuery matchPhrase(String field, Set values) {
+ Assert.isNotNull(field);
if (values != null && !values.isEmpty()) {
conditions.add(DSL.field(field).in(values));
}
return this;
}
- @Override
- public FilterQuery exists(String field) {
+ public CriteriaJooqQuery exists(String field) {
if (field != null) {
conditions.add(DSL.field(field).isNotNull());
}
return this;
}
- @Override
- public FilterQuery like(@NonNull String field, String value, boolean ignoreCase) {
+ public CriteriaJooqQuery like(String field, String value, boolean ignoreCase) {
+ Assert.isNotNull(field);
final Field