Skip to content

Commit 7b426ce

Browse files
committed
Make filtering optional on no value conditions
1 parent f49cf7f commit 7b426ce

File tree

4 files changed

+18
-38
lines changed

4 files changed

+18
-38
lines changed

src/main/java/org/mybatis/dynamic/sql/AbstractNoValueCondition.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,23 @@ protected <S extends AbstractNoValueCondition<?>> S filterSupport(BooleanSupplie
3434

3535
public abstract String operator();
3636

37-
/**
38-
* If renderable and the supplier returns true, returns this condition. Else returns a condition that will not
39-
* render.
40-
*
41-
* @param booleanSupplier
42-
* function that specifies whether the condition should render
43-
* @param <S>
44-
* condition type - not used except for compilation compliance
45-
*
46-
* @return this condition if renderable and the supplier returns true, otherwise a condition that will not render.
47-
*/
48-
public abstract <S> AbstractNoValueCondition<S> filter(BooleanSupplier booleanSupplier);
49-
50-
51-
@Override
37+
@Override
5238
public FragmentAndParameters renderCondition(RenderingContext renderingContext, BindableColumn<T> leftColumn) {
5339
return FragmentAndParameters.fromFragment(operator());
5440
}
41+
42+
public interface Filterable {
43+
/**
44+
* If renderable and the supplier returns true, returns this condition. Else returns a condition that will not
45+
* render.
46+
*
47+
* @param booleanSupplier
48+
* function that specifies whether the condition should render
49+
* @param <S>
50+
* condition type - not used except for compilation compliance
51+
*
52+
* @return this condition if renderable and the supplier returns true, otherwise a condition that will not render.
53+
*/
54+
<S> AbstractNoValueCondition<S> filter(BooleanSupplier booleanSupplier);
55+
}
5556
}

src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotNull.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import org.mybatis.dynamic.sql.AbstractNoValueCondition;
2121

22-
public class IsNotNull<T> extends AbstractNoValueCondition<T> {
22+
public class IsNotNull<T> extends AbstractNoValueCondition<T> implements AbstractNoValueCondition.Filterable {
2323
private static final IsNotNull<?> EMPTY = new IsNotNull<>() {
2424
@Override
2525
public boolean isEmpty() {

src/main/java/org/mybatis/dynamic/sql/where/condition/IsNull.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import org.mybatis.dynamic.sql.AbstractNoValueCondition;
2121

22-
public class IsNull<T> extends AbstractNoValueCondition<T> {
22+
public class IsNull<T> extends AbstractNoValueCondition<T> implements AbstractNoValueCondition.Filterable {
2323
private static final IsNull<?> EMPTY = new IsNull<>() {
2424
@Override
2525
public boolean isEmpty() {

src/test/java/examples/mysql/MemberOfCondition.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,12 @@
1616
package examples.mysql;
1717

1818
import java.util.Objects;
19-
import java.util.function.BooleanSupplier;
2019

2120
import org.jspecify.annotations.NullMarked;
2221
import org.mybatis.dynamic.sql.AbstractNoValueCondition;
2322

2423
@NullMarked
2524
public class MemberOfCondition<T> extends AbstractNoValueCondition<T> {
26-
private static final MemberOfCondition<?> EMPTY = new MemberOfCondition<>("") {
27-
@Override
28-
public boolean isEmpty() {
29-
return true;
30-
}
31-
};
32-
33-
public static <T> MemberOfCondition<T> empty() {
34-
@SuppressWarnings("unchecked")
35-
MemberOfCondition<T> t = (MemberOfCondition<T>) EMPTY;
36-
return t;
37-
}
38-
3925
private final String jsonArray;
4026

4127
protected MemberOfCondition(String jsonArray) {
@@ -47,13 +33,6 @@ public String operator() {
4733
return "member of(" + jsonArray + ")";
4834
}
4935

50-
@Override
51-
public <S> MemberOfCondition<S> filter(BooleanSupplier booleanSupplier) {
52-
@SuppressWarnings("unchecked")
53-
MemberOfCondition<S> self = (MemberOfCondition<S>) this;
54-
return filterSupport(booleanSupplier, MemberOfCondition::empty, self);
55-
}
56-
5736
public static <T> MemberOfCondition<T> memberOf(String jsonArray) {
5837
return new MemberOfCondition<>(jsonArray);
5938
}

0 commit comments

Comments
 (0)