Skip to content

Commit 900587c

Browse files
authored
Merge pull request #1064 from jeffgbutler/deprecate-old-where-stuff
Remove Independently Renderable Where Clauses
2 parents c13e19b + 3a4fff1 commit 900587c

29 files changed

Lines changed: 245 additions & 825 deletions

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ library or in migrating to the new DSLs, please let us know by opening an issue
105105
useful in a variety of circumstances. If you follow the patterns shown on the
106106
[Extending the Library](https://mybatis.org/mybatis-dynamic-sql/docs/extending.html) page, the change should be
107107
limited to changing the private constructor to accept `BasicColumn` rather than `BindableColumn`.
108+
- Remove support for independently renderable where clauses. This was a holdover from the earliest days of building the
109+
library. The idea was to build where clauses that would render and could then be inserted into hand-coded SQL.
110+
As far as I know, this was only used for some internal testing. If you have a use case for this feature, please
111+
let us know and we will revisit this decision.
108112

109113
### Adoption of JSpecify (https://jspecify.dev/)
110114

src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.jspecify.annotations.Nullable;
2525
import org.mybatis.dynamic.sql.delete.DeleteDSL;
2626
import org.mybatis.dynamic.sql.delete.DeleteModel;
27+
import org.mybatis.dynamic.sql.dsl.HavingDSL;
28+
import org.mybatis.dynamic.sql.dsl.WhereDSL;
2729
import org.mybatis.dynamic.sql.insert.BatchInsertDSL;
2830
import org.mybatis.dynamic.sql.insert.GeneralInsertDSL;
2931
import org.mybatis.dynamic.sql.insert.InsertDSL;
@@ -36,7 +38,6 @@
3638
import org.mybatis.dynamic.sql.select.SelectDSL;
3739
import org.mybatis.dynamic.sql.select.SelectModel;
3840
import org.mybatis.dynamic.sql.select.SimpleSortSpecification;
39-
import org.mybatis.dynamic.sql.select.StandaloneHavingBuilder;
4041
import org.mybatis.dynamic.sql.select.aggregate.Avg;
4142
import org.mybatis.dynamic.sql.select.aggregate.Count;
4243
import org.mybatis.dynamic.sql.select.aggregate.CountAll;
@@ -60,7 +61,6 @@
6061
import org.mybatis.dynamic.sql.update.UpdateDSL;
6162
import org.mybatis.dynamic.sql.update.UpdateModel;
6263
import org.mybatis.dynamic.sql.util.Buildable;
63-
import org.mybatis.dynamic.sql.where.StandaloneWhereBuilder;
6464
import org.mybatis.dynamic.sql.where.condition.IsBetween;
6565
import org.mybatis.dynamic.sql.where.condition.IsBetweenWhenPresent;
6666
import org.mybatis.dynamic.sql.where.condition.IsEqualTo;
@@ -262,37 +262,37 @@ static UpdateDSL<UpdateModel> update(SqlTable table, String tableAlias) {
262262
return UpdateDSL.update(table, tableAlias);
263263
}
264264

265-
static StandaloneWhereBuilder where() {
266-
return new StandaloneWhereBuilder();
265+
static WhereDSL where() {
266+
return new WhereDSL();
267267
}
268268

269-
static <T> StandaloneWhereBuilder where(BindableColumn<T> column, RenderableCondition<T> condition,
270-
AndOrCriteriaGroup... subCriteria) {
269+
static <T> WhereDSL where(BindableColumn<T> column, RenderableCondition<T> condition,
270+
AndOrCriteriaGroup... subCriteria) {
271271
ColumnAndConditionCriterion<T> initialCriterion = ColumnAndConditionCriterion.withColumn(column)
272272
.withCondition(condition)
273273
.build();
274274

275275
return where(initialCriterion, subCriteria);
276276
}
277277

278-
static StandaloneWhereBuilder where(SqlCriterion initialCriterion, AndOrCriteriaGroup... subCriteria) {
279-
return new StandaloneWhereBuilder(initialCriterion, Arrays.asList(subCriteria));
278+
static WhereDSL where(SqlCriterion initialCriterion, AndOrCriteriaGroup... subCriteria) {
279+
return new WhereDSL(initialCriterion, Arrays.asList(subCriteria));
280280
}
281281

282-
static StandaloneWhereBuilder where(ExistsPredicate existsPredicate, AndOrCriteriaGroup... subCriteria) {
282+
static WhereDSL where(ExistsPredicate existsPredicate, AndOrCriteriaGroup... subCriteria) {
283283
ExistsCriterion existsCriterion = new ExistsCriterion.Builder()
284284
.withExistsPredicate(existsPredicate).build();
285285
return where(existsCriterion, subCriteria);
286286
}
287287

288-
static <T> StandaloneHavingBuilder having(BindableColumn<T> column, RenderableCondition<T> condition,
289-
AndOrCriteriaGroup... subCriteria) {
288+
static <T> HavingDSL having(BindableColumn<T> column, RenderableCondition<T> condition,
289+
AndOrCriteriaGroup... subCriteria) {
290290
SqlCriterion initialCriterion = ColumnAndConditionCriterion.withColumn(column).withCondition(condition).build();
291291
return having(initialCriterion, subCriteria);
292292
}
293293

294-
static StandaloneHavingBuilder having(SqlCriterion initialCriterion, AndOrCriteriaGroup... subCriteria) {
295-
return new StandaloneHavingBuilder(initialCriterion, Arrays.asList(subCriteria));
294+
static HavingDSL having(SqlCriterion initialCriterion, AndOrCriteriaGroup... subCriteria) {
295+
return new HavingDSL(initialCriterion, Arrays.asList(subCriteria));
296296
}
297297

298298
// where condition connectors

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2025 the original author or authors.
2+
* Copyright 2016-2026 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@
1818
import org.jspecify.annotations.Nullable;
1919
import org.mybatis.dynamic.sql.SqlTable;
2020
import org.mybatis.dynamic.sql.configuration.StatementConfiguration;
21-
import org.mybatis.dynamic.sql.where.EmbeddedWhereModel;
21+
import org.mybatis.dynamic.sql.where.WhereModel;
2222

2323
/**
2424
* Builder class shared between the delete and update model builders.
@@ -28,7 +28,7 @@
2828
public abstract class CommonBuilder<T extends CommonBuilder<T>> {
2929
private @Nullable SqlTable table;
3030
private @Nullable String tableAlias;
31-
private @Nullable EmbeddedWhereModel whereModel;
31+
private @Nullable WhereModel whereModel;
3232
private @Nullable Long limit;
3333
private @Nullable OrderByModel orderByModel;
3434
private @Nullable StatementConfiguration statementConfiguration;
@@ -41,7 +41,7 @@ public abstract class CommonBuilder<T extends CommonBuilder<T>> {
4141
return tableAlias;
4242
}
4343

44-
public @Nullable EmbeddedWhereModel whereModel() {
44+
public @Nullable WhereModel whereModel() {
4545
return whereModel;
4646
}
4747

@@ -67,7 +67,7 @@ public T withTableAlias(@Nullable String tableAlias) {
6767
return getThis();
6868
}
6969

70-
public T withWhereModel(@Nullable EmbeddedWhereModel whereModel) {
70+
public T withWhereModel(@Nullable WhereModel whereModel) {
7171
this.whereModel = whereModel;
7272
return getThis();
7373
}

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

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

3232
public class DeleteModel {
3333
private final SqlTable table;
3434
private final @Nullable String tableAlias;
35-
private final @Nullable EmbeddedWhereModel whereModel;
35+
private final @Nullable WhereModel whereModel;
3636
private final @Nullable Long limit;
3737
private final @Nullable OrderByModel orderByModel;
3838
private final StatementConfiguration statementConfiguration;
@@ -54,7 +54,7 @@ public Optional<String> tableAlias() {
5454
return Optional.ofNullable(tableAlias);
5555
}
5656

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2025 the original author or authors.
2+
* Copyright 2016-2026 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -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.EmbeddedWhereModel;
33+
import org.mybatis.dynamic.sql.where.WhereModel;
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(EmbeddedWhereModel whereModel) {
78+
private Optional<FragmentAndParameters> renderWhereClause(WhereModel whereModel) {
7979
return whereModel.render(renderingContext);
8080
}
8181

src/main/java/org/mybatis/dynamic/sql/dsl/AbstractCountDSL.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
import org.mybatis.dynamic.sql.util.Buildable;
3535
import org.mybatis.dynamic.sql.util.ConfigurableStatement;
3636
import org.mybatis.dynamic.sql.util.Validator;
37-
import org.mybatis.dynamic.sql.where.EmbeddedWhereModel;
3837
import org.mybatis.dynamic.sql.where.WhereApplier;
38+
import org.mybatis.dynamic.sql.where.WhereModel;
3939

4040
/**
4141
* DSL for building count queries. Count queries are specializations of select queries. They have joins and where
@@ -217,8 +217,8 @@ public M build() {
217217
return AbstractCountDSL.this.build();
218218
}
219219

220-
protected EmbeddedWhereModel buildWhereModel() {
221-
return new EmbeddedWhereModel.Builder()
220+
protected WhereModel buildWhereModel() {
221+
return new WhereModel.Builder()
222222
.withInitialCriterion(initialCriterion)
223223
.withSubCriteria(subCriteria)
224224
.build();

src/main/java/org/mybatis/dynamic/sql/dsl/AbstractDeleteDSL.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
import org.mybatis.dynamic.sql.util.Buildable;
3535
import org.mybatis.dynamic.sql.util.ConfigurableStatement;
3636
import org.mybatis.dynamic.sql.util.Validator;
37-
import org.mybatis.dynamic.sql.where.EmbeddedWhereModel;
3837
import org.mybatis.dynamic.sql.where.WhereApplier;
38+
import org.mybatis.dynamic.sql.where.WhereModel;
3939

4040
public abstract class AbstractDeleteDSL<M, D extends AbstractDeleteDSL<M, D>>
4141
implements WhereOperations<AbstractDeleteDSL<M, D>.DeleteWhereBuilder>,
@@ -161,8 +161,8 @@ public M build() {
161161
return AbstractDeleteDSL.this.build();
162162
}
163163

164-
protected EmbeddedWhereModel buildWhereModel() {
165-
return new EmbeddedWhereModel.Builder()
164+
protected WhereModel buildWhereModel() {
165+
return new WhereModel.Builder()
166166
.withInitialCriterion(initialCriterion)
167167
.withSubCriteria(subCriteria)
168168
.build();

src/main/java/org/mybatis/dynamic/sql/dsl/AbstractUpdateDSL.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
import org.mybatis.dynamic.sql.util.ValueMapping;
4848
import org.mybatis.dynamic.sql.util.ValueOrNullMapping;
4949
import org.mybatis.dynamic.sql.util.ValueWhenPresentMapping;
50-
import org.mybatis.dynamic.sql.where.EmbeddedWhereModel;
5150
import org.mybatis.dynamic.sql.where.WhereApplier;
51+
import org.mybatis.dynamic.sql.where.WhereModel;
5252

5353
public abstract class AbstractUpdateDSL<M, D extends AbstractUpdateDSL<M, D>>
5454
implements WhereOperations<AbstractUpdateDSL<M, D>.UpdateWhereBuilder>,
@@ -242,8 +242,8 @@ public M build() {
242242
return AbstractUpdateDSL.this.build();
243243
}
244244

245-
protected EmbeddedWhereModel buildWhereModel() {
246-
return new EmbeddedWhereModel.Builder()
245+
protected WhereModel buildWhereModel() {
246+
return new WhereModel.Builder()
247247
.withInitialCriterion(initialCriterion)
248248
.withSubCriteria(subCriteria)
249249
.build();

src/main/java/org/mybatis/dynamic/sql/select/StandaloneHavingBuilder.java renamed to src/main/java/org/mybatis/dynamic/sql/dsl/HavingDSL.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,30 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.mybatis.dynamic.sql.select;
16+
package org.mybatis.dynamic.sql.dsl;
1717

1818
import java.util.ArrayList;
1919
import java.util.List;
2020

2121
import org.mybatis.dynamic.sql.AndOrCriteriaGroup;
2222
import org.mybatis.dynamic.sql.SqlCriterion;
23-
import org.mybatis.dynamic.sql.dsl.BooleanOperations;
24-
import org.mybatis.dynamic.sql.util.Buildable;
23+
import org.mybatis.dynamic.sql.select.HavingApplier;
2524

26-
public class StandaloneHavingBuilder implements BooleanOperations<StandaloneHavingBuilder>, Buildable<HavingModel> {
25+
public class HavingDSL implements BooleanOperations<HavingDSL> {
2726
private final SqlCriterion initialCriterion;
2827
private final List<AndOrCriteriaGroup> subCriteria = new ArrayList<>();
2928

30-
public StandaloneHavingBuilder(SqlCriterion initialCriterion, List<AndOrCriteriaGroup> subCriteria) {
29+
public HavingDSL(SqlCriterion initialCriterion, List<AndOrCriteriaGroup> subCriteria) {
3130
this.initialCriterion = initialCriterion;
3231
this.subCriteria.addAll(subCriteria);
3332
}
3433

3534
@Override
36-
public StandaloneHavingBuilder addSubCriterion(AndOrCriteriaGroup subCriterion) {
35+
public HavingDSL addSubCriterion(AndOrCriteriaGroup subCriterion) {
3736
subCriteria.add(subCriterion);
3837
return this;
3938
}
4039

41-
@Override
42-
public HavingModel build() {
43-
return new HavingModel.Builder()
44-
.withInitialCriterion(initialCriterion)
45-
.withSubCriteria(subCriteria)
46-
.build();
47-
}
48-
4940
public HavingApplier toHavingApplier() {
5041
return new HavingApplier(initialCriterion, subCriteria);
5142
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
import org.mybatis.dynamic.sql.util.Buildable;
4343
import org.mybatis.dynamic.sql.util.ConfigurableStatement;
4444
import org.mybatis.dynamic.sql.util.Validator;
45-
import org.mybatis.dynamic.sql.where.EmbeddedWhereModel;
4645
import org.mybatis.dynamic.sql.where.WhereApplier;
46+
import org.mybatis.dynamic.sql.where.WhereModel;
4747

4848
public class SelectDSL implements
4949
JoinOperations<SelectDSL.JoinSpecificationFinisher>,
@@ -303,8 +303,8 @@ public SelectModel build() {
303303
return SelectDSL.this.build();
304304
}
305305

306-
protected EmbeddedWhereModel buildWhereModel() {
307-
return new EmbeddedWhereModel.Builder()
306+
protected WhereModel buildWhereModel() {
307+
return new WhereModel.Builder()
308308
.withInitialCriterion(initialCriterion)
309309
.withSubCriteria(subCriteria)
310310
.build();

0 commit comments

Comments
 (0)