Добавил возможность использовать not операции
This commit is contained in:
parent
2b5d5ce9f6
commit
24df33a6b3
18
.gitignore
vendored
18
.gitignore
vendored
@ -20,21 +20,7 @@ dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
.idea/**/contentModel.xml
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
.idea/
|
||||
cmake-build-*/
|
||||
.idea/**/mongoSettings.xml
|
||||
*.iws
|
||||
@ -46,8 +32,6 @@ com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
.idea/httpRequests
|
||||
.idea/caches/build_file_checksums.ser
|
||||
*~
|
||||
.fuse_hidden*
|
||||
.directory
|
||||
|
7
pom.xml
7
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>dev.struchkov.haiti.filter</groupId>
|
||||
<artifactId>haiti-filter-jooq</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.9.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Haiti Filter JOOQ</name>
|
||||
@ -24,13 +24,14 @@
|
||||
</issueManagement>
|
||||
|
||||
<properties>
|
||||
<java.version>11</java.version>
|
||||
<java.version>17</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>
|
||||
|
||||
<jooq.version>3.15.5</jooq.version>
|
||||
<!-- https://mvnrepository.com/artifact/org.jooq/jooq -->
|
||||
<jooq.version>3.18.3</jooq.version>
|
||||
|
||||
<plugin.nexus.staging.ver>1.6.8</plugin.nexus.staging.ver>
|
||||
<plugin.maven.source.ver>3.2.1</plugin.maven.source.ver>
|
||||
|
@ -31,9 +31,9 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static dev.struchkov.haiti.filter.jooq.exception.FilterJooqHaitiException.filterJooqException;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static org.jooq.impl.DSL.condition;
|
||||
import static org.jooq.impl.DSL.field;
|
||||
|
||||
@ -41,7 +41,6 @@ public class CriteriaJooqFilter {
|
||||
|
||||
private final List<Condition> andConditions = new ArrayList<>();
|
||||
private final List<Condition> orConditions = new ArrayList<>();
|
||||
private final List<Condition> notConditions = new ArrayList<>();
|
||||
private final List<JoinTable> joinTables = new ArrayList<>();
|
||||
|
||||
private final Table<Record> generalTable;
|
||||
@ -85,17 +84,6 @@ public class CriteriaJooqFilter {
|
||||
return this;
|
||||
}
|
||||
|
||||
// FIXME: Добавить поддержку
|
||||
// public CriteriaJooqFilter not(FilterQuery filterQuery) {
|
||||
// throw new IllegalStateException("Операция отрицания пока не поддерживается");
|
||||
// }
|
||||
|
||||
|
||||
// FIXME: Добавить поддержку
|
||||
// public CriteriaJooqFilter not(Consumer<FilterQuery> query) {
|
||||
// throw new IllegalStateException("Операция отрицания пока не поддерживается");
|
||||
// }
|
||||
|
||||
public CriteriaJooqFilter page(PageableOffset offset) {
|
||||
Inspector.isNotNull(offset);
|
||||
Inspector.isNull(seek, filterJooqException("Нельзя установить два типа пагинации одновременно"));
|
||||
@ -154,7 +142,7 @@ public class CriteriaJooqFilter {
|
||||
|
||||
public CriteriaJooqFilter join(JoinTable... joinTables) {
|
||||
Inspector.isNotNull(joinTables);
|
||||
this.joinTables.addAll(Arrays.stream(joinTables).collect(Collectors.toList()));
|
||||
this.joinTables.addAll(Arrays.stream(joinTables).collect(toList()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -167,7 +155,7 @@ public class CriteriaJooqFilter {
|
||||
}
|
||||
|
||||
public Query generateQuery(String... fields) {
|
||||
final List<Field<Object>> selectFields = Arrays.stream(fields).map(DSL::field).collect(Collectors.toList());
|
||||
final List<Field<Object>> selectFields = Arrays.stream(fields).map(DSL::field).collect(toList());
|
||||
final SelectSelectStep<Record> mainSelect = !selectFields.isEmpty() ? dsl.select(selectFields) : dsl.select();
|
||||
final SelectLimitStep<? extends Record> selectSeekStepN = generate(mainSelect);
|
||||
return setPaginationOffset(selectSeekStepN);
|
||||
@ -201,7 +189,7 @@ public class CriteriaJooqFilter {
|
||||
return where.groupBy(
|
||||
groupByFields.stream()
|
||||
.map(DSL::field)
|
||||
.collect(Collectors.toList())
|
||||
.collect(toList())
|
||||
);
|
||||
}
|
||||
return where;
|
||||
|
@ -10,6 +10,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static dev.struchkov.haiti.utils.Checker.checkNotEmpty;
|
||||
import static org.jooq.impl.DSL.condition;
|
||||
import static org.jooq.impl.DSL.field;
|
||||
|
||||
@ -34,6 +35,15 @@ public class CriteriaJooqQuery {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <Y extends Comparable<? super Y>> CriteriaJooqQuery notBetween(String field, Y from, Y to) {
|
||||
Inspector.isNotNull(field);
|
||||
if (from != null && to != null) {
|
||||
Condition condition = DSL.field(field).notBetween(from, to);
|
||||
conditions.add(condition);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public CriteriaJooqQuery matchPhrase(String field, Object value) {
|
||||
Inspector.isNotNull(field);
|
||||
if (value != null) {
|
||||
@ -43,6 +53,14 @@ public class CriteriaJooqQuery {
|
||||
return this;
|
||||
}
|
||||
|
||||
public CriteriaJooqQuery matchPhrase(String field, Object... values) {
|
||||
Inspector.isNotNull(field);
|
||||
if (checkNotEmpty(values)) {
|
||||
conditions.add(DSL.field(field).in(values));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public <U> CriteriaJooqQuery matchPhrase(String field, Set<U> values) {
|
||||
Inspector.isNotNull(field);
|
||||
if (values != null) {
|
||||
@ -55,6 +73,35 @@ public class CriteriaJooqQuery {
|
||||
return this;
|
||||
}
|
||||
|
||||
public CriteriaJooqQuery notMatchPhrase(String field, Object value) {
|
||||
Inspector.isNotNull(field);
|
||||
if (value != null) {
|
||||
final Condition condition = condition(Map.of(field(field), value)).not();
|
||||
conditions.add(condition);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public <U> CriteriaJooqQuery notMatchPhrase(String field, Set<U> values) {
|
||||
Inspector.isNotNull(field);
|
||||
if (values != null) {
|
||||
if (values.isEmpty()) {
|
||||
conditions.add(DSL.field(field).isNull().not());
|
||||
} else {
|
||||
conditions.add(DSL.field(field).in(values).not());
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public CriteriaJooqQuery notMatchPhrase(String field, Object... values) {
|
||||
Inspector.isNotNull(field);
|
||||
if (checkNotEmpty(values)) {
|
||||
conditions.add(DSL.field(field).in(values).not());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public CriteriaJooqQuery exists(String field) {
|
||||
if (field != null) {
|
||||
conditions.add(DSL.field(field).isNotNull());
|
||||
@ -62,6 +109,13 @@ public class CriteriaJooqQuery {
|
||||
return this;
|
||||
}
|
||||
|
||||
public CriteriaJooqQuery notExists(String field) {
|
||||
if (field != null) {
|
||||
conditions.add(DSL.field(field).isNull());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public CriteriaJooqQuery like(String field, String value) {
|
||||
like(field, value, false);
|
||||
return this;
|
||||
@ -72,6 +126,16 @@ public class CriteriaJooqQuery {
|
||||
return this;
|
||||
}
|
||||
|
||||
public CriteriaJooqQuery notLike(String field, String value) {
|
||||
notLike(field, value, false);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CriteriaJooqQuery notLikeIgnoreCase(String field, String value) {
|
||||
notLike(field, value, true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CriteriaJooqQuery like(String field, String value, boolean ignoreCase) {
|
||||
Inspector.isNotNull(field);
|
||||
final Field<Object> query = field(field);
|
||||
@ -85,4 +149,17 @@ public class CriteriaJooqQuery {
|
||||
return this;
|
||||
}
|
||||
|
||||
public CriteriaJooqQuery notLike(String field, String value, boolean ignoreCase) {
|
||||
Inspector.isNotNull(field);
|
||||
final Field<Object> query = field(field);
|
||||
if (value != null) {
|
||||
if (ignoreCase) {
|
||||
conditions.add(query.likeIgnoreCase(value).not());
|
||||
} else {
|
||||
conditions.add(query.like(value).not());
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user