@@ -53,15 +53,34 @@ public class QueryExpressionDSL<R> implements Buildable<R> {
53
53
private Supplier <R > buildDelegateMethod ;
54
54
55
55
private QueryExpressionDSL (FromGatherer <R > fromGatherer ) {
56
- connector = fromGatherer .builder . connector ;
57
- selectList = Arrays .asList (fromGatherer .builder . selectList );
58
- isDistinct = fromGatherer .builder . isDistinct ;
59
- selectDSL = Objects .requireNonNull (fromGatherer .builder . selectDSL );
56
+ connector = fromGatherer .connector ;
57
+ selectList = Arrays .asList (fromGatherer .selectList );
58
+ isDistinct = fromGatherer .isDistinct ;
59
+ selectDSL = Objects .requireNonNull (fromGatherer .selectDSL );
60
60
table = Objects .requireNonNull (fromGatherer .table );
61
- tableAliases .putAll (fromGatherer .tableAliasMap );
62
61
buildDelegateMethod = this ::internalBuild ;
63
62
}
64
63
64
+ private QueryExpressionDSL (FromGatherer <R > fromGatherer , String tableAlias ) {
65
+ this (fromGatherer );
66
+ tableAliases .put (table , tableAlias );
67
+ }
68
+
69
+ public static <R > FromGatherer <R > select (SelectDSL <R > selectDSL , BasicColumn ...selectList ) {
70
+ return new FromGatherer .Builder <R >()
71
+ .withSelectList (selectList )
72
+ .withSelectDSL (selectDSL )
73
+ .build ();
74
+ }
75
+
76
+ public static <R > FromGatherer <R > selectDistinct (SelectDSL <R > selectDSL , BasicColumn ...selectList ) {
77
+ return new FromGatherer .Builder <R >()
78
+ .withSelectList (selectList )
79
+ .withSelectDSL (selectDSL )
80
+ .isDistinct ()
81
+ .build ();
82
+ }
83
+
65
84
public <T > QueryExpressionWhereBuilder where (BindableColumn <T > column , VisitableCondition <T > condition ) {
66
85
return new QueryExpressionWhereBuilder (column , condition );
67
86
}
@@ -171,55 +190,58 @@ public SelectDSL<R>.FetchFirstFinisher fetchFirst(long fetchFirstRows) {
171
190
}
172
191
173
192
public static class FromGatherer <R > {
174
- private FromGathererBuilder <R > builder ;
175
- private Map <SqlTable , String > tableAliasMap = new HashMap <>();
193
+ private String connector ;
194
+ private BasicColumn [] selectList ;
195
+ private SelectDSL <R > selectDSL ;
196
+ private boolean isDistinct ;
176
197
private SqlTable table ;
177
198
178
- public FromGatherer (FromGathererBuilder <R > builder ) {
179
- this .builder = builder ;
199
+ public FromGatherer (Builder <R > builder ) {
200
+ this .connector = builder .connector ;
201
+ this .selectList = Objects .requireNonNull (builder .selectList );
202
+ this .selectDSL = Objects .requireNonNull (builder .selectDSL );
203
+ this .isDistinct = builder .isDistinct ;
180
204
}
181
205
182
206
public QueryExpressionDSL <R > from (SqlTable table ) {
183
207
this .table = table ;
184
-
185
208
return new QueryExpressionDSL <>(this );
186
209
}
187
210
188
211
public QueryExpressionDSL <R > from (SqlTable table , String tableAlias ) {
189
212
this .table = table ;
190
- tableAliasMap .put (table , tableAlias );
191
- return new QueryExpressionDSL <>(this );
192
- }
193
- }
194
-
195
- public static class FromGathererBuilder <R > {
196
- private String connector ;
197
- private BasicColumn [] selectList ;
198
- private SelectDSL <R > selectDSL ;
199
- private boolean isDistinct ;
200
-
201
- public FromGathererBuilder <R > withConnector (String connector ) {
202
- this .connector = connector ;
203
- return this ;
204
- }
205
-
206
- public FromGathererBuilder <R > withSelectList (BasicColumn [] selectList ) {
207
- this .selectList = selectList ;
208
- return this ;
209
- }
210
-
211
- public FromGathererBuilder <R > withSelectDSL (SelectDSL <R > selectDSL ) {
212
- this .selectDSL = selectDSL ;
213
- return this ;
213
+ return new QueryExpressionDSL <>(this , tableAlias );
214
214
}
215
215
216
- public FromGathererBuilder <R > isDistinct () {
217
- this .isDistinct = true ;
218
- return this ;
219
- }
220
-
221
- public FromGatherer <R > build () {
222
- return new FromGatherer <>(this );
216
+ public static class Builder <R > {
217
+ private String connector ;
218
+ private BasicColumn [] selectList ;
219
+ private SelectDSL <R > selectDSL ;
220
+ private boolean isDistinct ;
221
+
222
+ public Builder <R > withConnector (String connector ) {
223
+ this .connector = connector ;
224
+ return this ;
225
+ }
226
+
227
+ public Builder <R > withSelectList (BasicColumn [] selectList ) {
228
+ this .selectList = selectList ;
229
+ return this ;
230
+ }
231
+
232
+ public Builder <R > withSelectDSL (SelectDSL <R > selectDSL ) {
233
+ this .selectDSL = selectDSL ;
234
+ return this ;
235
+ }
236
+
237
+ public Builder <R > isDistinct () {
238
+ this .isDistinct = true ;
239
+ return this ;
240
+ }
241
+
242
+ public FromGatherer <R > build () {
243
+ return new FromGatherer <>(this );
244
+ }
223
245
}
224
246
}
225
247
@@ -509,19 +531,19 @@ public UnionBuilder(String connector) {
509
531
}
510
532
511
533
public FromGatherer <R > select (BasicColumn ...selectList ) {
512
- return new FromGathererBuilder <R >()
534
+ return new FromGatherer . Builder <R >()
513
535
.withConnector (connector )
514
536
.withSelectList (selectList )
515
537
.withSelectDSL (selectDSL )
516
538
.build ();
517
539
}
518
540
519
541
public FromGatherer <R > selectDistinct (BasicColumn ...selectList ) {
520
- return new FromGathererBuilder <R >()
542
+ return new FromGatherer . Builder <R >()
521
543
.withConnector (connector )
522
- .isDistinct ()
523
544
.withSelectList (selectList )
524
545
.withSelectDSL (selectDSL )
546
+ .isDistinct ()
525
547
.build ();
526
548
}
527
549
}
0 commit comments