Skip to content

Commit f385ba4

Browse files
committed
Implement embedded where clauses
This separate the concept of a standalone where clause from a where clause that is a part of another statetment.
1 parent b30958c commit f385ba4

15 files changed

+104
-48
lines changed

src/main/java/org/mybatis/dynamic/sql/common/CommonBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import org.mybatis.dynamic.sql.SqlTable;
1919
import org.mybatis.dynamic.sql.configuration.StatementConfiguration;
20-
import org.mybatis.dynamic.sql.where.WhereModel;
20+
import org.mybatis.dynamic.sql.where.EmbeddedWhereModel;
2121

2222
/**
2323
* Builder class shared between the delete and update model builders.
@@ -27,7 +27,7 @@
2727
public abstract class CommonBuilder<T extends CommonBuilder<T>> {
2828
private SqlTable table;
2929
private String tableAlias;
30-
private WhereModel whereModel;
30+
private EmbeddedWhereModel whereModel;
3131
private Long limit;
3232
private OrderByModel orderByModel;
3333
private StatementConfiguration statementConfiguration;
@@ -40,7 +40,7 @@ public String tableAlias() {
4040
return tableAlias;
4141
}
4242

43-
public WhereModel whereModel() {
43+
public EmbeddedWhereModel whereModel() {
4444
return whereModel;
4545
}
4646

@@ -66,7 +66,7 @@ public T withTableAlias(String tableAlias) {
6666
return getThis();
6767
}
6868

69-
public T withWhereModel(WhereModel whereModel) {
69+
public T withWhereModel(EmbeddedWhereModel whereModel) {
7070
this.whereModel = whereModel;
7171
return getThis();
7272
}

src/main/java/org/mybatis/dynamic/sql/delete/DeleteDSL.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.mybatis.dynamic.sql.util.Utilities;
3131
import org.mybatis.dynamic.sql.where.AbstractWhereFinisher;
3232
import org.mybatis.dynamic.sql.where.AbstractWhereStarter;
33-
import org.mybatis.dynamic.sql.where.WhereModel;
33+
import org.mybatis.dynamic.sql.where.EmbeddedWhereModel;
3434

3535
public class DeleteDSL<R> extends AbstractWhereStarter<DeleteDSL<R>.DeleteWhereBuilder, DeleteDSL<R>>
3636
implements Buildable<R> {
@@ -111,7 +111,7 @@ public static DeleteDSL<DeleteModel> deleteFrom(SqlTable table, String tableAlia
111111
public class DeleteWhereBuilder extends AbstractWhereFinisher<DeleteWhereBuilder> implements Buildable<R> {
112112

113113
private DeleteWhereBuilder() {
114-
super(statementConfiguration);
114+
super(DeleteDSL.this);
115115
}
116116

117117
public DeleteDSL<R> limit(long limit) {
@@ -138,7 +138,7 @@ protected DeleteWhereBuilder getThis() {
138138
return this;
139139
}
140140

141-
protected WhereModel buildWhereModel() {
141+
protected EmbeddedWhereModel buildWhereModel() {
142142
return buildModel();
143143
}
144144
}

src/main/java/org/mybatis/dynamic/sql/delete/DeleteModel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
import org.mybatis.dynamic.sql.delete.render.DeleteRenderer;
2727
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
2828
import org.mybatis.dynamic.sql.render.RenderingStrategy;
29-
import org.mybatis.dynamic.sql.where.WhereModel;
29+
import org.mybatis.dynamic.sql.where.EmbeddedWhereModel;
3030

3131
public class DeleteModel {
3232
private final SqlTable table;
3333
private final String tableAlias;
34-
private final WhereModel whereModel;
34+
private final EmbeddedWhereModel whereModel;
3535
private final Long limit;
3636
private final OrderByModel orderByModel;
3737
private final StatementConfiguration statementConfiguration;
@@ -53,7 +53,7 @@ public Optional<String> tableAlias() {
5353
return Optional.ofNullable(tableAlias);
5454
}
5555

56-
public Optional<WhereModel> whereModel() {
56+
public Optional<EmbeddedWhereModel> whereModel() {
5757
return Optional.ofNullable(whereModel);
5858
}
5959

src/main/java/org/mybatis/dynamic/sql/delete/render/DeleteRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.mybatis.dynamic.sql.render.TableAliasCalculator;
3131
import org.mybatis.dynamic.sql.util.FragmentAndParameters;
3232
import org.mybatis.dynamic.sql.util.FragmentCollector;
33-
import org.mybatis.dynamic.sql.where.WhereModel;
33+
import org.mybatis.dynamic.sql.where.EmbeddedWhereModel;
3434

3535
public class DeleteRenderer {
3636
private final DeleteModel deleteModel;
@@ -75,7 +75,7 @@ private Optional<FragmentAndParameters> calculateWhereClause() {
7575
return deleteModel.whereModel().flatMap(this::renderWhereClause);
7676
}
7777

78-
private Optional<FragmentAndParameters> renderWhereClause(WhereModel whereModel) {
78+
private Optional<FragmentAndParameters> renderWhereClause(EmbeddedWhereModel whereModel) {
7979
return whereModel.render(renderingContext);
8080
}
8181

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.mybatis.dynamic.sql.util.Buildable;
2828
import org.mybatis.dynamic.sql.util.Utilities;
2929
import org.mybatis.dynamic.sql.where.AbstractWhereFinisher;
30-
import org.mybatis.dynamic.sql.where.WhereModel;
30+
import org.mybatis.dynamic.sql.where.EmbeddedWhereModel;
3131

3232
/**
3333
* DSL for building count queries. Count queries are specializations of select queries. They have joins and where
@@ -131,7 +131,7 @@ public CountDSL<R> from(SqlTable table) {
131131
public class CountWhereBuilder extends AbstractWhereFinisher<CountWhereBuilder>
132132
implements Buildable<R> {
133133
private CountWhereBuilder() {
134-
super(statementConfiguration);
134+
super(CountDSL.this);
135135
}
136136

137137
@NotNull
@@ -145,7 +145,7 @@ protected CountWhereBuilder getThis() {
145145
return this;
146146
}
147147

148-
protected WhereModel buildWhereModel() {
148+
protected EmbeddedWhereModel buildWhereModel() {
149149
return super.buildModel();
150150
}
151151
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import org.mybatis.dynamic.sql.util.Utilities;
3939
import org.mybatis.dynamic.sql.where.AbstractWhereFinisher;
4040
import org.mybatis.dynamic.sql.where.AbstractWhereStarter;
41-
import org.mybatis.dynamic.sql.where.WhereModel;
41+
import org.mybatis.dynamic.sql.where.EmbeddedWhereModel;
4242

4343
public class QueryExpressionDSL<R>
4444
extends AbstractQueryExpressionDSL<QueryExpressionDSL<R>.QueryExpressionWhereBuilder, QueryExpressionDSL<R>>
@@ -275,7 +275,7 @@ public FromGatherer<R> build() {
275275
public class QueryExpressionWhereBuilder extends AbstractWhereFinisher<QueryExpressionWhereBuilder>
276276
implements Buildable<R> {
277277
private QueryExpressionWhereBuilder() {
278-
super(selectDSL.statementConfiguration);
278+
super(QueryExpressionDSL.this);
279279
}
280280

281281
public UnionBuilder union() {
@@ -325,7 +325,7 @@ protected QueryExpressionWhereBuilder getThis() {
325325
return this;
326326
}
327327

328-
protected WhereModel buildWhereModel() {
328+
protected EmbeddedWhereModel buildWhereModel() {
329329
return super.buildModel();
330330
}
331331
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.mybatis.dynamic.sql.TableExpression;
3030
import org.mybatis.dynamic.sql.select.join.JoinModel;
3131
import org.mybatis.dynamic.sql.util.Validator;
32-
import org.mybatis.dynamic.sql.where.WhereModel;
32+
import org.mybatis.dynamic.sql.where.EmbeddedWhereModel;
3333

3434
public class QueryExpressionModel {
3535
private final String connector;
@@ -38,7 +38,7 @@ public class QueryExpressionModel {
3838
private final TableExpression table;
3939
private final JoinModel joinModel;
4040
private final Map<SqlTable, String> tableAliases;
41-
private final WhereModel whereModel;
41+
private final EmbeddedWhereModel whereModel;
4242
private final GroupByModel groupByModel;
4343
private final HavingModel havingModel;
4444

@@ -75,7 +75,7 @@ public Map<SqlTable, String> tableAliases() {
7575
return tableAliases;
7676
}
7777

78-
public Optional<WhereModel> whereModel() {
78+
public Optional<EmbeddedWhereModel> whereModel() {
7979
return Optional.ofNullable(whereModel);
8080
}
8181

@@ -101,7 +101,7 @@ public static class Builder {
101101
private final List<BasicColumn> selectList = new ArrayList<>();
102102
private TableExpression table;
103103
private final Map<SqlTable, String> tableAliases = new HashMap<>();
104-
private WhereModel whereModel;
104+
private EmbeddedWhereModel whereModel;
105105
private JoinModel joinModel;
106106
private GroupByModel groupByModel;
107107
private HavingModel havingModel;
@@ -136,7 +136,7 @@ public Builder withTableAliases(Map<SqlTable, String> tableAliases) {
136136
return this;
137137
}
138138

139-
public Builder withWhereModel(WhereModel whereModel) {
139+
public Builder withWhereModel(EmbeddedWhereModel whereModel) {
140140
this.whereModel = whereModel;
141141
return this;
142142
}

src/main/java/org/mybatis/dynamic/sql/select/render/QueryExpressionRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.mybatis.dynamic.sql.util.FragmentAndParameters;
3333
import org.mybatis.dynamic.sql.util.FragmentCollector;
3434
import org.mybatis.dynamic.sql.util.StringUtilities;
35-
import org.mybatis.dynamic.sql.where.WhereModel;
35+
import org.mybatis.dynamic.sql.where.EmbeddedWhereModel;
3636

3737
public class QueryExpressionRenderer {
3838
private final QueryExpressionModel queryExpression;
@@ -166,7 +166,7 @@ private Optional<FragmentAndParameters> calculateWhereClause() {
166166
return queryExpression.whereModel().flatMap(this::renderWhereClause);
167167
}
168168

169-
private Optional<FragmentAndParameters> renderWhereClause(WhereModel whereModel) {
169+
private Optional<FragmentAndParameters> renderWhereClause(EmbeddedWhereModel whereModel) {
170170
return whereModel.render(renderingContext);
171171
}
172172

src/main/java/org/mybatis/dynamic/sql/update/UpdateDSL.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import org.mybatis.dynamic.sql.util.ValueWhenPresentMapping;
4646
import org.mybatis.dynamic.sql.where.AbstractWhereFinisher;
4747
import org.mybatis.dynamic.sql.where.AbstractWhereStarter;
48-
import org.mybatis.dynamic.sql.where.WhereModel;
48+
import org.mybatis.dynamic.sql.where.EmbeddedWhereModel;
4949

5050
public class UpdateDSL<R> extends AbstractWhereStarter<UpdateDSL<R>.UpdateWhereBuilder, UpdateDSL<R>>
5151
implements Buildable<R> {
@@ -192,7 +192,7 @@ public UpdateDSL<R> equalToWhenPresent(Supplier<T> valueSupplier) {
192192
public class UpdateWhereBuilder extends AbstractWhereFinisher<UpdateWhereBuilder> implements Buildable<R> {
193193

194194
private UpdateWhereBuilder() {
195-
super(statementConfiguration);
195+
super(UpdateDSL.this);
196196
}
197197

198198
public UpdateDSL<R> limit(long limit) {
@@ -219,7 +219,7 @@ protected UpdateWhereBuilder getThis() {
219219
return this;
220220
}
221221

222-
protected WhereModel buildWhereModel() {
222+
protected EmbeddedWhereModel buildWhereModel() {
223223
return buildModel();
224224
}
225225
}

src/main/java/org/mybatis/dynamic/sql/update/UpdateModel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
3333
import org.mybatis.dynamic.sql.util.AbstractColumnMapping;
3434
import org.mybatis.dynamic.sql.util.Validator;
35-
import org.mybatis.dynamic.sql.where.WhereModel;
35+
import org.mybatis.dynamic.sql.where.EmbeddedWhereModel;
3636

3737
public class UpdateModel {
3838
private final SqlTable table;
3939
private final String tableAlias;
40-
private final WhereModel whereModel;
40+
private final EmbeddedWhereModel whereModel;
4141
private final List<AbstractColumnMapping> columnMappings;
4242
private final Long limit;
4343
private final OrderByModel orderByModel;
@@ -62,7 +62,7 @@ public Optional<String> tableAlias() {
6262
return Optional.ofNullable(tableAlias);
6363
}
6464

65-
public Optional<WhereModel> whereModel() {
65+
public Optional<EmbeddedWhereModel> whereModel() {
6666
return Optional.ofNullable(whereModel);
6767
}
6868

0 commit comments

Comments
 (0)