Skip to content

Commit fbd0461

Browse files
committed
Merge branch 'master' into new-join-syntax
# Conflicts: # src/main/java/org/mybatis/dynamic/sql/select/QueryExpressionDSL.java
2 parents 3cc83da + 4215d85 commit fbd0461

18 files changed

+463
-197
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Other important changes:
3030
an empty In condition would render as invalid SQL and would usually cause a runtime exception from the database.
3131
With this change, the exception thrown is more predictable and the error is caught before sending the SQL to the
3232
database.
33+
- All the paging methods (limit, offset, fetchFirst) now have "WhenPresent" variations that will drop the phrase from
34+
rendering if a null value is passed in
3335

3436
## Release 1.5.2 - June 3, 2024
3537

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<properties>
5959
<java.version>17</java.version>
6060
<java.release.version>17</java.release.version>
61-
<junit.jupiter.version>5.10.3</junit.jupiter.version>
61+
<junit.jupiter.version>5.11.0</junit.jupiter.version>
6262
<spring.batch.version>5.1.2</spring.batch.version>
6363

6464
<checkstyle.config>checkstyle-override.xml</checkstyle.config>
@@ -94,7 +94,7 @@
9494
<dependency>
9595
<groupId>org.springframework</groupId>
9696
<artifactId>spring-jdbc</artifactId>
97-
<version>6.1.11</version>
97+
<version>6.1.12</version>
9898
<scope>provided</scope>
9999
<optional>true</optional>
100100
</dependency>
@@ -133,7 +133,7 @@
133133
<dependency>
134134
<groupId>org.mybatis</groupId>
135135
<artifactId>mybatis-spring</artifactId>
136-
<version>3.0.3</version>
136+
<version>3.0.4</version>
137137
<scope>test</scope>
138138
</dependency>
139139
<dependency>
@@ -163,7 +163,7 @@
163163
<dependency>
164164
<groupId>ch.qos.logback</groupId>
165165
<artifactId>logback-classic</artifactId>
166-
<version>1.5.6</version>
166+
<version>1.5.7</version>
167167
<scope>test</scope>
168168
</dependency>
169169
<dependency>

src/main/java/org/mybatis/dynamic/sql/delete/DeleteDSL.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public DeleteWhereBuilder where() {
5656
}
5757

5858
public DeleteDSL<R> limit(long limit) {
59+
return limitWhenPresent(limit);
60+
}
61+
62+
public DeleteDSL<R> limitWhenPresent(Long limit) {
5963
this.limit = limit;
6064
return this;
6165
}
@@ -115,7 +119,11 @@ private DeleteWhereBuilder() {
115119
}
116120

117121
public DeleteDSL<R> limit(long limit) {
118-
return DeleteDSL.this.limit(limit);
122+
return limitWhenPresent(limit);
123+
}
124+
125+
public DeleteDSL<R> limitWhenPresent(Long limit) {
126+
return DeleteDSL.this.limitWhenPresent(limit);
119127
}
120128

121129
public DeleteDSL<R> orderBy(SortSpecification... columns) {

src/main/java/org/mybatis/dynamic/sql/exception/NonRenderingWhereClauseException.java

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

18+
import java.io.Serial;
19+
1820
import org.mybatis.dynamic.sql.configuration.GlobalConfiguration;
1921
import org.mybatis.dynamic.sql.configuration.StatementConfiguration;
2022
import org.mybatis.dynamic.sql.util.Messages;
2123

22-
import java.io.Serial;
23-
2424
/**
2525
* This exception is thrown when the where clause in a statement will not render.
2626
* This can happen if all the optional conditions in a where clause fail to

src/main/java/org/mybatis/dynamic/sql/select/MultiSelectDSL.java

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
import org.mybatis.dynamic.sql.util.Buildable;
3030
import org.mybatis.dynamic.sql.util.ConfigurableStatement;
3131

32-
public class MultiSelectDSL implements Buildable<MultiSelectModel>, ConfigurableStatement<MultiSelectDSL> {
32+
public class MultiSelectDSL implements Buildable<MultiSelectModel>, ConfigurableStatement<MultiSelectDSL>,
33+
PagingDSL<MultiSelectModel> {
3334
private final List<UnionQuery> unionQueries = new ArrayList<>();
3435
private final SelectModel initialSelect;
3536
private OrderByModel orderByModel;
@@ -61,19 +62,22 @@ public MultiSelectDSL orderBy(Collection<? extends SortSpecification> columns) {
6162
return this;
6263
}
6364

64-
public LimitFinisher limit(long limit) {
65+
@Override
66+
public LimitFinisher<MultiSelectModel> limitWhenPresent(Long limit) {
6567
this.limit = limit;
66-
return new LimitFinisher();
68+
return new LF();
6769
}
6870

69-
public OffsetFirstFinisher offset(long offset) {
71+
@Override
72+
public OffsetFirstFinisher<MultiSelectModel> offsetWhenPresent(Long offset) {
7073
this.offset = offset;
71-
return new OffsetFirstFinisher();
74+
return new OFF();
7275
}
7376

74-
public FetchFirstFinisher fetchFirst(long fetchFirstRows) {
77+
@Override
78+
public FetchFirstFinisher<MultiSelectModel> fetchFirstWhenPresent(Long fetchFirstRows) {
7579
this.fetchFirstRows = fetchFirstRows;
76-
return new FetchFirstFinisher();
80+
return new FFF();
7781
}
7882

7983
@NotNull
@@ -102,31 +106,18 @@ public MultiSelectDSL configureStatement(Consumer<StatementConfiguration> consum
102106
return this;
103107
}
104108

105-
public class LimitFinisher implements Buildable<MultiSelectModel> {
106-
public OffsetFinisher offset(long offset) {
107-
MultiSelectDSL.this.offset(offset);
108-
return new OffsetFinisher();
109-
}
110-
111-
@NotNull
109+
class FFF implements FetchFirstFinisher<MultiSelectModel> {
112110
@Override
113-
public MultiSelectModel build() {
114-
return MultiSelectDSL.this.build();
111+
public Buildable<MultiSelectModel> rowsOnly() {
112+
return MultiSelectDSL.this;
115113
}
116114
}
117115

118-
public class OffsetFinisher implements Buildable<MultiSelectModel> {
119-
@NotNull
116+
class LF implements LimitFinisher<MultiSelectModel> {
120117
@Override
121-
public MultiSelectModel build() {
122-
return MultiSelectDSL.this.build();
123-
}
124-
}
125-
126-
public class OffsetFirstFinisher implements Buildable<MultiSelectModel> {
127-
public FetchFirstFinisher fetchFirst(long fetchFirstRows) {
128-
MultiSelectDSL.this.fetchFirst(fetchFirstRows);
129-
return new FetchFirstFinisher();
118+
public Buildable<MultiSelectModel> offsetWhenPresent(Long offset) {
119+
MultiSelectDSL.this.offset = offset;
120+
return MultiSelectDSL.this;
130121
}
131122

132123
@NotNull
@@ -136,13 +127,13 @@ public MultiSelectModel build() {
136127
}
137128
}
138129

139-
public class FetchFirstFinisher {
140-
public RowsOnlyFinisher rowsOnly() {
141-
return new RowsOnlyFinisher();
130+
class OFF implements OffsetFirstFinisher<MultiSelectModel> {
131+
@Override
132+
public FetchFirstFinisher<MultiSelectModel> fetchFirstWhenPresent(Long fetchFirstRows) {
133+
MultiSelectDSL.this.fetchFirstRows = fetchFirstRows;
134+
return new FFF();
142135
}
143-
}
144136

145-
public class RowsOnlyFinisher implements Buildable<MultiSelectModel> {
146137
@NotNull
147138
@Override
148139
public MultiSelectModel build() {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2016-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.mybatis.dynamic.sql.select;
17+
18+
import org.mybatis.dynamic.sql.util.Buildable;
19+
20+
public interface PagingDSL<T> {
21+
default LimitFinisher<T> limit(long limit) {
22+
return limitWhenPresent(limit);
23+
}
24+
25+
LimitFinisher<T> limitWhenPresent(Long limit);
26+
27+
default OffsetFirstFinisher<T> offset(long offset) {
28+
return offsetWhenPresent(offset);
29+
}
30+
31+
OffsetFirstFinisher<T> offsetWhenPresent(Long offset);
32+
33+
default FetchFirstFinisher<T> fetchFirst(long fetchFirstRows) {
34+
return fetchFirstWhenPresent(fetchFirstRows);
35+
}
36+
37+
FetchFirstFinisher<T> fetchFirstWhenPresent(Long fetchFirstRows);
38+
39+
interface LimitFinisher<T> extends Buildable<T> {
40+
default Buildable<T> offset(long offset) {
41+
return offsetWhenPresent(offset);
42+
}
43+
44+
Buildable<T> offsetWhenPresent(Long offset);
45+
}
46+
47+
interface OffsetFirstFinisher<T> extends Buildable<T> {
48+
default FetchFirstFinisher<T> fetchFirst(long fetchFirstRows) {
49+
return fetchFirstWhenPresent(fetchFirstRows);
50+
}
51+
52+
FetchFirstFinisher<T> fetchFirstWhenPresent(Long fetchFirstRows);
53+
}
54+
55+
interface FetchFirstFinisher<T> {
56+
Buildable<T> rowsOnly();
57+
}
58+
}

0 commit comments

Comments
 (0)