Skip to content

Commit 112efe8

Browse files
committed
Merge resolution
1 parent 5733e1c commit 112efe8

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,26 @@ private Optional<RenderedCriterion> renderWithoutInitialCriterion() {
6565
}
6666

6767
private String calculateClause(FragmentCollector collector) {
68-
return collector.fragments()
69-
.collect(Collectors.joining(" ", prefix + " ", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
68+
if (collector.hasMultipleFragments()) {
69+
return collector.fragments()
70+
.collect(Collectors.joining(" ", prefix + " ", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
71+
} else {
72+
return collector.firstFragment()
73+
.map(this::stripEnclosingParenthesesIfPresent)
74+
.map(s -> prefix + " " + s) //$NON-NLS-1$
75+
.orElse(""); //$NON-NLS-1$
76+
}
7077
}
7178

79+
private String stripEnclosingParenthesesIfPresent(String fragment) {
80+
// 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+
if (fragment.startsWith("(") && fragment.endsWith(")")) { //$NON-NLS-1$ //$NON-NLS-2$
83+
return fragment.substring(1, fragment.length() - 1);
84+
} else {
85+
return fragment;
86+
}
87+
}
7288
public abstract static class AbstractBuilder<M, B extends AbstractBuilder<M, B>> {
7389
private final M model;
7490
private RenderingStrategy renderingStrategy;

0 commit comments

Comments
 (0)