Skip to content

Commit 1d41ea4

Browse files
committedMar 13, 2025
Define a map template method for no value
1 parent 1da7647 commit 1d41ea4

File tree

4 files changed

+38
-23
lines changed

4 files changed

+38
-23
lines changed
 

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

+15-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,21 @@ protected <S extends AbstractNoValueCondition<?>> S filterSupport(BooleanSupplie
3434

3535
public abstract String operator();
3636

37-
@Override
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
3852
public FragmentAndParameters renderCondition(RenderingContext renderingContext, BindableColumn<T> leftColumn) {
3953
return FragmentAndParameters.fromFragment(operator());
4054
}

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

+1-11
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,7 @@ public String operator() {
4242
return "is not null"; //$NON-NLS-1$
4343
}
4444

45-
/**
46-
* If renderable and the supplier returns true, returns this condition. Else returns a condition that will not
47-
* render.
48-
*
49-
* @param booleanSupplier
50-
* function that specifies whether the condition should render
51-
* @param <S>
52-
* condition type - not used except for compilation compliance
53-
*
54-
* @return this condition if renderable and the supplier returns true, otherwise a condition that will not render.
55-
*/
45+
@Override
5646
public <S> IsNotNull<S> filter(BooleanSupplier booleanSupplier) {
5747
@SuppressWarnings("unchecked")
5848
IsNotNull<S> self = (IsNotNull<S>) this;

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

+1-11
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,7 @@ public String operator() {
4242
return "is null"; //$NON-NLS-1$
4343
}
4444

45-
/**
46-
* If renderable and the supplier returns true, returns this condition. Else returns a condition that will not
47-
* render.
48-
*
49-
* @param booleanSupplier
50-
* function that specifies whether the condition should render
51-
* @param <S>
52-
* condition type - not used except for compilation compliance
53-
*
54-
* @return this condition if renderable and the supplier returns true, otherwise a condition that will not render.
55-
*/
45+
@Override
5646
public <S> IsNull<S> filter(BooleanSupplier booleanSupplier) {
5747
@SuppressWarnings("unchecked")
5848
IsNull<S> self = (IsNull<S>) this;

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

+21
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,26 @@
1616
package examples.mysql;
1717

1818
import java.util.Objects;
19+
import java.util.function.BooleanSupplier;
1920

2021
import org.jspecify.annotations.NullMarked;
2122
import org.mybatis.dynamic.sql.AbstractNoValueCondition;
2223

2324
@NullMarked
2425
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+
2539
private final String jsonArray;
2640

2741
protected MemberOfCondition(String jsonArray) {
@@ -33,6 +47,13 @@ public String operator() {
3347
return "member of(" + jsonArray + ")";
3448
}
3549

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+
3657
public static <T> MemberOfCondition<T> memberOf(String jsonArray) {
3758
return new MemberOfCondition<>(jsonArray);
3859
}

0 commit comments

Comments
 (0)
Failed to load comments.