Skip to content

Commit aaf9cd8

Browse files
committed
Merge branch 'master' into gh-100
Conflicts: src/main/java/org/mybatis/dynamic/sql/select/QueryExpressionDSL.java src/main/java/org/mybatis/dynamic/sql/select/SelectDSL.java
2 parents 005fc68 + 319396c commit aaf9cd8

File tree

2 files changed

+70
-63
lines changed

2 files changed

+70
-63
lines changed

src/main/java/org/mybatis/dynamic/sql/select/QueryExpressionDSL.java

Lines changed: 66 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/main/java/org/mybatis/dynamic/sql/select/SelectDSL.java

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,14 @@ private SelectDSL(Function<SelectModel, R> adapterFunction) {
4545
buildDelegateMethod = this::internalBuild;
4646
}
4747

48-
private QueryExpressionDSL.FromGatherer<R> queryExpressionBuilder(BasicColumn...selectList) {
49-
return new QueryExpressionDSL.FromGathererBuilder<R>()
50-
.withSelectDSL(this)
51-
.withSelectList(selectList)
52-
.build();
53-
}
54-
55-
private QueryExpressionDSL.FromGatherer<R> distinctQueryExpressionBuilder(BasicColumn...selectList) {
56-
return new QueryExpressionDSL.FromGathererBuilder<R>()
57-
.withSelectDSL(this)
58-
.withSelectList(selectList)
59-
.isDistinct()
60-
.build();
61-
}
62-
6348
public static QueryExpressionDSL.FromGatherer<SelectModel> select(BasicColumn...selectList) {
6449
return select(Function.identity(), selectList);
6550
}
6651

6752
public static <R> QueryExpressionDSL.FromGatherer<R> select(Function<SelectModel, R> adapterFunction,
6853
BasicColumn...selectList) {
69-
SelectDSL<R> selectModelBuilder = new SelectDSL<>(adapterFunction);
70-
return selectModelBuilder.queryExpressionBuilder(selectList);
54+
SelectDSL<R> selectDSL = new SelectDSL<>(adapterFunction);
55+
return QueryExpressionDSL.select(selectDSL, selectList);
7156
}
7257

7358
public static QueryExpressionDSL.FromGatherer<SelectModel> selectDistinct(BasicColumn...selectList) {
@@ -76,8 +61,8 @@ public static QueryExpressionDSL.FromGatherer<SelectModel> selectDistinct(BasicC
7661

7762
public static <R> QueryExpressionDSL.FromGatherer<R> selectDistinct(Function<SelectModel, R> adapterFunction,
7863
BasicColumn...selectList) {
79-
SelectDSL<R> selectModelBuilder = new SelectDSL<>(adapterFunction);
80-
return selectModelBuilder.distinctQueryExpressionBuilder(selectList);
64+
SelectDSL<R> selectDSL = new SelectDSL<>(adapterFunction);
65+
return QueryExpressionDSL.selectDistinct(selectDSL, selectList);
8166
}
8267

8368
public static <T> QueryExpressionDSL.FromGatherer<MyBatis3SelectModelAdapter<T>> selectWithMapper(

0 commit comments

Comments
 (0)