Skip to content

Commit 970d936

Browse files
authored
Merge pull request #826 from jeffgbutler/remove-deprecated-code
Remove deprecated code
2 parents bb60c74 + a602206 commit 970d936

25 files changed

+29
-779
lines changed

Diff for: CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ This log will detail notable changes to MyBatis Dynamic SQL. Full details are av
44

55
## Release 2.0.0 - Unreleased
66

7-
The library now requires Java 17.
7+
Significant changes:
8+
9+
- The library now requires Java 17
10+
- Deprecated code from prior releases is removed
811

912
## Release 1.5.2 - June 3, 2024
1013

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ The library test cases provide several complete examples of using the library in
8080

8181
## Requirements
8282

83-
The library has no dependencies. Version 2.x requires Java 17. Version 1.8 requires Java 8.
83+
The library has no dependencies. Version 2.x requires Java 17. Version 1.x requires Java 8.

Diff for: src/main/java/org/mybatis/dynamic/sql/AliasableSqlTable.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected AliasableSqlTable(String tableName, Supplier<T> constructor) {
3232
public T withAlias(String alias) {
3333
T newTable = constructor.get();
3434
((AliasableSqlTable<T>) newTable).tableAlias = alias;
35-
newTable.nameSupplier = nameSupplier;
35+
newTable.tableName = tableName;
3636
return newTable;
3737
}
3838

@@ -48,7 +48,7 @@ public T withName(String name) {
4848
Objects.requireNonNull(name);
4949
T newTable = constructor.get();
5050
((AliasableSqlTable<T>) newTable).tableAlias = tableAlias;
51-
newTable.nameSupplier = () -> name;
51+
newTable.tableName = name;
5252
return newTable;
5353
}
5454

Diff for: src/main/java/org/mybatis/dynamic/sql/BasicColumn.java

+1-22
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717

1818
import java.util.Optional;
1919

20-
import org.mybatis.dynamic.sql.exception.DynamicSqlException;
2120
import org.mybatis.dynamic.sql.render.RenderingContext;
22-
import org.mybatis.dynamic.sql.render.TableAliasCalculator;
2321
import org.mybatis.dynamic.sql.util.FragmentAndParameters;
24-
import org.mybatis.dynamic.sql.util.Messages;
2522

2623
/**
2724
* Describes attributes of columns that are necessary for rendering if the column is not expected to
@@ -59,25 +56,7 @@ public interface BasicColumn {
5956
* @return a rendered SQL fragment and, optionally, parameters associated with the fragment
6057
* @since 1.5.1
6158
*/
62-
default FragmentAndParameters render(RenderingContext renderingContext) {
63-
// the default implementation ensures compatibility with prior releases. When the
64-
// deprecated renderWithTableAlias method is removed, this function can become purely abstract.
65-
// Also remove the method tableAliasCalculator() from RenderingContext.
66-
return FragmentAndParameters.fromFragment(renderWithTableAlias(renderingContext.tableAliasCalculator()));
67-
}
68-
69-
/**
70-
* Returns the name of the item aliased with a table name if appropriate.
71-
* For example, "a.foo". This is appropriate for where clauses and order by clauses.
72-
*
73-
* @param tableAliasCalculator the table alias calculator for the current renderer
74-
* @return the item name with the table alias applied
75-
* @deprecated Please replace this method by overriding the more general "render" method
76-
*/
77-
@Deprecated
78-
default String renderWithTableAlias(TableAliasCalculator tableAliasCalculator) {
79-
throw new DynamicSqlException(Messages.getString("ERROR.36")); //$NON-NLS-1$
80-
}
59+
FragmentAndParameters render(RenderingContext renderingContext);
8160

8261
/**
8362
* Utility method to make it easier to build column lists for methods that require an

Diff for: src/main/java/org/mybatis/dynamic/sql/SqlTable.java

+4-78
Original file line numberDiff line numberDiff line change
@@ -18,93 +18,19 @@
1818
import java.sql.JDBCType;
1919
import java.util.Objects;
2020
import java.util.Optional;
21-
import java.util.function.Supplier;
2221

2322
import org.jetbrains.annotations.NotNull;
2423

2524
public class SqlTable implements TableExpression {
2625

27-
protected Supplier<String> nameSupplier;
26+
protected String tableName;
2827

2928
protected SqlTable(String tableName) {
30-
Objects.requireNonNull(tableName);
31-
32-
this.nameSupplier = () -> tableName;
33-
}
34-
35-
/**
36-
* Creates an SqlTable whose name can be changed at runtime.
37-
*
38-
* @param tableNameSupplier table name supplier
39-
* @deprecated please use {@link AliasableSqlTable} if you need to change the table name at runtime
40-
*/
41-
@Deprecated
42-
protected SqlTable(Supplier<String> tableNameSupplier) {
43-
Objects.requireNonNull(tableNameSupplier);
44-
45-
this.nameSupplier = tableNameSupplier;
46-
}
47-
48-
/**
49-
* Creates an SqlTable whose name can be changed at runtime.
50-
*
51-
* @param schemaSupplier schema supplier
52-
* @param tableName table name
53-
* @deprecated please use {@link AliasableSqlTable} if you need to change the table name at runtime
54-
*/
55-
@Deprecated
56-
protected SqlTable(Supplier<Optional<String>> schemaSupplier, String tableName) {
57-
this(Optional::empty, schemaSupplier, tableName);
58-
}
59-
60-
/**
61-
* Creates an SqlTable whose name can be changed at runtime.
62-
*
63-
* @param catalogSupplier catalog supplier
64-
* @param schemaSupplier schema supplier
65-
* @param tableName table name
66-
* @deprecated please use {@link AliasableSqlTable} if you need to change the table name at runtime
67-
*/
68-
@Deprecated
69-
protected SqlTable(Supplier<Optional<String>> catalogSupplier, Supplier<Optional<String>> schemaSupplier,
70-
String tableName) {
71-
Objects.requireNonNull(catalogSupplier);
72-
Objects.requireNonNull(schemaSupplier);
73-
Objects.requireNonNull(tableName);
74-
75-
this.nameSupplier = () -> compose(catalogSupplier, schemaSupplier, tableName);
76-
}
77-
78-
private String compose(Supplier<Optional<String>> catalogSupplier, Supplier<Optional<String>> schemaSupplier,
79-
String tableName) {
80-
return catalogSupplier.get().map(c -> compose(c, schemaSupplier, tableName))
81-
.orElseGet(() -> compose(schemaSupplier, tableName));
82-
}
83-
84-
private String compose(String catalog, Supplier<Optional<String>> schemaSupplier, String tableName) {
85-
return schemaSupplier.get().map(s -> composeCatalogSchemaAndTable(catalog, s, tableName))
86-
.orElseGet(() -> composeCatalogAndTable(catalog, tableName));
87-
}
88-
89-
private String compose(Supplier<Optional<String>> schemaSupplier, String tableName) {
90-
return schemaSupplier.get().map(s -> composeSchemaAndTable(s, tableName))
91-
.orElse(tableName);
92-
}
93-
94-
private String composeCatalogAndTable(String catalog, String tableName) {
95-
return catalog + ".." + tableName; //$NON-NLS-1$
96-
}
97-
98-
private String composeSchemaAndTable(String schema, String tableName) {
99-
return schema + "." + tableName; //$NON-NLS-1$
100-
}
101-
102-
private String composeCatalogSchemaAndTable(String catalog, String schema, String tableName) {
103-
return catalog + "." + schema + "." + tableName; //$NON-NLS-1$ //$NON-NLS-2$
29+
this.tableName = Objects.requireNonNull(tableName);
10430
}
10531

106-
public String tableNameAtRuntime() {
107-
return nameSupplier.get();
32+
public String tableName() {
33+
return tableName;
10834
}
10935

11036
public BasicColumn allColumns() {

Diff for: src/main/java/org/mybatis/dynamic/sql/exception/DuplicateTableAliasException.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ public DuplicateTableAliasException(SqlTable table, String newAlias, String exis
4343
}
4444

4545
private static String generateMessage(SqlTable table, String newAlias, String existingAlias) {
46-
return Messages.getString("ERROR.1", table.tableNameAtRuntime(), newAlias, existingAlias); //$NON-NLS-1$
46+
return Messages.getString("ERROR.1", table.tableName(), newAlias, existingAlias); //$NON-NLS-1$
4747
}
4848
}

Diff for: src/main/java/org/mybatis/dynamic/sql/insert/render/DefaultInsertStatementProvider.java

-13
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,11 @@
2121

2222
public class DefaultInsertStatementProvider<T> implements InsertStatementProvider<T> {
2323
private final String insertStatement;
24-
// need to keep both row and record for now so we don't break
25-
// old code. The MyBatis reflection utilities don't handle
26-
// the case where the attribute name is different from the getter.
27-
//
28-
// MyBatis Generator version 1.4.1 (March 8, 2022) changed to use "row" instead of "record".
29-
// Target March 2023 for removing "record" from MyBatis Dynamic SQL.
30-
private final T record;
3124
private final T row;
3225

3326
private DefaultInsertStatementProvider(Builder<T> builder) {
3427
insertStatement = Objects.requireNonNull(builder.insertStatement);
3528
row = Objects.requireNonNull(builder.row);
36-
record = row;
37-
}
38-
39-
@Override
40-
public T getRecord() {
41-
return record;
4229
}
4330

4431
@Override

Diff for: src/main/java/org/mybatis/dynamic/sql/insert/render/InsertRenderingUtilities.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ public static String calculateInsertStatement(SqlTable table, FieldAndValueColle
3131
}
3232

3333
public static String calculateInsertStatementStart(SqlTable table) {
34-
return "insert into " + table.tableNameAtRuntime(); //$NON-NLS-1$
34+
return "insert into " + table.tableName(); //$NON-NLS-1$
3535
}
3636
}

Diff for: src/main/java/org/mybatis/dynamic/sql/insert/render/InsertStatementProvider.java

-10
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@
1818
import org.jetbrains.annotations.NotNull;
1919

2020
public interface InsertStatementProvider<T> {
21-
/**
22-
* Return the row associated with this insert statement.
23-
*
24-
* @return the row associated with this insert statement.
25-
*
26-
* @deprecated in favor of {@link InsertStatementProvider#getRow()}
27-
*/
28-
@Deprecated
29-
T getRecord();
30-
3121
/**
3222
* Return the row associated with this insert statement.
3323
*

Diff for: src/main/java/org/mybatis/dynamic/sql/render/GuaranteedTableAliasCalculator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public Optional<String> aliasForColumn(SqlTable table) {
3838
if (alias.isPresent()) {
3939
return alias;
4040
} else {
41-
return Optional.of(table.tableNameAtRuntime());
41+
return Optional.of(table.tableName());
4242
}
4343
}
4444

Diff for: src/main/java/org/mybatis/dynamic/sql/render/RenderingContext.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ private RenderingContext(Builder builder) {
5353
: builder.parameterName + "." + RenderingStrategy.DEFAULT_PARAMETER_PREFIX; //$NON-NLS-1$
5454
}
5555

56-
public TableAliasCalculator tableAliasCalculator() {
57-
// this method can be removed when the renderWithTableAlias method is removed from BasicColumn
58-
return tableAliasCalculator;
59-
}
60-
6156
private String nextMapKey() {
6257
return renderingStrategy.formatParameterMapKey(sequence);
6358
}
@@ -93,8 +88,8 @@ public <T> String aliasedColumnName(SqlColumn<T> column, String explicitAlias) {
9388

9489
public String aliasedTableName(SqlTable table) {
9590
return tableAliasCalculator.aliasForTable(table)
96-
.map(a -> table.tableNameAtRuntime() + spaceBefore(a))
97-
.orElseGet(table::tableNameAtRuntime);
91+
.map(a -> table.tableName() + spaceBefore(a))
92+
.orElseGet(table::tableName);
9893
}
9994

10095
public boolean isNonRenderingClauseAllowed() {

Diff for: src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinBaseBuilders.kt

-34
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ import org.mybatis.dynamic.sql.where.AbstractWhereStarter
2525
@DslMarker
2626
annotation class MyBatisDslMarker
2727

28-
@Deprecated("Please use GroupingCriteriaCollector.where")
29-
typealias WhereApplier = KotlinBaseBuilder<*>.() -> Unit
30-
31-
@Deprecated("Please use GroupingCriteriaCollector.where")
32-
fun WhereApplier.andThen(after: WhereApplier): WhereApplier = {
33-
invoke(this)
34-
after(this)
35-
}
36-
3728
@MyBatisDslMarker
3829
@Suppress("TooManyFunctions")
3930
abstract class KotlinBaseBuilder<D : AbstractWhereStarter<*,*>> {
@@ -51,31 +42,6 @@ abstract class KotlinBaseBuilder<D : AbstractWhereStarter<*,*>> {
5142
getDsl().where(criteria)
5243
}
5344

54-
@Deprecated("Please move the \"and\" function into the where lambda. If the where lambda has more than one condition, you may need to surround the existing conditions with \"group\" first.")
55-
fun and(criteria: GroupingCriteriaReceiver): Unit =
56-
GroupingCriteriaCollector().apply(criteria).let {
57-
getDsl().where().and(it.initialCriterion, it.subCriteria)
58-
}
59-
60-
@Deprecated("Please move the \"and\" function into the where lambda. If the where lambda has more than one condition, you may need to surround the existing conditions with \"group\" first.")
61-
fun and(criteria: List<AndOrCriteriaGroup>) {
62-
getDsl().where().and(criteria)
63-
}
64-
65-
@Deprecated("Please move the \"or\" function into the where lambda. If the where lambda has more than one condition, you may need to surround the existing conditions with \"group\" first.")
66-
fun or(criteria: GroupingCriteriaReceiver): Unit =
67-
GroupingCriteriaCollector().apply(criteria).let {
68-
getDsl().where().or(it.initialCriterion, it.subCriteria)
69-
}
70-
71-
@Deprecated("Please move the \"or\" function into the where lambda. If the where lambda has more than one condition, you may need to surround the existing conditions with \"group\" first.")
72-
fun or(criteria: List<AndOrCriteriaGroup>) {
73-
getDsl().where().or(criteria)
74-
}
75-
76-
@Deprecated("Please use GroupingCriteriaCollector.where, then pass it to the \"where\" method")
77-
fun applyWhere(whereApplier: WhereApplier) = whereApplier.invoke(this)
78-
7945
/**
8046
* This function does nothing, but it can be used to make some code snippets more understandable.
8147
*

Diff for: src/main/resources/org/mybatis/dynamic/sql/util/messages.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ERROR.33=Calling "select" or "selectDistinct" more than once is not allowed. Add
5252
union or unionAll expression
5353
ERROR.34=You must specify "select" or "selectDistinct" before any other clauses in a multi-select statement
5454
ERROR.35=Multi-select statements must have at least one "union" or "union all" expression
55-
ERROR.36=You must either implement the "render" or "renderWithTableAlias" method in a column or function
55+
ERROR.36=Obsolete Message - Not Used
5656
ERROR.37=The "{0}" function does not support conditions that fail to render
5757
ERROR.38=Bound values cannot be aliased
5858
ERROR.39=When clauses in case expressions must render

Diff for: src/test/java/examples/joins/JoinMapperTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ void testSelfWithDuplicateAlias() {
957957
.from(user, "u1");
958958

959959
assertThatExceptionOfType(DuplicateTableAliasException.class).isThrownBy(() -> dsl.join(user, "u2"))
960-
.withMessage(Messages.getString("ERROR.1", user.tableNameAtRuntime(), "u2", "u1"));
960+
.withMessage(Messages.getString("ERROR.1", user.tableName(), "u2", "u1"));
961961
}
962962

963963
@Test

Diff for: src/test/java/examples/schema_supplier/SchemaSupplier.java

-26
This file was deleted.

0 commit comments

Comments
 (0)