Skip to content

Commit

Permalink
Merge pull request #832 from jeffgbutler/sort-deprecations
Browse files Browse the repository at this point in the history
Remove Deprecated sortSpecification Methods
  • Loading branch information
jeffgbutler authored Aug 7, 2024
2 parents 8263897 + f920911 commit 68cadc5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 208 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ worked to make these changes as minimal as possible.

**Potentially Breaking Changes:**

- If you have created any custom implementations of `SortSpecification`, you will need to update those
implementations due to a new rendering strategy for ORDER BY phrases. The old methods `isDescending` and `orderByName`
are removed in favor of a new method `renderForOrderBy`
- If you have implemented any custom functions, you will likely need to make changes. The supplied base classes now
hold an instance of `BasicColumn` rather than `BindableColumn`. This change was made to make the functions more
useful in variety of circumstances. If you follow the patterns shown on the
Expand Down
39 changes: 6 additions & 33 deletions src/main/java/org/mybatis/dynamic/sql/SortSpecification.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
*/
package org.mybatis.dynamic.sql;

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

/**
* Defines attributes of columns that are necessary for rendering an order by expression.
Expand All @@ -35,37 +33,12 @@ public interface SortSpecification {
SortSpecification descending();

/**
* Return the phrase that should be written into a rendered order by clause. This should
* NOT include the "DESC" word for descending sort specifications.
* Return a fragment rendered for use in an ORDER BY clause. The fragment should include "DESC" if a
* descending order is desired.
*
* @return the order by phrase
* @deprecated Please replace this method by overriding the more general "renderForOrderBy" method. Target for
* removal in release 2.1
* @param renderingContext the current rendering context
* @return a rendered fragment and parameters if applicable
* @since 2.0.0
*/
@Deprecated(since = "2.0", forRemoval = true)
default String orderByName() {
throw new DynamicSqlException(Messages.getString("ERROR.44")); //$NON-NLS-1$
}

/**
* Return true if the sort order is descending.
*
* @return true if the SortSpecification should render as descending
* @deprecated Please replace this method by overriding the more general "renderForOrderBy" method. Target for
* removal in release 2.1
*/
@Deprecated(since = "2.0", forRemoval = true)
default boolean isDescending() {
throw new DynamicSqlException(Messages.getString("ERROR.44")); //$NON-NLS-1$
}

// the default implementation ensures compatibility with prior releases. When the
// deprecated methods are removed, this function can become purely abstract.
default FragmentAndParameters renderForOrderBy(RenderingContext renderingContext) {
String phrase = orderByName();
if (isDescending()) {
phrase = phrase + " DESC"; //$NON-NLS-1$
}
return FragmentAndParameters.fromFragment(phrase);
}
FragmentAndParameters renderForOrderBy(RenderingContext renderingContext);
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,4 @@ ERROR.40=Case expressions must have at least one "when" clause
ERROR.41=You cannot call "then" in a Kotlin case expression more than once
ERROR.42=You cannot call `else` in a Kotlin case expression more than once
ERROR.43=A Kotlin cast expression must have one, and only one, `as` element
ERROR.44=You must either implement the "renderForOrderBy" method or both "orderByName" and "isDescending" methods in a \
sort specification
INTERNAL.ERROR=Internal Error {0}
173 changes: 0 additions & 173 deletions src/test/java/org/mybatis/dynamic/sql/DeprecatedSortMethodsTest.java

This file was deleted.

0 comments on commit 68cadc5

Please sign in to comment.