Skip to content

Commit

Permalink
Merge pull request #826 from jeffgbutler/remove-deprecated-code
Browse files Browse the repository at this point in the history
Remove deprecated code
  • Loading branch information
jeffgbutler authored Aug 5, 2024
2 parents bb60c74 + a602206 commit 970d936
Show file tree
Hide file tree
Showing 25 changed files with 29 additions and 779 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ This log will detail notable changes to MyBatis Dynamic SQL. Full details are av

## Release 2.0.0 - Unreleased

The library now requires Java 17.
Significant changes:

- The library now requires Java 17
- Deprecated code from prior releases is removed

## Release 1.5.2 - June 3, 2024

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ The library test cases provide several complete examples of using the library in

## Requirements

The library has no dependencies. Version 2.x requires Java 17. Version 1.8 requires Java 8.
The library has no dependencies. Version 2.x requires Java 17. Version 1.x requires Java 8.
4 changes: 2 additions & 2 deletions src/main/java/org/mybatis/dynamic/sql/AliasableSqlTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected AliasableSqlTable(String tableName, Supplier<T> constructor) {
public T withAlias(String alias) {
T newTable = constructor.get();
((AliasableSqlTable<T>) newTable).tableAlias = alias;
newTable.nameSupplier = nameSupplier;
newTable.tableName = tableName;
return newTable;
}

Expand All @@ -48,7 +48,7 @@ public T withName(String name) {
Objects.requireNonNull(name);
T newTable = constructor.get();
((AliasableSqlTable<T>) newTable).tableAlias = tableAlias;
newTable.nameSupplier = () -> name;
newTable.tableName = name;
return newTable;
}

Expand Down
23 changes: 1 addition & 22 deletions src/main/java/org/mybatis/dynamic/sql/BasicColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@

import java.util.Optional;

import org.mybatis.dynamic.sql.exception.DynamicSqlException;
import org.mybatis.dynamic.sql.render.RenderingContext;
import org.mybatis.dynamic.sql.render.TableAliasCalculator;
import org.mybatis.dynamic.sql.util.FragmentAndParameters;
import org.mybatis.dynamic.sql.util.Messages;

/**
* Describes attributes of columns that are necessary for rendering if the column is not expected to
Expand Down Expand Up @@ -59,25 +56,7 @@ public interface BasicColumn {
* @return a rendered SQL fragment and, optionally, parameters associated with the fragment
* @since 1.5.1
*/
default FragmentAndParameters render(RenderingContext renderingContext) {
// the default implementation ensures compatibility with prior releases. When the
// deprecated renderWithTableAlias method is removed, this function can become purely abstract.
// Also remove the method tableAliasCalculator() from RenderingContext.
return FragmentAndParameters.fromFragment(renderWithTableAlias(renderingContext.tableAliasCalculator()));
}

/**
* Returns the name of the item aliased with a table name if appropriate.
* For example, "a.foo". This is appropriate for where clauses and order by clauses.
*
* @param tableAliasCalculator the table alias calculator for the current renderer
* @return the item name with the table alias applied
* @deprecated Please replace this method by overriding the more general "render" method
*/
@Deprecated
default String renderWithTableAlias(TableAliasCalculator tableAliasCalculator) {
throw new DynamicSqlException(Messages.getString("ERROR.36")); //$NON-NLS-1$
}
FragmentAndParameters render(RenderingContext renderingContext);

/**
* Utility method to make it easier to build column lists for methods that require an
Expand Down
82 changes: 4 additions & 78 deletions src/main/java/org/mybatis/dynamic/sql/SqlTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,93 +18,19 @@
import java.sql.JDBCType;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Supplier;

import org.jetbrains.annotations.NotNull;

public class SqlTable implements TableExpression {

protected Supplier<String> nameSupplier;
protected String tableName;

protected SqlTable(String tableName) {
Objects.requireNonNull(tableName);

this.nameSupplier = () -> tableName;
}

/**
* Creates an SqlTable whose name can be changed at runtime.
*
* @param tableNameSupplier table name supplier
* @deprecated please use {@link AliasableSqlTable} if you need to change the table name at runtime
*/
@Deprecated
protected SqlTable(Supplier<String> tableNameSupplier) {
Objects.requireNonNull(tableNameSupplier);

this.nameSupplier = tableNameSupplier;
}

/**
* Creates an SqlTable whose name can be changed at runtime.
*
* @param schemaSupplier schema supplier
* @param tableName table name
* @deprecated please use {@link AliasableSqlTable} if you need to change the table name at runtime
*/
@Deprecated
protected SqlTable(Supplier<Optional<String>> schemaSupplier, String tableName) {
this(Optional::empty, schemaSupplier, tableName);
}

/**
* Creates an SqlTable whose name can be changed at runtime.
*
* @param catalogSupplier catalog supplier
* @param schemaSupplier schema supplier
* @param tableName table name
* @deprecated please use {@link AliasableSqlTable} if you need to change the table name at runtime
*/
@Deprecated
protected SqlTable(Supplier<Optional<String>> catalogSupplier, Supplier<Optional<String>> schemaSupplier,
String tableName) {
Objects.requireNonNull(catalogSupplier);
Objects.requireNonNull(schemaSupplier);
Objects.requireNonNull(tableName);

this.nameSupplier = () -> compose(catalogSupplier, schemaSupplier, tableName);
}

private String compose(Supplier<Optional<String>> catalogSupplier, Supplier<Optional<String>> schemaSupplier,
String tableName) {
return catalogSupplier.get().map(c -> compose(c, schemaSupplier, tableName))
.orElseGet(() -> compose(schemaSupplier, tableName));
}

private String compose(String catalog, Supplier<Optional<String>> schemaSupplier, String tableName) {
return schemaSupplier.get().map(s -> composeCatalogSchemaAndTable(catalog, s, tableName))
.orElseGet(() -> composeCatalogAndTable(catalog, tableName));
}

private String compose(Supplier<Optional<String>> schemaSupplier, String tableName) {
return schemaSupplier.get().map(s -> composeSchemaAndTable(s, tableName))
.orElse(tableName);
}

private String composeCatalogAndTable(String catalog, String tableName) {
return catalog + ".." + tableName; //$NON-NLS-1$
}

private String composeSchemaAndTable(String schema, String tableName) {
return schema + "." + tableName; //$NON-NLS-1$
}

private String composeCatalogSchemaAndTable(String catalog, String schema, String tableName) {
return catalog + "." + schema + "." + tableName; //$NON-NLS-1$ //$NON-NLS-2$
this.tableName = Objects.requireNonNull(tableName);
}

public String tableNameAtRuntime() {
return nameSupplier.get();
public String tableName() {
return tableName;
}

public BasicColumn allColumns() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ public DuplicateTableAliasException(SqlTable table, String newAlias, String exis
}

private static String generateMessage(SqlTable table, String newAlias, String existingAlias) {
return Messages.getString("ERROR.1", table.tableNameAtRuntime(), newAlias, existingAlias); //$NON-NLS-1$
return Messages.getString("ERROR.1", table.tableName(), newAlias, existingAlias); //$NON-NLS-1$
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,11 @@

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

private DefaultInsertStatementProvider(Builder<T> builder) {
insertStatement = Objects.requireNonNull(builder.insertStatement);
row = Objects.requireNonNull(builder.row);
record = row;
}

@Override
public T getRecord() {
return record;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public static String calculateInsertStatement(SqlTable table, FieldAndValueColle
}

public static String calculateInsertStatementStart(SqlTable table) {
return "insert into " + table.tableNameAtRuntime(); //$NON-NLS-1$
return "insert into " + table.tableName(); //$NON-NLS-1$
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@
import org.jetbrains.annotations.NotNull;

public interface InsertStatementProvider<T> {
/**
* Return the row associated with this insert statement.
*
* @return the row associated with this insert statement.
*
* @deprecated in favor of {@link InsertStatementProvider#getRow()}
*/
@Deprecated
T getRecord();

/**
* Return the row associated with this insert statement.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Optional<String> aliasForColumn(SqlTable table) {
if (alias.isPresent()) {
return alias;
} else {
return Optional.of(table.tableNameAtRuntime());
return Optional.of(table.tableName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ private RenderingContext(Builder builder) {
: builder.parameterName + "." + RenderingStrategy.DEFAULT_PARAMETER_PREFIX; //$NON-NLS-1$
}

public TableAliasCalculator tableAliasCalculator() {
// this method can be removed when the renderWithTableAlias method is removed from BasicColumn
return tableAliasCalculator;
}

private String nextMapKey() {
return renderingStrategy.formatParameterMapKey(sequence);
}
Expand Down Expand Up @@ -93,8 +88,8 @@ public <T> String aliasedColumnName(SqlColumn<T> column, String explicitAlias) {

public String aliasedTableName(SqlTable table) {
return tableAliasCalculator.aliasForTable(table)
.map(a -> table.tableNameAtRuntime() + spaceBefore(a))
.orElseGet(table::tableNameAtRuntime);
.map(a -> table.tableName() + spaceBefore(a))
.orElseGet(table::tableName);
}

public boolean isNonRenderingClauseAllowed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ import org.mybatis.dynamic.sql.where.AbstractWhereStarter
@DslMarker
annotation class MyBatisDslMarker

@Deprecated("Please use GroupingCriteriaCollector.where")
typealias WhereApplier = KotlinBaseBuilder<*>.() -> Unit

@Deprecated("Please use GroupingCriteriaCollector.where")
fun WhereApplier.andThen(after: WhereApplier): WhereApplier = {
invoke(this)
after(this)
}

@MyBatisDslMarker
@Suppress("TooManyFunctions")
abstract class KotlinBaseBuilder<D : AbstractWhereStarter<*,*>> {
Expand All @@ -51,31 +42,6 @@ abstract class KotlinBaseBuilder<D : AbstractWhereStarter<*,*>> {
getDsl().where(criteria)
}

@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.")
fun and(criteria: GroupingCriteriaReceiver): Unit =
GroupingCriteriaCollector().apply(criteria).let {
getDsl().where().and(it.initialCriterion, it.subCriteria)
}

@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.")
fun and(criteria: List<AndOrCriteriaGroup>) {
getDsl().where().and(criteria)
}

@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.")
fun or(criteria: GroupingCriteriaReceiver): Unit =
GroupingCriteriaCollector().apply(criteria).let {
getDsl().where().or(it.initialCriterion, it.subCriteria)
}

@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.")
fun or(criteria: List<AndOrCriteriaGroup>) {
getDsl().where().or(criteria)
}

@Deprecated("Please use GroupingCriteriaCollector.where, then pass it to the \"where\" method")
fun applyWhere(whereApplier: WhereApplier) = whereApplier.invoke(this)

/**
* This function does nothing, but it can be used to make some code snippets more understandable.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ERROR.33=Calling "select" or "selectDistinct" more than once is not allowed. Add
union or unionAll expression
ERROR.34=You must specify "select" or "selectDistinct" before any other clauses in a multi-select statement
ERROR.35=Multi-select statements must have at least one "union" or "union all" expression
ERROR.36=You must either implement the "render" or "renderWithTableAlias" method in a column or function
ERROR.36=Obsolete Message - Not Used
ERROR.37=The "{0}" function does not support conditions that fail to render
ERROR.38=Bound values cannot be aliased
ERROR.39=When clauses in case expressions must render
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/examples/joins/JoinMapperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ void testSelfWithDuplicateAlias() {
.from(user, "u1");

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

@Test
Expand Down
26 changes: 0 additions & 26 deletions src/test/java/examples/schema_supplier/SchemaSupplier.java

This file was deleted.

Loading

0 comments on commit 970d936

Please sign in to comment.