Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.util.Collection;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
Expand All @@ -27,32 +26,8 @@
public abstract class AbstractListValueCondition<T> implements VisitableCondition<T> {
protected final Collection<T> values;

/**
* Callback to execute when the list is empty.
*
* @deprecated in favor of the statement configuration functions
*/
@Deprecated
protected final Callback emptyCallback;

protected AbstractListValueCondition(Collection<T> values) {
this(values, () -> { });
}

/**
* Construct a new condition with a callback.
*
* @param values
* values
* @param emptyCallback
* empty callback
*
* @deprecated in favor of the statement configuration functions
*/
@Deprecated
protected AbstractListValueCondition(Collection<T> values, Callback emptyCallback) {
this.values = Objects.requireNonNull(values);
this.emptyCallback = Objects.requireNonNull(emptyCallback);
}

public final <R> Stream<R> mapValues(Function<T, R> mapper) {
Expand All @@ -64,11 +39,6 @@ public boolean shouldRender() {
return !values.isEmpty();
}

@Override
public void renderingSkipped() {
emptyCallback.call();
}

@Override
public <R> R accept(ConditionVisitor<T, R> visitor) {
return visitor.visit(this);
Expand All @@ -85,19 +55,19 @@ private Collection<T> applyFilter(Predicate<? super T> predicate) {
}

protected <S extends AbstractListValueCondition<T>> S filterSupport(Predicate<? super T> predicate,
BiFunction<Collection<T>, Callback, S> constructor, S self, Supplier<S> emptySupplier) {
Function<Collection<T>, S> constructor, S self, Supplier<S> emptySupplier) {
if (shouldRender()) {
Collection<T> filtered = applyFilter(predicate);
return filtered.isEmpty() ? emptySupplier.get() : constructor.apply(filtered, emptyCallback);
return filtered.isEmpty() ? emptySupplier.get() : constructor.apply(filtered);
} else {
return self;
}
}

protected <R, S extends AbstractListValueCondition<R>> S mapSupport(Function<? super T, ? extends R> mapper,
BiFunction<Collection<R>, Callback, S> constructor, Supplier<S> emptySupplier) {
Function<Collection<R>, S> constructor, Supplier<S> emptySupplier) {
if (shouldRender()) {
return constructor.apply(applyMapper(mapper), emptyCallback);
return constructor.apply(applyMapper(mapper));
} else {
return emptySupplier.get();
}
Expand All @@ -115,18 +85,5 @@ protected <R, S extends AbstractListValueCondition<R>> S mapSupport(Function<? s
*/
public abstract AbstractListValueCondition<T> filter(Predicate<? super T> predicate);

/**
* Specifies a callback function to be called if the value list is empty when rendered.
*
* @param callback
* a callback function - typically throws an exception to block the statement from executing
*
* @return this condition
*
* @deprecated in favor of the statement configuration functions
*/
@Deprecated
public abstract AbstractListValueCondition<T> withListEmptyCallback(Callback callback);

public abstract String renderCondition(String columnName, Stream<String> placeholders);
}
40 changes: 0 additions & 40 deletions src/main/java/org/mybatis/dynamic/sql/Callback.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class DefaultInsertStatementProvider<T> implements InsertStatementProvide
// 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;

Expand Down
51 changes: 3 additions & 48 deletions src/main/java/org/mybatis/dynamic/sql/where/condition/IsIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.mybatis.dynamic.sql.AbstractListValueCondition;
import org.mybatis.dynamic.sql.Callback;

public class IsIn<T> extends AbstractListValueCondition<T> {
private static final IsIn<?> EMPTY = new IsIn<>(Collections.emptyList());
Expand All @@ -38,62 +36,19 @@ public static <T> IsIn<T> empty() {
return t;
}

/**
* Build an empty condition.
*
* @return a new empty condition
*
* @deprecated in favor of the statement configuration functions
*/
@Deprecated
private <S> IsIn<S> emptyWithCallBack() {
return new IsIn<>(Collections.emptyList(), emptyCallback);
}

protected IsIn(Collection<T> values) {
super(values);
}

/**
* Build a new condition with a callback.
*
* @param values
* values
* @param emptyCallback
* empty callback
*
* @deprecated in favor of the statement configuration functions
*/
@Deprecated
protected IsIn(Collection<T> values, Callback emptyCallback) {
super(values, emptyCallback);
}

@Override
public String renderCondition(String columnName, Stream<String> placeholders) {
return spaceAfter(columnName)
+ placeholders.collect(Collectors.joining(",", "in (", ")")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}

/**
* Build a new condition with a callback.
*
* @param callback
* a callback function - typically throws an exception to block the statement from executing
*
* @return this condition
*
* @deprecated in favor of the statement configuration functions
*/
@Deprecated
@Override
public IsIn<T> withListEmptyCallback(Callback callback) {
return new IsIn<>(values, callback);
}

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

/**
Expand All @@ -106,8 +61,8 @@ public IsIn<T> filter(Predicate<? super T> predicate) {
* that will not render.
*/
public <R> IsIn<R> map(Function<? super T, ? extends R> mapper) {
BiFunction<Collection<R>, Callback, IsIn<R>> constructor = IsIn::new;
return mapSupport(mapper, constructor, this::emptyWithCallBack);
Function<Collection<R>, IsIn<R>> constructor = IsIn::new;
return mapSupport(mapper, constructor, IsIn::empty);
}

@SafeVarargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.stream.Stream;

import org.mybatis.dynamic.sql.AbstractListValueCondition;
import org.mybatis.dynamic.sql.Callback;
import org.mybatis.dynamic.sql.util.StringUtilities;

public class IsInCaseInsensitive extends AbstractListValueCondition<String> {
Expand All @@ -34,63 +33,20 @@ public static IsInCaseInsensitive empty() {
return EMPTY;
}

/**
* Build an empty condition.
*
* @return a new empty condition
*
* @deprecated in favor of the statement configuration functions
*/
@Deprecated
private IsInCaseInsensitive emptyWithCallback() {
return new IsInCaseInsensitive(Collections.emptyList(), emptyCallback);
}

protected IsInCaseInsensitive(Collection<String> values) {
super(values);
}

/**
* Build a new instance with a callback.
*
* @param values
* values
* @param emptyCallback
* empty callback
*
* @deprecated in favor of the statement configuration functions
*/
@Deprecated
protected IsInCaseInsensitive(Collection<String> values, Callback emptyCallback) {
super(values, emptyCallback);
}

@Override
public String renderCondition(String columnName, Stream<String> placeholders) {
return "upper(" + columnName + ") " //$NON-NLS-1$ //$NON-NLS-2$
+ placeholders.collect(
Collectors.joining(",", "in (", ")")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}

/**
* Build a new instance with a callback.
*
* @param callback
* a callback function - typically throws an exception to block the statement from executing
*
* @return this condition
*
* @deprecated in favor of the statement configuration functions
*/
@Deprecated
@Override
public IsInCaseInsensitive withListEmptyCallback(Callback callback) {
return new IsInCaseInsensitive(values, callback);
}

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

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

public static IsInCaseInsensitive of(String... values) {
Expand Down
Loading