@@ -14,17 +14,14 @@ public class SqlStatementSelect extends SqlStatement {
1414 private final SqlOrderBy orderBy ;
1515 private final SqlLimit limit ;
1616
17- public SqlStatementSelect (final SqlNode fromClause , final SqlSelectList selectList , final SqlNode whereClause ,
18- final SqlExpressionList groupBy , final SqlNode having , final SqlOrderBy orderBy , final SqlLimit limit ) {
19- this .fromClause = fromClause ;
20- this .selectList = selectList ;
21- this .whereClause = whereClause ;
22- this .groupBy = groupBy ;
23- this .having = having ;
24- this .orderBy = orderBy ;
25- this .limit = limit ;
26- assert this .fromClause != null ;
27- assert this .selectList != null ;
17+ private SqlStatementSelect (final Builder builder ) {
18+ this .fromClause = builder .fromClause ;
19+ this .selectList = builder .selectList ;
20+ this .whereClause = builder .whereClause ;
21+ this .groupBy = builder .groupBy ;
22+ this .having = builder .having ;
23+ this .orderBy = builder .orderBy ;
24+ this .limit = builder .limit ;
2825 this .fromClause .setParent (this );
2926 this .selectList .setParent (this );
3027
@@ -137,4 +134,112 @@ public SqlNodeType getType() {
137134 public <R > R accept (final SqlNodeVisitor <R > visitor ) throws AdapterException {
138135 return visitor .visit (this );
139136 }
140- }
137+
138+ /**
139+ * Create a new builder for {@link SqlStatementSelect}.
140+ *
141+ * @return builder instance
142+ */
143+ public static Builder builder () {
144+ return new Builder ();
145+ }
146+
147+ /**
148+ * Builder for {@link SqlStatementSelect}.
149+ */
150+ public static class Builder {
151+ private SqlNode fromClause ;
152+ private SqlSelectList selectList ;
153+ private SqlNode whereClause ;
154+ private SqlExpressionList groupBy ;
155+ private SqlNode having ;
156+ private SqlOrderBy orderBy ;
157+ private SqlLimit limit ;
158+
159+ /**
160+ * Set the from clause of the SQL Select Statement.
161+ *
162+ * @param fromClause from clause
163+ * @return builder instance for fluent programming
164+ */
165+ public Builder fromClause (final SqlNode fromClause ) {
166+ this .fromClause = fromClause ;
167+ return this ;
168+ }
169+
170+ /**
171+ * Set the select list of the SQL Select Statement.
172+ *
173+ * @param selectList select list
174+ * @return builder instance for fluent programming
175+ */
176+ public Builder selectList (final SqlSelectList selectList ) {
177+ this .selectList = selectList ;
178+ return this ;
179+ }
180+
181+ /**
182+ * Set the where clause of the SQL Select Statement.
183+ *
184+ * @param whereClause where clause
185+ * @return builder instance for fluent programming
186+ */
187+ public Builder whereClause (final SqlNode whereClause ) {
188+ this .whereClause = whereClause ;
189+ return this ;
190+ }
191+
192+ /**
193+ * Set the group by clause of the SQL Select Statement.
194+ *
195+ * @param groupBy group by clause
196+ * @return builder instance for fluent programming
197+ */
198+ public Builder groupBy (final SqlExpressionList groupBy ) {
199+ this .groupBy = groupBy ;
200+ return this ;
201+ }
202+
203+ /**
204+ * Set the having clause of the SQL Select Statement.
205+ *
206+ * @param having having clause
207+ * @return builder instance for fluent programming
208+ */
209+ public Builder having (final SqlNode having ) {
210+ this .having = having ;
211+ return this ;
212+ }
213+
214+ /**
215+ * Set the order by clause of the SQL Select Statement.
216+ *
217+ * @param orderBy order by clause
218+ * @return builder instance for fluent programming
219+ */
220+ public Builder orderBy (final SqlOrderBy orderBy ) {
221+ this .orderBy = orderBy ;
222+ return this ;
223+ }
224+
225+ /**
226+ * Set the limit clause of the SQL Select Statement.
227+ *
228+ * @param limit limit clause
229+ * @return builder instance for fluent programming
230+ */
231+ public Builder limit (final SqlLimit limit ) {
232+ this .limit = limit ;
233+ return this ;
234+ }
235+
236+ /**
237+ * Build a new instance of {@link SqlStatementSelect}
238+ *
239+ * @return new instance
240+ */
241+ public SqlStatementSelect build () {
242+ return new SqlStatementSelect (this );
243+ }
244+ }
245+ }
0 commit comments