@@ -51,12 +51,31 @@ public class QueryExpressionDSL<R> implements Buildable<R> {
51
51
private List <JoinSpecification > joinSpecifications = new ArrayList <>();
52
52
53
53
private QueryExpressionDSL (FromGatherer <R > fromGatherer ) {
54
- connector = fromGatherer .builder . connector ;
55
- selectList = Arrays .asList (fromGatherer .builder . selectList );
56
- isDistinct = fromGatherer .builder . isDistinct ;
57
- selectDSL = Objects .requireNonNull (fromGatherer .builder . selectDSL );
54
+ connector = fromGatherer .connector ;
55
+ selectList = Arrays .asList (fromGatherer .selectList );
56
+ isDistinct = fromGatherer .isDistinct ;
57
+ selectDSL = Objects .requireNonNull (fromGatherer .selectDSL );
58
58
table = Objects .requireNonNull (fromGatherer .table );
59
- tableAliases .putAll (fromGatherer .tableAliasMap );
59
+ }
60
+
61
+ private QueryExpressionDSL (FromGatherer <R > fromGatherer , String tableAlias ) {
62
+ this (fromGatherer );
63
+ tableAliases .put (table , tableAlias );
64
+ }
65
+
66
+ public static <R > FromGatherer <R > select (SelectDSL <R > selectDSL , BasicColumn ...selectList ) {
67
+ return new FromGatherer .Builder <R >()
68
+ .withSelectList (selectList )
69
+ .withSelectDSL (selectDSL )
70
+ .build ();
71
+ }
72
+
73
+ public static <R > FromGatherer <R > selectDistinct (SelectDSL <R > selectDSL , BasicColumn ...selectList ) {
74
+ return new FromGatherer .Builder <R >()
75
+ .withSelectList (selectList )
76
+ .withSelectDSL (selectDSL )
77
+ .isDistinct ()
78
+ .build ();
60
79
}
61
80
62
81
public <T > QueryExpressionWhereBuilder where (BindableColumn <T > column , VisitableCondition <T > condition ) {
@@ -160,55 +179,58 @@ public SelectDSL<R>.FetchFirstFinisher fetchFirst(long fetchFirstRows) {
160
179
}
161
180
162
181
public static class FromGatherer <R > {
163
- private FromGathererBuilder <R > builder ;
164
- private Map <SqlTable , String > tableAliasMap = new HashMap <>();
182
+ private String connector ;
183
+ private BasicColumn [] selectList ;
184
+ private SelectDSL <R > selectDSL ;
185
+ private boolean isDistinct ;
165
186
private SqlTable table ;
166
187
167
- public FromGatherer (FromGathererBuilder <R > builder ) {
168
- this .builder = builder ;
188
+ public FromGatherer (Builder <R > builder ) {
189
+ this .connector = builder .connector ;
190
+ this .selectList = Objects .requireNonNull (builder .selectList );
191
+ this .selectDSL = Objects .requireNonNull (builder .selectDSL );
192
+ this .isDistinct = builder .isDistinct ;
169
193
}
170
194
171
195
public QueryExpressionDSL <R > from (SqlTable table ) {
172
196
this .table = table ;
173
-
174
197
return new QueryExpressionDSL <>(this );
175
198
}
176
199
177
200
public QueryExpressionDSL <R > from (SqlTable table , String tableAlias ) {
178
201
this .table = table ;
179
- tableAliasMap .put (table , tableAlias );
180
- return new QueryExpressionDSL <>(this );
181
- }
182
- }
183
-
184
- public static class FromGathererBuilder <R > {
185
- private String connector ;
186
- private BasicColumn [] selectList ;
187
- private SelectDSL <R > selectDSL ;
188
- private boolean isDistinct ;
189
-
190
- public FromGathererBuilder <R > withConnector (String connector ) {
191
- this .connector = connector ;
192
- return this ;
193
- }
194
-
195
- public FromGathererBuilder <R > withSelectList (BasicColumn [] selectList ) {
196
- this .selectList = selectList ;
197
- return this ;
198
- }
199
-
200
- public FromGathererBuilder <R > withSelectDSL (SelectDSL <R > selectDSL ) {
201
- this .selectDSL = selectDSL ;
202
- return this ;
202
+ return new QueryExpressionDSL <>(this , tableAlias );
203
203
}
204
204
205
- public FromGathererBuilder <R > isDistinct () {
206
- this .isDistinct = true ;
207
- return this ;
208
- }
209
-
210
- public FromGatherer <R > build () {
211
- return new FromGatherer <>(this );
205
+ public static class Builder <R > {
206
+ private String connector ;
207
+ private BasicColumn [] selectList ;
208
+ private SelectDSL <R > selectDSL ;
209
+ private boolean isDistinct ;
210
+
211
+ public Builder <R > withConnector (String connector ) {
212
+ this .connector = connector ;
213
+ return this ;
214
+ }
215
+
216
+ public Builder <R > withSelectList (BasicColumn [] selectList ) {
217
+ this .selectList = selectList ;
218
+ return this ;
219
+ }
220
+
221
+ public Builder <R > withSelectDSL (SelectDSL <R > selectDSL ) {
222
+ this .selectDSL = selectDSL ;
223
+ return this ;
224
+ }
225
+
226
+ public Builder <R > isDistinct () {
227
+ this .isDistinct = true ;
228
+ return this ;
229
+ }
230
+
231
+ public FromGatherer <R > build () {
232
+ return new FromGatherer <>(this );
233
+ }
212
234
}
213
235
}
214
236
@@ -469,19 +491,19 @@ public UnionBuilder(String connector) {
469
491
}
470
492
471
493
public FromGatherer <R > select (BasicColumn ...selectList ) {
472
- return new FromGathererBuilder <R >()
494
+ return new FromGatherer . Builder <R >()
473
495
.withConnector (connector )
474
496
.withSelectList (selectList )
475
497
.withSelectDSL (selectDSL )
476
498
.build ();
477
499
}
478
500
479
501
public FromGatherer <R > selectDistinct (BasicColumn ...selectList ) {
480
- return new FromGathererBuilder <R >()
502
+ return new FromGatherer . Builder <R >()
481
503
.withConnector (connector )
482
- .isDistinct ()
483
504
.withSelectList (selectList )
484
505
.withSelectDSL (selectDSL )
506
+ .isDistinct ()
485
507
.build ();
486
508
}
487
509
}
0 commit comments