@@ -51,12 +51,31 @@ public class QueryExpressionDSL<R> implements Buildable<R> {
5151 private List <JoinSpecification > joinSpecifications = new ArrayList <>();
5252
5353 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 );
5858 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 ();
6079 }
6180
6281 public <T > QueryExpressionWhereBuilder where (BindableColumn <T > column , VisitableCondition <T > condition ) {
@@ -160,55 +179,58 @@ public SelectDSL<R>.FetchFirstFinisher fetchFirst(long fetchFirstRows) {
160179 }
161180
162181 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 ;
165186 private SqlTable table ;
166187
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 ;
169193 }
170194
171195 public QueryExpressionDSL <R > from (SqlTable table ) {
172196 this .table = table ;
173-
174197 return new QueryExpressionDSL <>(this );
175198 }
176199
177200 public QueryExpressionDSL <R > from (SqlTable table , String tableAlias ) {
178201 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 );
203203 }
204204
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+ }
212234 }
213235 }
214236
@@ -469,19 +491,19 @@ public UnionBuilder(String connector) {
469491 }
470492
471493 public FromGatherer <R > select (BasicColumn ...selectList ) {
472- return new FromGathererBuilder <R >()
494+ return new FromGatherer . Builder <R >()
473495 .withConnector (connector )
474496 .withSelectList (selectList )
475497 .withSelectDSL (selectDSL )
476498 .build ();
477499 }
478500
479501 public FromGatherer <R > selectDistinct (BasicColumn ...selectList ) {
480- return new FromGathererBuilder <R >()
502+ return new FromGatherer . Builder <R >()
481503 .withConnector (connector )
482- .isDistinct ()
483504 .withSelectList (selectList )
484505 .withSelectDSL (selectDSL )
506+ .isDistinct ()
485507 .build ();
486508 }
487509 }
0 commit comments