File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
src/main/java/org/mybatis/dynamic/sql/common Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -65,10 +65,26 @@ private Optional<RenderedCriterion> renderWithoutInitialCriterion() {
65
65
}
66
66
67
67
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
+ }
70
77
}
71
78
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
+ }
72
88
public abstract static class AbstractBuilder <M , B extends AbstractBuilder <M , B >> {
73
89
private final M model ;
74
90
private RenderingStrategy renderingStrategy ;
You can’t perform that action at this time.
0 commit comments