Skip to content

Commit a1d92ef

Browse files
committed
Polishing
1 parent 6153b3e commit a1d92ef

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/main/java/org/mybatis/dynamic/sql/common/AbstractBooleanExpressionRenderer.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.mybatis.dynamic.sql.common;
1717

18+
import static org.mybatis.dynamic.sql.util.StringUtilities.spaceAfter;
19+
1820
import java.util.Objects;
1921
import java.util.Optional;
2022
import java.util.concurrent.atomic.AtomicInteger;
@@ -30,20 +32,19 @@
3032

3133
public abstract class AbstractBooleanExpressionRenderer<M extends AbstractBooleanExpressionModel> {
3234
protected final M model;
33-
private final CriterionRenderer criterionRenderer;
3435
private final String prefix;
36+
private final CriterionRenderer criterionRenderer;
3537

3638
protected AbstractBooleanExpressionRenderer(String prefix, AbstractBuilder<M, ?> builder) {
3739
model = Objects.requireNonNull(builder.model);
40+
this.prefix = Objects.requireNonNull(prefix);
3841

3942
criterionRenderer = new CriterionRenderer.Builder()
4043
.withSequence(builder.sequence)
4144
.withRenderingStrategy(builder.renderingStrategy)
4245
.withTableAliasCalculator(builder.tableAliasCalculator)
4346
.withParameterName(builder.parameterName)
4447
.build();
45-
46-
this.prefix = Objects.requireNonNull(prefix);
4748
}
4849

4950
public Optional<FragmentAndParameters> render() {
@@ -67,24 +68,29 @@ private Optional<RenderedCriterion> renderWithoutInitialCriterion() {
6768
private String calculateClause(FragmentCollector collector) {
6869
if (collector.hasMultipleFragments()) {
6970
return collector.fragments()
70-
.collect(Collectors.joining(" ", prefix + " ", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
71+
.collect(Collectors.joining(" ", spaceAfter(prefix), "")); //$NON-NLS-1$ //$NON-NLS-2$
7172
} else {
7273
return collector.firstFragment()
7374
.map(this::stripEnclosingParenthesesIfPresent)
74-
.map(s -> prefix + " " + s) //$NON-NLS-1$
75+
.map(this::addPrefix)
7576
.orElse(""); //$NON-NLS-1$
7677
}
7778
}
7879

7980
private String stripEnclosingParenthesesIfPresent(String fragment) {
8081
// The fragment will have surrounding open/close parentheses if there is more than one rendered condition.
81-
// Since there is only a single fragment, we don't need these in the where clause
82+
// Since there is only a single fragment, we don't need these in the final rendered clause
8283
if (fragment.startsWith("(") && fragment.endsWith(")")) { //$NON-NLS-1$ //$NON-NLS-2$
8384
return fragment.substring(1, fragment.length() - 1);
8485
} else {
8586
return fragment;
8687
}
8788
}
89+
90+
private String addPrefix(String fragment) {
91+
return spaceAfter(prefix) + fragment;
92+
}
93+
8894
public abstract static class AbstractBuilder<M, B extends AbstractBuilder<M, B>> {
8995
private final M model;
9096
private RenderingStrategy renderingStrategy;

0 commit comments

Comments
 (0)