Skip to content

Commit 066c1c5

Browse files
committed
Remove PagingDSL - no longer needed
1 parent aefb115 commit 066c1c5

File tree

6 files changed

+209
-143
lines changed

6 files changed

+209
-143
lines changed

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

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
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>,
33-
PagingDSL<MultiSelectModel> {
32+
public class MultiSelectDSL implements Buildable<MultiSelectModel>, ConfigurableStatement<MultiSelectDSL> {
3433
private final List<UnionQuery> unionQueries = new ArrayList<>();
3534
private final SelectModel initialSelect;
3635
private @Nullable OrderByModel orderByModel;
@@ -62,22 +61,31 @@ public MultiSelectDSL orderBy(Collection<? extends SortSpecification> columns) {
6261
return this;
6362
}
6463

65-
@Override
66-
public LimitFinisher<MultiSelectModel> limitWhenPresent(@Nullable Long limit) {
64+
public LimitFinisher limit(long limit) {
65+
return limitWhenPresent(limit);
66+
}
67+
68+
public LimitFinisher limitWhenPresent(@Nullable Long limit) {
6769
this.limit = limit;
68-
return new LocalLimitFinisher();
70+
return new LimitFinisher();
6971
}
7072

71-
@Override
72-
public OffsetFirstFinisher<MultiSelectModel> offsetWhenPresent(@Nullable Long offset) {
73+
public OffsetFirstFinisher offset(long offset) {
74+
return offsetWhenPresent(offset);
75+
}
76+
77+
public OffsetFirstFinisher offsetWhenPresent(@Nullable Long offset) {
7378
this.offset = offset;
74-
return new LocalOffsetFirstFinisher();
79+
return new OffsetFirstFinisher();
7580
}
7681

77-
@Override
78-
public FetchFirstFinisher<MultiSelectModel> fetchFirstWhenPresent(@Nullable Long fetchFirstRows) {
82+
public FetchFirstFinisher fetchFirst(long fetchFirstRows) {
83+
return fetchFirstWhenPresent(fetchFirstRows);
84+
}
85+
86+
public FetchFirstFinisher fetchFirstWhenPresent(@Nullable Long fetchFirstRows) {
7987
this.fetchFirstRows = fetchFirstRows;
80-
return () -> this;
88+
return new FetchFirstFinisher();
8189
}
8290

8391
@Override
@@ -105,25 +113,40 @@ public MultiSelectDSL configureStatement(Consumer<StatementConfiguration> consum
105113
return this;
106114
}
107115

108-
abstract class BaseBuildable implements Buildable<MultiSelectModel> {
116+
public class OffsetFirstFinisher implements Buildable<MultiSelectModel> {
117+
public FetchFirstFinisher fetchFirst(long fetchFirstRows) {
118+
return fetchFirstWhenPresent(fetchFirstRows);
119+
}
120+
121+
public FetchFirstFinisher fetchFirstWhenPresent(@Nullable Long fetchFirstRows) {
122+
MultiSelectDSL.this.fetchFirstRows = fetchFirstRows;
123+
return new FetchFirstFinisher();
124+
}
125+
109126
@Override
110127
public MultiSelectModel build() {
111128
return MultiSelectDSL.this.build();
112129
}
113130
}
114131

115-
class LocalOffsetFirstFinisher extends BaseBuildable implements OffsetFirstFinisher<MultiSelectModel> {
132+
public class LimitFinisher implements Buildable<MultiSelectModel> {
133+
public MultiSelectDSL offset(long offset) {
134+
return offsetWhenPresent(offset);
135+
}
136+
137+
public MultiSelectDSL offsetWhenPresent(@Nullable Long offset) {
138+
MultiSelectDSL.this.offset = offset;
139+
return MultiSelectDSL.this;
140+
}
141+
116142
@Override
117-
public FetchFirstFinisher<MultiSelectModel> fetchFirstWhenPresent(Long fetchFirstRows) {
118-
MultiSelectDSL.this.fetchFirstRows = fetchFirstRows;
119-
return () -> MultiSelectDSL.this;
143+
public MultiSelectModel build() {
144+
return MultiSelectDSL.this.build();
120145
}
121146
}
122147

123-
class LocalLimitFinisher extends BaseBuildable implements LimitFinisher<MultiSelectModel> {
124-
@Override
125-
public Buildable<MultiSelectModel> offsetWhenPresent(Long offset) {
126-
MultiSelectDSL.this.offset = offset;
148+
public class FetchFirstFinisher {
149+
public MultiSelectDSL rowsOnly() {
127150
return MultiSelectDSL.this;
128151
}
129152
}

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

Lines changed: 0 additions & 59 deletions
This file was deleted.

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

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* @param <R>
4343
* the type of model produced by this builder, typically SelectModel
4444
*/
45-
public class SelectDSL<R> implements Buildable<R>, ConfigurableStatement<SelectDSL<R>>, PagingDSL<R> {
45+
public class SelectDSL<R> implements Buildable<R>, ConfigurableStatement<SelectDSL<R>> {
4646

4747
private final Function<SelectModel, R> adapterFunction;
4848
private final List<QueryExpressionDSL<R>> queryExpressions = new ArrayList<>();
@@ -110,19 +110,31 @@ void orderBy(Collection<? extends SortSpecification> columns) {
110110
orderByModel = OrderByModel.of(columns);
111111
}
112112

113-
public LimitFinisher<R> limitWhenPresent(@Nullable Long limit) {
113+
public LimitFinisher limit(long limit) {
114+
return limitWhenPresent(limit);
115+
}
116+
117+
public LimitFinisher limitWhenPresent(@Nullable Long limit) {
114118
this.limit = limit;
115-
return new LocalLimitFinisher();
119+
return new LimitFinisher();
120+
}
121+
122+
public OffsetFirstFinisher offset(long offset) {
123+
return offsetWhenPresent(offset);
116124
}
117125

118-
public OffsetFirstFinisher<R> offsetWhenPresent(@Nullable Long offset) {
126+
public OffsetFirstFinisher offsetWhenPresent(@Nullable Long offset) {
119127
this.offset = offset;
120-
return new LocalOffsetFirstFinisher();
128+
return new OffsetFirstFinisher();
121129
}
122130

123-
public FetchFirstFinisher<R> fetchFirstWhenPresent(@Nullable Long fetchFirstRows) {
131+
public FetchFirstFinisher fetchFirst(long fetchFirstRows) {
132+
return fetchFirstWhenPresent(fetchFirstRows);
133+
}
134+
135+
public FetchFirstFinisher fetchFirstWhenPresent(@Nullable Long fetchFirstRows) {
124136
this.fetchFirstRows = fetchFirstRows;
125-
return () -> this;
137+
return new FetchFirstFinisher();
126138
}
127139

128140
public SelectDSL<R> forUpdate() {
@@ -193,25 +205,50 @@ private Optional<PagingModel> buildPagingModel() {
193205
.build();
194206
}
195207

196-
abstract class BaseBuildable implements Buildable<R> {
208+
public class OffsetFirstFinisher implements SelectDSLForAndWaitOperations<R>, Buildable<R> {
209+
public FetchFirstFinisher fetchFirst(long fetchFirstRows) {
210+
return fetchFirstWhenPresent(fetchFirstRows);
211+
}
212+
213+
public FetchFirstFinisher fetchFirstWhenPresent(@Nullable Long fetchFirstRows) {
214+
SelectDSL.this.fetchFirstRows = fetchFirstRows;
215+
return new FetchFirstFinisher();
216+
}
217+
218+
@Override
219+
public SelectDSL<R> getSelectDSL() {
220+
return SelectDSL.this;
221+
}
222+
197223
@Override
198224
public R build() {
199225
return SelectDSL.this.build();
200226
}
201227
}
202228

203-
class LocalOffsetFirstFinisher extends BaseBuildable implements OffsetFirstFinisher<R> {
229+
public class LimitFinisher implements SelectDSLForAndWaitOperations<R>, Buildable<R> {
230+
public SelectDSL<R> offset(long offset) {
231+
return offsetWhenPresent(offset);
232+
}
233+
234+
public SelectDSL<R> offsetWhenPresent(@Nullable Long offset) {
235+
SelectDSL.this.offset = offset;
236+
return SelectDSL.this;
237+
}
238+
204239
@Override
205-
public FetchFirstFinisher<R> fetchFirstWhenPresent(Long fetchFirstRows) {
206-
SelectDSL.this.fetchFirstRows = fetchFirstRows;
207-
return () -> SelectDSL.this;
240+
public SelectDSL<R> getSelectDSL() {
241+
return SelectDSL.this;
208242
}
209-
}
210243

211-
class LocalLimitFinisher extends BaseBuildable implements LimitFinisher<R> {
212244
@Override
213-
public Buildable<R> offsetWhenPresent(Long offset) {
214-
SelectDSL.this.offset = offset;
245+
public R build() {
246+
return SelectDSL.this.build();
247+
}
248+
}
249+
250+
public class FetchFirstFinisher {
251+
public SelectDSL<R> rowsOnly() {
215252
return SelectDSL.this;
216253
}
217254
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2016-2025 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+
public interface SelectDSLForAndWaitOperations<R> {
19+
default SelectDSL<R> forUpdate() {
20+
return getSelectDSL().forUpdate();
21+
}
22+
23+
default SelectDSL<R> forNoKeyUpdate() {
24+
return getSelectDSL().forNoKeyUpdate();
25+
}
26+
27+
default SelectDSL<R> forShare() {
28+
return getSelectDSL().forShare();
29+
}
30+
31+
default SelectDSL<R> forKeyShare() {
32+
return getSelectDSL().forKeyShare();
33+
}
34+
35+
default SelectDSL<R> skipLocked() {
36+
return getSelectDSL().skipLocked();
37+
}
38+
39+
default SelectDSL<R> nowait() {
40+
return getSelectDSL().nowait();
41+
}
42+
43+
/**
44+
* Gain access to the SelectDSL instance.
45+
*
46+
* <p>This is a leak of an implementation detail into the public API. The tradeoff is that it
47+
* significantly reduces copy/paste code of SelectDSL methods into all the different inner classes of
48+
* QueryExpressionDSL where they would be needed.
49+
*
50+
* @return the SelectDSL instance associated with this interface instance
51+
*/
52+
SelectDSL<R> getSelectDSL();
53+
}

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

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,63 +17,28 @@
1717

1818
import org.jspecify.annotations.Nullable;
1919

20-
public interface SelectDSLOperations<R> {
21-
default PagingDSL.LimitFinisher<R> limit(long limit) {
20+
public interface SelectDSLOperations<R> extends SelectDSLForAndWaitOperations<R> {
21+
default SelectDSL<R>.LimitFinisher limit(long limit) {
2222
return getSelectDSL().limit(limit);
2323
}
2424

25-
default PagingDSL.LimitFinisher<R> limitWhenPresent(@Nullable Long limit) {
25+
default SelectDSL<R>.LimitFinisher limitWhenPresent(@Nullable Long limit) {
2626
return getSelectDSL().limitWhenPresent(limit);
2727
}
2828

29-
default PagingDSL.OffsetFirstFinisher<R> offset(long offset) {
29+
default SelectDSL<R>.OffsetFirstFinisher offset(long offset) {
3030
return getSelectDSL().offset(offset);
3131
}
3232

33-
default PagingDSL.OffsetFirstFinisher<R> offsetWhenPresent(@Nullable Long offset) {
33+
default SelectDSL<R>.OffsetFirstFinisher offsetWhenPresent(@Nullable Long offset) {
3434
return getSelectDSL().offsetWhenPresent(offset);
3535
}
3636

37-
default PagingDSL.FetchFirstFinisher<R> fetchFirst(long fetchFirstRows) {
37+
default SelectDSL<R>.FetchFirstFinisher fetchFirst(long fetchFirstRows) {
3838
return getSelectDSL().fetchFirst(fetchFirstRows);
3939
}
4040

41-
default PagingDSL.FetchFirstFinisher<R> fetchFirstWhenPresent(@Nullable Long fetchFirstRows) {
41+
default SelectDSL<R>.FetchFirstFinisher fetchFirstWhenPresent(@Nullable Long fetchFirstRows) {
4242
return getSelectDSL().fetchFirstWhenPresent(fetchFirstRows);
4343
}
44-
45-
default SelectDSL<R> forUpdate() {
46-
return getSelectDSL().forUpdate();
47-
}
48-
49-
default SelectDSL<R> forNoKeyUpdate() {
50-
return getSelectDSL().forNoKeyUpdate();
51-
}
52-
53-
default SelectDSL<R> forShare() {
54-
return getSelectDSL().forShare();
55-
}
56-
57-
default SelectDSL<R> forKeyShare() {
58-
return getSelectDSL().forKeyShare();
59-
}
60-
61-
default SelectDSL<R> skipLocked() {
62-
return getSelectDSL().skipLocked();
63-
}
64-
65-
default SelectDSL<R> nowait() {
66-
return getSelectDSL().nowait();
67-
}
68-
69-
/**
70-
* Gain access to the SelectDSL instance.
71-
*
72-
* <p>This is a leak of an implementation detail into the public API. The tradeoff is that it
73-
* significantly reduces copy/paste code of SelectDSL methods into all the different inner classes of
74-
* QueryExpressionDSL where they would be needed.
75-
*
76-
* @return the SelectDSL instance associated with this interface instance
77-
*/
78-
SelectDSL<R> getSelectDSL();
7944
}

0 commit comments

Comments
 (0)