@@ -53,15 +53,34 @@ public class QueryExpressionDSL<R> implements Buildable<R> {
5353 private Supplier <R > buildDelegateMethod ;
5454
5555 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 );
6060 table = Objects .requireNonNull (fromGatherer .table );
61- tableAliases .putAll (fromGatherer .tableAliasMap );
6261 buildDelegateMethod = this ::internalBuild ;
6362 }
6463
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+
6584 public <T > QueryExpressionWhereBuilder where (BindableColumn <T > column , VisitableCondition <T > condition ) {
6685 return new QueryExpressionWhereBuilder (column , condition );
6786 }
@@ -171,55 +190,58 @@ public SelectDSL<R>.FetchFirstFinisher fetchFirst(long fetchFirstRows) {
171190 }
172191
173192 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 ;
176197 private SqlTable table ;
177198
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 ;
180204 }
181205
182206 public QueryExpressionDSL <R > from (SqlTable table ) {
183207 this .table = table ;
184-
185208 return new QueryExpressionDSL <>(this );
186209 }
187210
188211 public QueryExpressionDSL <R > from (SqlTable table , String tableAlias ) {
189212 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 );
214214 }
215215
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+ }
223245 }
224246 }
225247
@@ -509,19 +531,19 @@ public UnionBuilder(String connector) {
509531 }
510532
511533 public FromGatherer <R > select (BasicColumn ...selectList ) {
512- return new FromGathererBuilder <R >()
534+ return new FromGatherer . Builder <R >()
513535 .withConnector (connector )
514536 .withSelectList (selectList )
515537 .withSelectDSL (selectDSL )
516538 .build ();
517539 }
518540
519541 public FromGatherer <R > selectDistinct (BasicColumn ...selectList ) {
520- return new FromGathererBuilder <R >()
542+ return new FromGatherer . Builder <R >()
521543 .withConnector (connector )
522- .isDistinct ()
523544 .withSelectList (selectList )
524545 .withSelectDSL (selectDSL )
546+ .isDistinct ()
525547 .build ();
526548 }
527549 }
0 commit comments