Skip to content

Remove deprecated "when" and "then" methods #435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ GitHub milestone: [https://github.com/mybatis/mybatis-dynamic-sql/issues?q=miles
we did not support the grouping of criteria at the beginning of a where clause or the beginning of an and/or
condition. Adding this support required significant refactoring, but that should be transparent to most users.
([#434](https://github.com/mybatis/mybatis-dynamic-sql/pull/434))
2. Remove deprecated "when" and "then" methods on all conditions. The methods have been replaced by more appropriately
named "filter" and "map" methods that function as expected for method chaining.
([#435](https://github.com/mybatis/mybatis-dynamic-sql/pull/435))

## Release 1.3.1 - December 18, 2021

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--

Copyright 2016-2021 the original author or authors.
Copyright 2016-2022 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 the original author or authors.
* Copyright 2016-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,6 @@
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;

import org.mybatis.dynamic.sql.AbstractTwoValueCondition;

Expand All @@ -46,35 +45,6 @@ public String renderCondition(String columnName, String placeholder1, String pla
return columnName + " between " + placeholder1 + " and " + placeholder2; //$NON-NLS-1$ //$NON-NLS-2$
}

/**
* If renderable and the values match the predicate, returns this condition. Else returns a condition
* that will not render.
*
* @deprecated replaced by {@link IsBetween#filter(BiPredicate)}
* @param predicate predicate applied to the values, if renderable
* @return this condition if renderable and the values match the predicate, otherwise a condition
* that will not render.
*/
@Deprecated
public IsBetween<T> when(BiPredicate<T, T> predicate) {
return filter(predicate);
}

/**
* If renderable, apply the mappings to the values and return a new condition with the new values. Else return a
* condition that will not render (this).
*
* @deprecated replaced by {@link IsBetween#map(Function, Function)}
* @param mapper1 a mapping function to apply to the first value, if renderable
* @param mapper2 a mapping function to apply to the second value, if renderable
* @return a new condition with the result of applying the mappers to the values of this condition,
* if renderable, otherwise a condition that will not render.
*/
@Deprecated
public IsBetween<T> then(UnaryOperator<T> mapper1, UnaryOperator<T> mapper2) {
return map(mapper1, mapper2);
}

@Override
public IsBetween<T> filter(BiPredicate<? super T, ? super T> predicate) {
return filterSupport(predicate, IsBetween::empty, this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 the original author or authors.
* Copyright 2016-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@

import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;

import org.mybatis.dynamic.sql.AbstractSingleValueCondition;

Expand Down Expand Up @@ -49,34 +48,6 @@ public static <T> IsEqualTo<T> of(T value) {
return new IsEqualTo<>(value);
}

/**
* If renderable and the value matches the predicate, returns this condition. Else returns a condition
* that will not render.
*
* @deprecated replaced by {@link IsEqualTo#filter(Predicate)}
* @param predicate predicate applied to the value, if renderable
* @return this condition if renderable and the value matches the predicate, otherwise a condition
* that will not render.
*/
@Deprecated
public IsEqualTo<T> when(Predicate<T> predicate) {
return filter(predicate);
}

/**
* If renderable, apply the mapping to the value and return a new condition with the new value. Else return a
* condition that will not render (this).
*
* @deprecated replaced by {@link IsEqualTo#map(Function)}
* @param mapper a mapping function to apply to the value, if renderable
* @return a new condition with the result of applying the mapper to the value of this condition,
* if renderable, otherwise a condition that will not render.
*/
@Deprecated
public IsEqualTo<T> then(UnaryOperator<T> mapper) {
return map(mapper);
}

@Override
public IsEqualTo<T> filter(Predicate<? super T> predicate) {
return filterSupport(predicate, IsEqualTo::empty, this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 the original author or authors.
* Copyright 2016-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@

import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;

import org.mybatis.dynamic.sql.AbstractSingleValueCondition;

Expand Down Expand Up @@ -48,34 +47,6 @@ public static <T> IsGreaterThan<T> of(T value) {
return new IsGreaterThan<>(value);
}

/**
* If renderable and the value matches the predicate, returns this condition. Else returns a condition
* that will not render.
*
* @deprecated replaced by {@link IsGreaterThan#filter(Predicate)}
* @param predicate predicate applied to the value, if renderable
* @return this condition if renderable and the value matches the predicate, otherwise a condition
* that will not render.
*/
@Deprecated
public IsGreaterThan<T> when(Predicate<T> predicate) {
return filter(predicate);
}

/**
* If renderable, apply the mapping to the value and return a new condition with the new value. Else return a
* condition that will not render (this).
*
* @deprecated replaced by {@link IsGreaterThan#map(Function)}
* @param mapper a mapping function to apply to the value, if renderable
* @return a new condition with the result of applying the mapper to the value of this condition,
* if renderable, otherwise a condition that will not render.
*/
@Deprecated
public IsGreaterThan<T> then(UnaryOperator<T> mapper) {
return map(mapper);
}

@Override
public IsGreaterThan<T> filter(Predicate<? super T> predicate) {
return filterSupport(predicate, IsGreaterThan::empty, this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 the original author or authors.
* Copyright 2016-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@

import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;

import org.mybatis.dynamic.sql.AbstractSingleValueCondition;

Expand Down Expand Up @@ -48,34 +47,6 @@ public static <T> IsGreaterThanOrEqualTo<T> of(T value) {
return new IsGreaterThanOrEqualTo<>(value);
}

/**
* If renderable and the value matches the predicate, returns this condition. Else returns a condition
* that will not render.
*
* @deprecated replaced by {@link IsGreaterThanOrEqualTo#filter(Predicate)}
* @param predicate predicate applied to the value, if renderable
* @return this condition if renderable and the value matches the predicate, otherwise a condition
* that will not render.
*/
@Deprecated
public IsGreaterThanOrEqualTo<T> when(Predicate<T> predicate) {
return filter(predicate);
}

/**
* If renderable, apply the mapping to the value and return a new condition with the new value. Else return a
* condition that will not render (this).
*
* @deprecated replaced by {@link IsGreaterThanOrEqualTo#map(Function)}
* @param mapper a mapping function to apply to the value, if renderable
* @return a new condition with the result of applying the mapper to the value of this condition,
* if renderable, otherwise a condition that will not render.
*/
@Deprecated
public IsGreaterThanOrEqualTo<T> then(UnaryOperator<T> mapper) {
return map(mapper);
}

@Override
public IsGreaterThanOrEqualTo<T> filter(Predicate<? super T> predicate) {
return filterSupport(predicate, IsGreaterThanOrEqualTo::empty, this);
Expand Down
30 changes: 7 additions & 23 deletions src/main/java/org/mybatis/dynamic/sql/where/condition/IsIn.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 the original author or authors.
* Copyright 2016-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,11 +20,9 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -40,6 +38,10 @@ public static <T> IsIn<T> empty() {
return t;
}

private <S> IsIn<S> emptyWithCallBack() {
return new IsIn<>(Collections.emptyList(), emptyCallback);
}

protected IsIn(Collection<T> values) {
super(values);
}
Expand All @@ -59,27 +61,9 @@ public IsIn<T> withListEmptyCallback(Callback callback) {
return new IsIn<>(values, callback);
}

/**
* This method allows you to modify the condition's values before they are placed into the parameter map.
* For example, you could filter nulls, or trim strings, etc. This process will run before final rendering of SQL.
* If you filter values out of the stream, then final condition will not reference those values. If you filter all
* values out of the stream, then the condition will not render.
*
* @deprecated replaced by {@link IsIn#map(Function)} and {@link IsIn#filter(Predicate)}
* @param valueStreamTransformer a UnaryOperator that will transform the value stream before
* the values are placed in the parameter map
* @return new condition with the specified transformer
*/
@Deprecated
public IsIn<T> then(UnaryOperator<Stream<T>> valueStreamTransformer) {
List<T> mapped = valueStreamTransformer.apply(values.stream())
.collect(Collectors.toList());
return new IsIn<>(mapped, emptyCallback);
}

@Override
public IsIn<T> filter(Predicate<? super T> predicate) {
return filterSupport(predicate, IsIn::new, this, IsIn::empty);
return filterSupport(predicate, IsIn::new, this, this::emptyWithCallBack);
}

/**
Expand All @@ -93,7 +77,7 @@ public IsIn<T> filter(Predicate<? super T> predicate) {
*/
public <R> IsIn<R> map(Function<? super T, ? extends R> mapper) {
BiFunction<Collection<R>, Callback, IsIn<R>> constructor = IsIn::new;
return mapSupport(mapper, constructor, IsIn::empty);
return mapSupport(mapper, constructor, this::emptyWithCallBack);
}

@SafeVarargs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 the original author or authors.
* Copyright 2016-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,6 +34,10 @@ public static IsInCaseInsensitive empty() {
return EMPTY;
}

private IsInCaseInsensitive emptyWithCallback() {
return new IsInCaseInsensitive(Collections.emptyList(), emptyCallback);
}

protected IsInCaseInsensitive(Collection<String> values) {
super(values);
}
Expand All @@ -56,7 +60,7 @@ public IsInCaseInsensitive withListEmptyCallback(Callback callback) {

@Override
public IsInCaseInsensitive filter(Predicate<? super String> predicate) {
return filterSupport(predicate, IsInCaseInsensitive::new, this, IsInCaseInsensitive::empty);
return filterSupport(predicate, IsInCaseInsensitive::new, this, this::emptyWithCallback);
}

/**
Expand All @@ -68,7 +72,7 @@ public IsInCaseInsensitive filter(Predicate<? super String> predicate) {
* that will not render.
*/
public IsInCaseInsensitive map(UnaryOperator<String> mapper) {
return mapSupport(mapper, IsInCaseInsensitive::new, IsInCaseInsensitive::empty);
return mapSupport(mapper, IsInCaseInsensitive::new, this::emptyWithCallback);
}

public static IsInCaseInsensitive of(String... values) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 the original author or authors.
* Copyright 2016-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@

import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;

import org.mybatis.dynamic.sql.AbstractSingleValueCondition;

Expand Down Expand Up @@ -48,34 +47,6 @@ public static <T> IsLessThan<T> of(T value) {
return new IsLessThan<>(value);
}

/**
* If renderable and the value matches the predicate, returns this condition. Else returns a condition
* that will not render.
*
* @deprecated replaced by {@link IsLessThan#filter(Predicate)}
* @param predicate predicate applied to the value, if renderable
* @return this condition if renderable and the value matches the predicate, otherwise a condition
* that will not render.
*/
@Deprecated
public IsLessThan<T> when(Predicate<T> predicate) {
return filter(predicate);
}

/**
* If renderable, apply the mapping to the value and return a new condition with the new value. Else return a
* condition that will not render (this).
*
* @deprecated replaced by {@link IsLessThan#map(Function)}
* @param mapper a mapping function to apply to the value, if renderable
* @return a new condition with the result of applying the mapper to the value of this condition,
* if renderable, otherwise a condition that will not render.
*/
@Deprecated
public IsLessThan<T> then(UnaryOperator<T> mapper) {
return map(mapper);
}

@Override
public IsLessThan<T> filter(Predicate<? super T> predicate) {
return filterSupport(predicate, IsLessThan::empty, this);
Expand Down
Loading