Skip to content

Commit b0e2f79

Browse files
committed
Make sure the empty callback is only called during rendering
1 parent ad939fb commit b0e2f79

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public final <R> Stream<R> mapValues(Function<T, R> mapper) {
4141

4242
@Override
4343
public boolean shouldRender() {
44-
if (values.isEmpty()) {
45-
emptyCallback.call();
46-
return false;
47-
} else {
48-
return true;
49-
}
44+
return !values.isEmpty();
45+
}
46+
47+
@Override
48+
public void renderingSkipped() {
49+
emptyCallback.call();
5050
}
5151

5252
@Override

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,4 +28,10 @@ public interface VisitableCondition<T> {
2828
default boolean shouldRender() {
2929
return true;
3030
}
31+
32+
/**
33+
* This method will be called during rendering when {@link VisitableCondition#shouldRender()}
34+
* returns false.
35+
*/
36+
default void renderingSkipped() {}
3137
}

src/main/java/org/mybatis/dynamic/sql/where/render/CriterionRenderer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -69,6 +69,7 @@ public <T> Optional<RenderedCriterion> visit(ColumnAndConditionCriterion<T> crit
6969
if (criterion.condition().shouldRender()) {
7070
return renderWithInitialCondition(renderCondition(criterion), criterion);
7171
} else {
72+
criterion.condition().renderingSkipped();
7273
return renderWithoutInitialCondition(criterion);
7374
}
7475
}

0 commit comments

Comments
 (0)