From 9aea401ccb54bea67d5db7c3cf6471a8ad47cbc0 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Wed, 15 May 2024 10:07:17 -0400 Subject: [PATCH 01/11] Change Default Behavior - empty list conditions render by default This will force an empty list condition to render by default - which will cause an SQLException. After much discussion and many issues, we decided this was the safest approach. --- .../dynamic/sql/configuration/GlobalConfiguration.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/mybatis/dynamic/sql/configuration/GlobalConfiguration.java b/src/main/java/org/mybatis/dynamic/sql/configuration/GlobalConfiguration.java index b5027e565..7beaab9d3 100644 --- a/src/main/java/org/mybatis/dynamic/sql/configuration/GlobalConfiguration.java +++ b/src/main/java/org/mybatis/dynamic/sql/configuration/GlobalConfiguration.java @@ -26,7 +26,7 @@ public class GlobalConfiguration { public static final String CONFIGURATION_FILE_PROPERTY = "mybatis-dynamic-sql.configurationFile"; //$NON-NLS-1$ private static final String DEFAULT_PROPERTY_FILE = "mybatis-dynamic-sql.properties"; //$NON-NLS-1$ private boolean isNonRenderingWhereClauseAllowed = false; - private boolean isEmptyListConditionRenderingAllowed = false; + private boolean isEmptyListConditionRenderingAllowed = true; private final Properties properties = new Properties(); public GlobalConfiguration() { @@ -67,7 +67,7 @@ private void initializeKnownProperties() { String value = properties.getProperty("nonRenderingWhereClauseAllowed", "false"); //$NON-NLS-1$ //$NON-NLS-2$ isNonRenderingWhereClauseAllowed = Boolean.parseBoolean(value); - value = properties.getProperty("emptyListConditionRenderingAllowed", "false"); //$NON-NLS-1$ //$NON-NLS-2$ + value = properties.getProperty("emptyListConditionRenderingAllowed", "true"); //$NON-NLS-1$ //$NON-NLS-2$ isEmptyListConditionRenderingAllowed = Boolean.parseBoolean(value); } From b47aed44c812e117aec54731b3c60ae3f0db2b4b Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Wed, 15 May 2024 10:37:59 -0400 Subject: [PATCH 02/11] New InWhenPresent Conditions These conditions will not render if empty regardless of configuration settings. This is consistent with the other "when present" conditions. --- .../org/mybatis/dynamic/sql/SqlBuilder.java | 38 +++++---- .../IsInCaseInsensitiveWhenPresent.java | 76 ++++++++++++++++++ .../sql/where/condition/IsInWhenPresent.java | 79 +++++++++++++++++++ .../IsNotInCaseInsensitiveWhenPresent.java | 76 ++++++++++++++++++ .../where/condition/IsNotInWhenPresent.java | 79 +++++++++++++++++++ .../sql/util/kotlin/elements/SqlElements.kt | 28 ++++--- 6 files changed, 347 insertions(+), 29 deletions(-) create mode 100644 src/main/java/org/mybatis/dynamic/sql/where/condition/IsInCaseInsensitiveWhenPresent.java create mode 100644 src/main/java/org/mybatis/dynamic/sql/where/condition/IsInWhenPresent.java create mode 100644 src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInCaseInsensitiveWhenPresent.java create mode 100644 src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInWhenPresent.java diff --git a/src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java b/src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java index a100e7bf7..6516696f6 100644 --- a/src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java +++ b/src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java @@ -76,6 +76,8 @@ import org.mybatis.dynamic.sql.where.condition.IsGreaterThanWithSubselect; import org.mybatis.dynamic.sql.where.condition.IsIn; import org.mybatis.dynamic.sql.where.condition.IsInCaseInsensitive; +import org.mybatis.dynamic.sql.where.condition.IsInCaseInsensitiveWhenPresent; +import org.mybatis.dynamic.sql.where.condition.IsInWhenPresent; import org.mybatis.dynamic.sql.where.condition.IsInWithSubselect; import org.mybatis.dynamic.sql.where.condition.IsLessThan; import org.mybatis.dynamic.sql.where.condition.IsLessThanColumn; @@ -91,6 +93,8 @@ import org.mybatis.dynamic.sql.where.condition.IsNotEqualToWithSubselect; import org.mybatis.dynamic.sql.where.condition.IsNotIn; import org.mybatis.dynamic.sql.where.condition.IsNotInCaseInsensitive; +import org.mybatis.dynamic.sql.where.condition.IsNotInCaseInsensitiveWhenPresent; +import org.mybatis.dynamic.sql.where.condition.IsNotInWhenPresent; import org.mybatis.dynamic.sql.where.condition.IsNotInWithSubselect; import org.mybatis.dynamic.sql.where.condition.IsNotLike; import org.mybatis.dynamic.sql.where.condition.IsNotLikeCaseInsensitive; @@ -764,12 +768,12 @@ static IsInWithSubselect isIn(Buildable selectModelBuilder) } @SafeVarargs - static IsIn isInWhenPresent(T... values) { - return IsIn.of(values).filter(Objects::nonNull); + static IsInWhenPresent isInWhenPresent(T... values) { + return IsInWhenPresent.of(values); } - static IsIn isInWhenPresent(Collection values) { - return values == null ? IsIn.empty() : IsIn.of(values).filter(Objects::nonNull); + static IsInWhenPresent isInWhenPresent(Collection values) { + return values == null ? IsInWhenPresent.empty() : IsInWhenPresent.of(values); } @SafeVarargs @@ -786,12 +790,12 @@ static IsNotInWithSubselect isNotIn(Buildable selectModelBui } @SafeVarargs - static IsNotIn isNotInWhenPresent(T... values) { - return IsNotIn.of(values).filter(Objects::nonNull); + static IsNotInWhenPresent isNotInWhenPresent(T... values) { + return IsNotInWhenPresent.of(values); } - static IsNotIn isNotInWhenPresent(Collection values) { - return values == null ? IsNotIn.empty() : IsNotIn.of(values).filter(Objects::nonNull); + static IsNotInWhenPresent isNotInWhenPresent(Collection values) { + return values == null ? IsNotInWhenPresent.empty() : IsNotInWhenPresent.of(values); } static IsBetween.Builder isBetween(T value1) { @@ -909,12 +913,12 @@ static IsInCaseInsensitive isInCaseInsensitive(Collection values) { return IsInCaseInsensitive.of(values); } - static IsInCaseInsensitive isInCaseInsensitiveWhenPresent(String... values) { - return IsInCaseInsensitive.of(values).filter(Objects::nonNull); + static IsInCaseInsensitiveWhenPresent isInCaseInsensitiveWhenPresent(String... values) { + return IsInCaseInsensitiveWhenPresent.of(values); } - static IsInCaseInsensitive isInCaseInsensitiveWhenPresent(Collection values) { - return values == null ? IsInCaseInsensitive.empty() : IsInCaseInsensitive.of(values).filter(Objects::nonNull); + static IsInCaseInsensitiveWhenPresent isInCaseInsensitiveWhenPresent(Collection values) { + return values == null ? IsInCaseInsensitiveWhenPresent.empty() : IsInCaseInsensitiveWhenPresent.of(values); } static IsNotInCaseInsensitive isNotInCaseInsensitive(String... values) { @@ -925,13 +929,13 @@ static IsNotInCaseInsensitive isNotInCaseInsensitive(Collection values) return IsNotInCaseInsensitive.of(values); } - static IsNotInCaseInsensitive isNotInCaseInsensitiveWhenPresent(String... values) { - return IsNotInCaseInsensitive.of(values).filter(Objects::nonNull); + static IsNotInCaseInsensitiveWhenPresent isNotInCaseInsensitiveWhenPresent(String... values) { + return IsNotInCaseInsensitiveWhenPresent.of(values); } - static IsNotInCaseInsensitive isNotInCaseInsensitiveWhenPresent(Collection values) { - return values == null ? IsNotInCaseInsensitive.empty() : - IsNotInCaseInsensitive.of(values).filter(Objects::nonNull); + static IsNotInCaseInsensitiveWhenPresent isNotInCaseInsensitiveWhenPresent(Collection values) { + return values == null ? IsNotInCaseInsensitiveWhenPresent.empty() : + IsNotInCaseInsensitiveWhenPresent.of(values); } // order by support diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsInCaseInsensitiveWhenPresent.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsInCaseInsensitiveWhenPresent.java new file mode 100644 index 000000000..c0e989fc3 --- /dev/null +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsInCaseInsensitiveWhenPresent.java @@ -0,0 +1,76 @@ +/* + * Copyright 2016-2024 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mybatis.dynamic.sql.where.condition; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Objects; +import java.util.function.Predicate; +import java.util.function.UnaryOperator; +import java.util.stream.Collectors; + +import org.mybatis.dynamic.sql.AbstractListValueCondition; +import org.mybatis.dynamic.sql.render.RenderingContext; +import org.mybatis.dynamic.sql.util.StringUtilities; + +public class IsInCaseInsensitiveWhenPresent extends AbstractListValueCondition + implements CaseInsensitiveVisitableCondition { + private static final IsInCaseInsensitiveWhenPresent EMPTY = new IsInCaseInsensitiveWhenPresent(Collections.emptyList()); + + public static IsInCaseInsensitiveWhenPresent empty() { + return EMPTY; + } + + protected IsInCaseInsensitiveWhenPresent(Collection values) { + super(values.stream().filter(Objects::nonNull).collect(Collectors.toList())); + } + + @Override + public boolean shouldRender(RenderingContext renderingContext) { + return !isEmpty(); + } + + @Override + public String operator() { + return "in"; //$NON-NLS-1$ + } + + @Override + public IsInCaseInsensitiveWhenPresent filter(Predicate predicate) { + return filterSupport(predicate, IsInCaseInsensitiveWhenPresent::new, this, IsInCaseInsensitiveWhenPresent::empty); + } + + /** + * If renderable, apply the mapping to each value in the list return a new condition with the mapped values. + * Else return a condition that will not render (this). + * + * @param mapper a mapping function to apply to the values, if renderable + * @return a new condition with mapped values if renderable, otherwise a condition + * that will not render. + */ + public IsInCaseInsensitiveWhenPresent map(UnaryOperator mapper) { + return mapSupport(mapper, IsInCaseInsensitiveWhenPresent::new, IsInCaseInsensitiveWhenPresent::empty); + } + + public static IsInCaseInsensitiveWhenPresent of(String... values) { + return of(Arrays.asList(values)); + } + + public static IsInCaseInsensitiveWhenPresent of(Collection values) { + return new IsInCaseInsensitiveWhenPresent(values).map(StringUtilities::safelyUpperCase); + } +} diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsInWhenPresent.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsInWhenPresent.java new file mode 100644 index 000000000..714e4f61b --- /dev/null +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsInWhenPresent.java @@ -0,0 +1,79 @@ +/* + * Copyright 2016-2024 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mybatis.dynamic.sql.where.condition; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Objects; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +import org.mybatis.dynamic.sql.AbstractListValueCondition; +import org.mybatis.dynamic.sql.render.RenderingContext; + +public class IsInWhenPresent extends AbstractListValueCondition { + private static final IsInWhenPresent EMPTY = new IsInWhenPresent<>(Collections.emptyList()); + + public static IsInWhenPresent empty() { + @SuppressWarnings("unchecked") + IsInWhenPresent t = (IsInWhenPresent) EMPTY; + return t; + } + + protected IsInWhenPresent(Collection values) { + super(values.stream().filter(Objects::nonNull).collect(Collectors.toList())); + } + + @Override + public boolean shouldRender(RenderingContext renderingContext) { + return !isEmpty(); + } + + @Override + public String operator() { + return "in"; //$NON-NLS-1$ + } + + @Override + public IsInWhenPresent filter(Predicate predicate) { + return filterSupport(predicate, IsInWhenPresent::new, this, IsInWhenPresent::empty); + } + + /** + * If renderable, apply the mapping to each value in the list return a new condition with the mapped values. + * Else return a condition that will not render (this). + * + * @param mapper a mapping function to apply to the values, if renderable + * @param type of the new condition + * @return a new condition with mapped values if renderable, otherwise a condition + * that will not render. + */ + public IsInWhenPresent map(Function mapper) { + Function, IsInWhenPresent> constructor = IsInWhenPresent::new; + return mapSupport(mapper, constructor, IsInWhenPresent::empty); + } + + @SafeVarargs + public static IsInWhenPresent of(T... values) { + return of(Arrays.asList(values)); + } + + public static IsInWhenPresent of(Collection values) { + return new IsInWhenPresent<>(values); + } +} diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInCaseInsensitiveWhenPresent.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInCaseInsensitiveWhenPresent.java new file mode 100644 index 000000000..1bafb1660 --- /dev/null +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInCaseInsensitiveWhenPresent.java @@ -0,0 +1,76 @@ +/* + * Copyright 2016-2024 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mybatis.dynamic.sql.where.condition; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Objects; +import java.util.function.Predicate; +import java.util.function.UnaryOperator; +import java.util.stream.Collectors; + +import org.mybatis.dynamic.sql.AbstractListValueCondition; +import org.mybatis.dynamic.sql.render.RenderingContext; +import org.mybatis.dynamic.sql.util.StringUtilities; + +public class IsNotInCaseInsensitiveWhenPresent extends AbstractListValueCondition + implements CaseInsensitiveVisitableCondition { + private static final IsNotInCaseInsensitiveWhenPresent EMPTY = new IsNotInCaseInsensitiveWhenPresent(Collections.emptyList()); + + public static IsNotInCaseInsensitiveWhenPresent empty() { + return EMPTY; + } + + protected IsNotInCaseInsensitiveWhenPresent(Collection values) { + super(values.stream().filter(Objects::nonNull).collect(Collectors.toList())); + } + + @Override + public boolean shouldRender(RenderingContext renderingContext) { + return !isEmpty(); + } + + @Override + public String operator() { + return "not in"; //$NON-NLS-1$ + } + + @Override + public IsNotInCaseInsensitiveWhenPresent filter(Predicate predicate) { + return filterSupport(predicate, IsNotInCaseInsensitiveWhenPresent::new, this, IsNotInCaseInsensitiveWhenPresent::empty); + } + + /** + * If renderable, apply the mapping to each value in the list return a new condition with the mapped values. + * Else return a condition that will not render (this). + * + * @param mapper a mapping function to apply to the values, if renderable + * @return a new condition with mapped values if renderable, otherwise a condition + * that will not render. + */ + public IsNotInCaseInsensitiveWhenPresent map(UnaryOperator mapper) { + return mapSupport(mapper, IsNotInCaseInsensitiveWhenPresent::new, IsNotInCaseInsensitiveWhenPresent::empty); + } + + public static IsNotInCaseInsensitiveWhenPresent of(String... values) { + return of(Arrays.asList(values)); + } + + public static IsNotInCaseInsensitiveWhenPresent of(Collection values) { + return new IsNotInCaseInsensitiveWhenPresent(values).map(StringUtilities::safelyUpperCase); + } +} diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInWhenPresent.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInWhenPresent.java new file mode 100644 index 000000000..4add4a8a9 --- /dev/null +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInWhenPresent.java @@ -0,0 +1,79 @@ +/* + * Copyright 2016-2024 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mybatis.dynamic.sql.where.condition; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Objects; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +import org.mybatis.dynamic.sql.AbstractListValueCondition; +import org.mybatis.dynamic.sql.render.RenderingContext; + +public class IsNotInWhenPresent extends AbstractListValueCondition { + private static final IsNotInWhenPresent EMPTY = new IsNotInWhenPresent<>(Collections.emptyList()); + + public static IsNotInWhenPresent empty() { + @SuppressWarnings("unchecked") + IsNotInWhenPresent t = (IsNotInWhenPresent) EMPTY; + return t; + } + + protected IsNotInWhenPresent(Collection values) { + super(values.stream().filter(Objects::nonNull).collect(Collectors.toList())); + } + + @Override + public boolean shouldRender(RenderingContext renderingContext) { + return !isEmpty(); + } + + @Override + public String operator() { + return "not in"; //$NON-NLS-1$ + } + + @Override + public IsNotInWhenPresent filter(Predicate predicate) { + return filterSupport(predicate, IsNotInWhenPresent::new, this, IsNotInWhenPresent::empty); + } + + /** + * If renderable, apply the mapping to each value in the list return a new condition with the mapped values. + * Else return a condition that will not render (this). + * + * @param mapper a mapping function to apply to the values, if renderable + * @param type of the new condition + * @return a new condition with mapped values if renderable, otherwise a condition + * that will not render. + */ + public IsNotInWhenPresent map(Function mapper) { + Function, IsNotInWhenPresent> constructor = IsNotInWhenPresent::new; + return mapSupport(mapper, constructor, IsNotInWhenPresent::empty); + } + + @SafeVarargs + public static IsNotInWhenPresent of(T... values) { + return of(Arrays.asList(values)); + } + + public static IsNotInWhenPresent of(Collection values) { + return new IsNotInWhenPresent<>(values); + } +} diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt index 11082ae1d..2d9f1e8a1 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt @@ -62,6 +62,8 @@ import org.mybatis.dynamic.sql.where.condition.IsGreaterThanOrEqualToWithSubsele import org.mybatis.dynamic.sql.where.condition.IsGreaterThanWithSubselect import org.mybatis.dynamic.sql.where.condition.IsIn import org.mybatis.dynamic.sql.where.condition.IsInCaseInsensitive +import org.mybatis.dynamic.sql.where.condition.IsInCaseInsensitiveWhenPresent +import org.mybatis.dynamic.sql.where.condition.IsInWhenPresent import org.mybatis.dynamic.sql.where.condition.IsInWithSubselect import org.mybatis.dynamic.sql.where.condition.IsLessThan import org.mybatis.dynamic.sql.where.condition.IsLessThanColumn @@ -77,6 +79,8 @@ import org.mybatis.dynamic.sql.where.condition.IsNotEqualToColumn import org.mybatis.dynamic.sql.where.condition.IsNotEqualToWithSubselect import org.mybatis.dynamic.sql.where.condition.IsNotIn import org.mybatis.dynamic.sql.where.condition.IsNotInCaseInsensitive +import org.mybatis.dynamic.sql.where.condition.IsNotInCaseInsensitiveWhenPresent +import org.mybatis.dynamic.sql.where.condition.IsNotInWhenPresent import org.mybatis.dynamic.sql.where.condition.IsNotInWithSubselect import org.mybatis.dynamic.sql.where.condition.IsNotLike import org.mybatis.dynamic.sql.where.condition.IsNotLikeCaseInsensitive @@ -270,12 +274,12 @@ fun isIn(values: Collection): IsIn = SqlBuilder.isIn(values) fun isIn(subQuery: KotlinSubQueryBuilder.() -> Unit): IsInWithSubselect = SqlBuilder.isIn(KotlinSubQueryBuilder().apply(subQuery)) -fun isInWhenPresent(vararg values: T?): IsIn = isInWhenPresent(values.asList()) +fun isInWhenPresent(vararg values: T?): IsInWhenPresent = isInWhenPresent(values.asList()) @JvmName("isInArrayWhenPresent") -fun isInWhenPresent(values: Array?): IsIn = SqlBuilder.isInWhenPresent(values?.asList()) +fun isInWhenPresent(values: Array?): IsInWhenPresent = SqlBuilder.isInWhenPresent(values?.asList()) -fun isInWhenPresent(values: Collection?): IsIn = SqlBuilder.isInWhenPresent(values) +fun isInWhenPresent(values: Collection?): IsInWhenPresent = SqlBuilder.isInWhenPresent(values) fun isNotIn(vararg values: T & Any): IsNotIn = isNotIn(values.asList()) @@ -287,12 +291,12 @@ fun isNotIn(values: Collection): IsNotIn = SqlBuilder.isNotIn(va fun isNotIn(subQuery: KotlinSubQueryBuilder.() -> Unit): IsNotInWithSubselect = SqlBuilder.isNotIn(KotlinSubQueryBuilder().apply(subQuery)) -fun isNotInWhenPresent(vararg values: T?): IsNotIn = isNotInWhenPresent(values.asList()) +fun isNotInWhenPresent(vararg values: T?): IsNotInWhenPresent = isNotInWhenPresent(values.asList()) @JvmName("isNotInArrayWhenPresent") -fun isNotInWhenPresent(values: Array?): IsNotIn = SqlBuilder.isNotInWhenPresent(values?.asList()) +fun isNotInWhenPresent(values: Array?): IsNotInWhenPresent = SqlBuilder.isNotInWhenPresent(values?.asList()) -fun isNotInWhenPresent(values: Collection?): IsNotIn = SqlBuilder.isNotInWhenPresent(values) +fun isNotInWhenPresent(values: Collection?): IsNotInWhenPresent = SqlBuilder.isNotInWhenPresent(values) fun isBetween(value1: T & Any): BetweenBuilder = BetweenBuilder(value1) @@ -335,14 +339,14 @@ fun isInCaseInsensitive(values: Array): IsInCaseInsensitive = SqlBui fun isInCaseInsensitive(values: Collection): IsInCaseInsensitive = SqlBuilder.isInCaseInsensitive(values) -fun isInCaseInsensitiveWhenPresent(vararg values: String?): IsInCaseInsensitive = +fun isInCaseInsensitiveWhenPresent(vararg values: String?): IsInCaseInsensitiveWhenPresent = isInCaseInsensitiveWhenPresent(values.asList()) @JvmName("isInArrayCaseInsensitiveWhenPresent") -fun isInCaseInsensitiveWhenPresent(values: Array?): IsInCaseInsensitive = +fun isInCaseInsensitiveWhenPresent(values: Array?): IsInCaseInsensitiveWhenPresent = SqlBuilder.isInCaseInsensitiveWhenPresent(values?.asList()) -fun isInCaseInsensitiveWhenPresent(values: Collection?): IsInCaseInsensitive = +fun isInCaseInsensitiveWhenPresent(values: Collection?): IsInCaseInsensitiveWhenPresent = SqlBuilder.isInCaseInsensitiveWhenPresent(values) fun isNotInCaseInsensitive(vararg values: String): IsNotInCaseInsensitive = isNotInCaseInsensitive(values.asList()) @@ -354,14 +358,14 @@ fun isNotInCaseInsensitive(values: Array): IsNotInCaseInsensitive = fun isNotInCaseInsensitive(values: Collection): IsNotInCaseInsensitive = SqlBuilder.isNotInCaseInsensitive(values) -fun isNotInCaseInsensitiveWhenPresent(vararg values: String?): IsNotInCaseInsensitive = +fun isNotInCaseInsensitiveWhenPresent(vararg values: String?): IsNotInCaseInsensitiveWhenPresent = isNotInCaseInsensitiveWhenPresent(values.asList()) @JvmName("isNotInArrayCaseInsensitiveWhenPresent") -fun isNotInCaseInsensitiveWhenPresent(values: Array?): IsNotInCaseInsensitive = +fun isNotInCaseInsensitiveWhenPresent(values: Array?): IsNotInCaseInsensitiveWhenPresent = SqlBuilder.isNotInCaseInsensitiveWhenPresent(values?.asList()) -fun isNotInCaseInsensitiveWhenPresent(values: Collection?): IsNotInCaseInsensitive = +fun isNotInCaseInsensitiveWhenPresent(values: Collection?): IsNotInCaseInsensitiveWhenPresent = SqlBuilder.isNotInCaseInsensitiveWhenPresent(values) // order by support From 0c27e97d709f70cb212bae5bae96cd3636a2c474 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Wed, 15 May 2024 10:55:54 -0400 Subject: [PATCH 03/11] Make the Tests Pass --- src/test/java/examples/animal/data/AnimalDataTest.java | 7 +++++-- .../OptionalConditionsWithPredicatesAnimalDataTest.java | 4 ++-- .../mybatis/dynamic/sql/select/SelectStatementTest.java | 4 ++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/test/java/examples/animal/data/AnimalDataTest.java b/src/test/java/examples/animal/data/AnimalDataTest.java index 137281acf..bf1b6e142 100644 --- a/src/test/java/examples/animal/data/AnimalDataTest.java +++ b/src/test/java/examples/animal/data/AnimalDataTest.java @@ -672,7 +672,7 @@ void testInConditionWithEventuallyEmptyList() { SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight) .from(animalData) - .where(id, isIn(null, 22, null).filter(Objects::nonNull).filter(i -> i != 22)) + .where(id, isInWhenPresent(null, 22, null).filter(i -> i != 22)) .configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true)) .build() .render(RenderingStrategies.MYBATIS3); @@ -694,6 +694,7 @@ void testInConditionWithEventuallyEmptyListForceRendering() { SelectModel selectModel = select(id, animalName, bodyWeight, brainWeight) .from(animalData) .where(id, isIn(inValues).filter(Objects::nonNull).filter(i -> i != 22)) + .configureStatement(c -> c.setEmptyListConditionRenderingAllowed(false)) .build(); assertThatExceptionOfType(NonRenderingWhereClauseException.class).isThrownBy(() -> @@ -706,6 +707,7 @@ void testInConditionWithEmptyList() { SelectModel selectModel = select(id, animalName, bodyWeight, brainWeight) .from(animalData) .where(id, isIn(Collections.emptyList())) + .configureStatement(c -> c.setEmptyListConditionRenderingAllowed(false)) .build(); assertThatExceptionOfType(NonRenderingWhereClauseException.class).isThrownBy(() -> @@ -784,7 +786,7 @@ void testNotInConditionWithEventuallyEmptyList() { SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight) .from(animalData) - .where(id, isNotIn(null, 22, null).filter(Objects::nonNull).filter(i -> i != 22)) + .where(id, isNotInWhenPresent(null, 22, null).filter(i -> i != 22)) .configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true)) .build() .render(RenderingStrategies.MYBATIS3); @@ -802,6 +804,7 @@ void testNotInConditionWithEventuallyEmptyListForceRendering() { .from(animalData) .where(id, isNotIn(null, 22, null) .filter(Objects::nonNull).filter(i -> i != 22)) + .configureStatement(c -> c.setEmptyListConditionRenderingAllowed(false)) .build(); assertThatExceptionOfType(NonRenderingWhereClauseException.class).isThrownBy(() -> diff --git a/src/test/java/examples/animal/data/OptionalConditionsWithPredicatesAnimalDataTest.java b/src/test/java/examples/animal/data/OptionalConditionsWithPredicatesAnimalDataTest.java index 079c79e00..2cfaab8bb 100644 --- a/src/test/java/examples/animal/data/OptionalConditionsWithPredicatesAnimalDataTest.java +++ b/src/test/java/examples/animal/data/OptionalConditionsWithPredicatesAnimalDataTest.java @@ -522,7 +522,7 @@ void testIsInCaseInsensitiveWhenWithNoValues() { AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class); SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight) .from(animalData) - .where(animalName, isInCaseInsensitive()) + .where(animalName, isInCaseInsensitiveWhenPresent()) .and(id, isLessThanOrEqualTo(10)) .orderBy(id) .build() @@ -602,7 +602,7 @@ void testIsNotInCaseInsensitiveWhenWithNoValues() { AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class); SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight) .from(animalData) - .where(animalName, isNotInCaseInsensitive()) + .where(animalName, isNotInCaseInsensitiveWhenPresent()) .and(id, isLessThanOrEqualTo(10)) .orderBy(id) .build() diff --git a/src/test/java/org/mybatis/dynamic/sql/select/SelectStatementTest.java b/src/test/java/org/mybatis/dynamic/sql/select/SelectStatementTest.java index 9fd066a42..2f231cf68 100644 --- a/src/test/java/org/mybatis/dynamic/sql/select/SelectStatementTest.java +++ b/src/test/java/org/mybatis/dynamic/sql/select/SelectStatementTest.java @@ -291,6 +291,7 @@ void testInEmptyList() { SelectModel selectModel = select(column1, column3) .from(table, "a") .where(column3, isIn(emptyList)) + .configureStatement(c -> c.setEmptyListConditionRenderingAllowed(false)) .build(); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> @@ -304,6 +305,7 @@ void testNotInEmptyList() { SelectModel selectModel = select(column1, column3) .from(table, "a") .where(column3, isNotIn(emptyList)) + .configureStatement(c -> c.setEmptyListConditionRenderingAllowed(false)) .build(); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> @@ -329,6 +331,7 @@ void testInCaseInsensitiveEmptyList() { SelectModel selectModel = select(column1, column3) .from(table, "a") .where(column3, isInCaseInsensitive(Collections.emptyList())) + .configureStatement(c -> c.setEmptyListConditionRenderingAllowed(false)) .build(); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> @@ -366,6 +369,7 @@ void testNotInCaseInsensitiveEmptyList() { SelectModel selectModel = select(column1, column3) .from(table, "a") .where(column3, isNotInCaseInsensitive(Collections.emptyList())) + .configureStatement(c -> c.setEmptyListConditionRenderingAllowed(false)) .build(); assertThatExceptionOfType(NonRenderingWhereClauseException.class).isThrownBy(() -> From 8ce5b5b86f1bdede5235d2bc23703815165022aa Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Wed, 15 May 2024 12:51:29 -0400 Subject: [PATCH 04/11] Remove configuration for empty list rendering With this change, the "in" conditions will always render. The "in when present" conditions will only render if the input collection is non-null and contains at least one non-null value. --- .../sql/AbstractListValueCondition.java | 21 ++++--------------- .../org/mybatis/dynamic/sql/SqlBuilder.java | 9 ++++---- .../configuration/GlobalConfiguration.java | 8 ------- .../configuration/StatementConfiguration.java | 19 ----------------- .../dynamic/sql/render/RenderingContext.java | 4 ---- .../dynamic/sql/where/condition/IsIn.java | 15 ++++++++----- .../where/condition/IsInCaseInsensitive.java | 15 ++++++++----- .../IsInCaseInsensitiveWhenPresent.java | 15 ++++--------- .../sql/where/condition/IsInWhenPresent.java | 15 ++++--------- .../dynamic/sql/where/condition/IsNotIn.java | 15 ++++++++----- .../condition/IsNotInCaseInsensitive.java | 15 ++++++++----- .../IsNotInCaseInsensitiveWhenPresent.java | 15 ++++--------- .../where/condition/IsNotInWhenPresent.java | 15 ++++--------- .../examples/animal/data/AnimalDataTest.java | 9 +++----- .../sql/select/SelectStatementTest.java | 12 ++++------- .../mybatis3/canonical/PersonMapperTest.kt | 1 - 16 files changed, 72 insertions(+), 131 deletions(-) diff --git a/src/main/java/org/mybatis/dynamic/sql/AbstractListValueCondition.java b/src/main/java/org/mybatis/dynamic/sql/AbstractListValueCondition.java index e70b1e611..104859de8 100644 --- a/src/main/java/org/mybatis/dynamic/sql/AbstractListValueCondition.java +++ b/src/main/java/org/mybatis/dynamic/sql/AbstractListValueCondition.java @@ -23,8 +23,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.mybatis.dynamic.sql.render.RenderingContext; - public abstract class AbstractListValueCondition implements VisitableCondition { protected final Collection values; @@ -41,15 +39,6 @@ public boolean isEmpty() { return values.isEmpty(); } - @Override - public boolean shouldRender(RenderingContext renderingContext) { - if (isEmpty()) { - return renderingContext.isEmptyListConditionRenderingAllowed(); - } else { - return true; - } - } - @Override public R accept(ConditionVisitor visitor) { return visitor.visit(this); @@ -85,14 +74,12 @@ protected > S mapSupport(Function filter(Predicate predicate); diff --git a/src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java b/src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java index 6516696f6..cef5eae5f 100644 --- a/src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java +++ b/src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java @@ -769,7 +769,7 @@ static IsInWithSubselect isIn(Buildable selectModelBuilder) @SafeVarargs static IsInWhenPresent isInWhenPresent(T... values) { - return IsInWhenPresent.of(values); + return values == null ? IsInWhenPresent.empty() : IsInWhenPresent.of(values); } static IsInWhenPresent isInWhenPresent(Collection values) { @@ -791,7 +791,7 @@ static IsNotInWithSubselect isNotIn(Buildable selectModelBui @SafeVarargs static IsNotInWhenPresent isNotInWhenPresent(T... values) { - return IsNotInWhenPresent.of(values); + return values == null ? IsNotInWhenPresent.empty() : IsNotInWhenPresent.of(values); } static IsNotInWhenPresent isNotInWhenPresent(Collection values) { @@ -914,7 +914,7 @@ static IsInCaseInsensitive isInCaseInsensitive(Collection values) { } static IsInCaseInsensitiveWhenPresent isInCaseInsensitiveWhenPresent(String... values) { - return IsInCaseInsensitiveWhenPresent.of(values); + return values == null ? IsInCaseInsensitiveWhenPresent.empty() : IsInCaseInsensitiveWhenPresent.of(values); } static IsInCaseInsensitiveWhenPresent isInCaseInsensitiveWhenPresent(Collection values) { @@ -930,7 +930,8 @@ static IsNotInCaseInsensitive isNotInCaseInsensitive(Collection values) } static IsNotInCaseInsensitiveWhenPresent isNotInCaseInsensitiveWhenPresent(String... values) { - return IsNotInCaseInsensitiveWhenPresent.of(values); + return values == null ? IsNotInCaseInsensitiveWhenPresent.empty() : + IsNotInCaseInsensitiveWhenPresent.of(values); } static IsNotInCaseInsensitiveWhenPresent isNotInCaseInsensitiveWhenPresent(Collection values) { diff --git a/src/main/java/org/mybatis/dynamic/sql/configuration/GlobalConfiguration.java b/src/main/java/org/mybatis/dynamic/sql/configuration/GlobalConfiguration.java index 7beaab9d3..8e7054d78 100644 --- a/src/main/java/org/mybatis/dynamic/sql/configuration/GlobalConfiguration.java +++ b/src/main/java/org/mybatis/dynamic/sql/configuration/GlobalConfiguration.java @@ -26,7 +26,6 @@ public class GlobalConfiguration { public static final String CONFIGURATION_FILE_PROPERTY = "mybatis-dynamic-sql.configurationFile"; //$NON-NLS-1$ private static final String DEFAULT_PROPERTY_FILE = "mybatis-dynamic-sql.properties"; //$NON-NLS-1$ private boolean isNonRenderingWhereClauseAllowed = false; - private boolean isEmptyListConditionRenderingAllowed = true; private final Properties properties = new Properties(); public GlobalConfiguration() { @@ -66,16 +65,9 @@ void loadProperties(InputStream inputStream, String propertyFile) { private void initializeKnownProperties() { String value = properties.getProperty("nonRenderingWhereClauseAllowed", "false"); //$NON-NLS-1$ //$NON-NLS-2$ isNonRenderingWhereClauseAllowed = Boolean.parseBoolean(value); - - value = properties.getProperty("emptyListConditionRenderingAllowed", "true"); //$NON-NLS-1$ //$NON-NLS-2$ - isEmptyListConditionRenderingAllowed = Boolean.parseBoolean(value); } public boolean isIsNonRenderingWhereClauseAllowed() { return isNonRenderingWhereClauseAllowed; } - - public boolean isEmptyListConditionRenderingAllowed() { - return isEmptyListConditionRenderingAllowed; - } } diff --git a/src/main/java/org/mybatis/dynamic/sql/configuration/StatementConfiguration.java b/src/main/java/org/mybatis/dynamic/sql/configuration/StatementConfiguration.java index 2828eb050..bb5641f3f 100644 --- a/src/main/java/org/mybatis/dynamic/sql/configuration/StatementConfiguration.java +++ b/src/main/java/org/mybatis/dynamic/sql/configuration/StatementConfiguration.java @@ -25,13 +25,6 @@ * Configurable behaviors are detailed below: * *
- *
emptyListConditionRenderingAllowed
- *
If false (default), the framework will not render list conditions that are empty in a where clause. - * This is beneficial in that it will not allow the library to generate invalid SQL, but it has a - * potentially dangerous side effect where a statement could be generated that impacts more rows - * then expected. If true, an empty list will be rendered as "in ()", "not in ()", etc. which will likely - * cause an SQLException at runtime. - *
*
nonRenderingWhereClauseAllowed
*
If false (default), the framework will throw a {@link NonRenderingWhereClauseException} * if a where clause is specified in the statement, but it fails to render because all @@ -51,9 +44,6 @@ public class StatementConfiguration { private boolean isNonRenderingWhereClauseAllowed = GlobalContext.getConfiguration().isIsNonRenderingWhereClauseAllowed(); - private boolean isEmptyListConditionRenderingAllowed = - GlobalContext.getConfiguration().isEmptyListConditionRenderingAllowed(); - public boolean isNonRenderingWhereClauseAllowed() { return isNonRenderingWhereClauseAllowed; } @@ -62,13 +52,4 @@ public StatementConfiguration setNonRenderingWhereClauseAllowed(boolean nonRende isNonRenderingWhereClauseAllowed = nonRenderingWhereClauseAllowed; return this; } - - public boolean isEmptyListConditionRenderingAllowed() { - return isEmptyListConditionRenderingAllowed; - } - - public StatementConfiguration setEmptyListConditionRenderingAllowed(boolean emptyListConditionRenderingAllowed) { - isEmptyListConditionRenderingAllowed = emptyListConditionRenderingAllowed; - return this; - } } diff --git a/src/main/java/org/mybatis/dynamic/sql/render/RenderingContext.java b/src/main/java/org/mybatis/dynamic/sql/render/RenderingContext.java index d19a94c50..a23c8d07a 100644 --- a/src/main/java/org/mybatis/dynamic/sql/render/RenderingContext.java +++ b/src/main/java/org/mybatis/dynamic/sql/render/RenderingContext.java @@ -101,10 +101,6 @@ public boolean isNonRenderingClauseAllowed() { return statementConfiguration.isNonRenderingWhereClauseAllowed(); } - public boolean isEmptyListConditionRenderingAllowed() { - return statementConfiguration.isEmptyListConditionRenderingAllowed(); - } - /** * Create a new rendering context based on this, with the table alias calculator modified to include the * specified child table alias calculator. This is used by the query expression renderer when the alias calculator diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsIn.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsIn.java index 044c294f6..ce00047b5 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsIn.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsIn.java @@ -22,6 +22,7 @@ import java.util.function.Predicate; import org.mybatis.dynamic.sql.AbstractListValueCondition; +import org.mybatis.dynamic.sql.render.RenderingContext; public class IsIn extends AbstractListValueCondition { private static final IsIn EMPTY = new IsIn<>(Collections.emptyList()); @@ -36,6 +37,11 @@ protected IsIn(Collection values) { super(values); } + @Override + public boolean shouldRender(RenderingContext renderingContext) { + return true; + } + @Override public String operator() { return "in"; //$NON-NLS-1$ @@ -47,13 +53,12 @@ public IsIn filter(Predicate predicate) { } /** - * If renderable, apply the mapping to each value in the list return a new condition with the mapped values. - * Else return a condition that will not render (this). + * If not empty, apply the mapping to each value in the list return a new condition with the mapped values. + * Else return an empty condition (this). * - * @param mapper a mapping function to apply to the values, if renderable + * @param mapper a mapping function to apply to the values, if not empty * @param type of the new condition - * @return a new condition with mapped values if renderable, otherwise a condition - * that will not render. + * @return a new condition with mapped values if renderable, otherwise an empty condition */ public IsIn map(Function mapper) { Function, IsIn> constructor = IsIn::new; diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsInCaseInsensitive.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsInCaseInsensitive.java index 05c916234..3fe30c1ef 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsInCaseInsensitive.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsInCaseInsensitive.java @@ -22,6 +22,7 @@ import java.util.function.UnaryOperator; import org.mybatis.dynamic.sql.AbstractListValueCondition; +import org.mybatis.dynamic.sql.render.RenderingContext; import org.mybatis.dynamic.sql.util.StringUtilities; public class IsInCaseInsensitive extends AbstractListValueCondition @@ -36,6 +37,11 @@ protected IsInCaseInsensitive(Collection values) { super(values); } + @Override + public boolean shouldRender(RenderingContext renderingContext) { + return true; + } + @Override public String operator() { return "in"; //$NON-NLS-1$ @@ -47,12 +53,11 @@ public IsInCaseInsensitive filter(Predicate predicate) { } /** - * If renderable, apply the mapping to each value in the list return a new condition with the mapped values. - * Else return a condition that will not render (this). + * If not empty, apply the mapping to each value in the list return a new condition with the mapped values. + * Else return an empty condition (this). * - * @param mapper a mapping function to apply to the values, if renderable - * @return a new condition with mapped values if renderable, otherwise a condition - * that will not render. + * @param mapper a mapping function to apply to the values, if not empty + * @return a new condition with mapped values if renderable, otherwise an empty condition */ public IsInCaseInsensitive map(UnaryOperator mapper) { return mapSupport(mapper, IsInCaseInsensitive::new, IsInCaseInsensitive::empty); diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsInCaseInsensitiveWhenPresent.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsInCaseInsensitiveWhenPresent.java index c0e989fc3..b123d30c5 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsInCaseInsensitiveWhenPresent.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsInCaseInsensitiveWhenPresent.java @@ -24,7 +24,6 @@ import java.util.stream.Collectors; import org.mybatis.dynamic.sql.AbstractListValueCondition; -import org.mybatis.dynamic.sql.render.RenderingContext; import org.mybatis.dynamic.sql.util.StringUtilities; public class IsInCaseInsensitiveWhenPresent extends AbstractListValueCondition @@ -39,11 +38,6 @@ protected IsInCaseInsensitiveWhenPresent(Collection values) { super(values.stream().filter(Objects::nonNull).collect(Collectors.toList())); } - @Override - public boolean shouldRender(RenderingContext renderingContext) { - return !isEmpty(); - } - @Override public String operator() { return "in"; //$NON-NLS-1$ @@ -55,12 +49,11 @@ public IsInCaseInsensitiveWhenPresent filter(Predicate predicate } /** - * If renderable, apply the mapping to each value in the list return a new condition with the mapped values. - * Else return a condition that will not render (this). + * If not empty, apply the mapping to each value in the list return a new condition with the mapped values. + * Else return an empty condition (this). * - * @param mapper a mapping function to apply to the values, if renderable - * @return a new condition with mapped values if renderable, otherwise a condition - * that will not render. + * @param mapper a mapping function to apply to the values, if not empty + * @return a new condition with mapped values if renderable, otherwise an empty condition */ public IsInCaseInsensitiveWhenPresent map(UnaryOperator mapper) { return mapSupport(mapper, IsInCaseInsensitiveWhenPresent::new, IsInCaseInsensitiveWhenPresent::empty); diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsInWhenPresent.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsInWhenPresent.java index 714e4f61b..fc2994ea7 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsInWhenPresent.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsInWhenPresent.java @@ -24,7 +24,6 @@ import java.util.stream.Collectors; import org.mybatis.dynamic.sql.AbstractListValueCondition; -import org.mybatis.dynamic.sql.render.RenderingContext; public class IsInWhenPresent extends AbstractListValueCondition { private static final IsInWhenPresent EMPTY = new IsInWhenPresent<>(Collections.emptyList()); @@ -39,11 +38,6 @@ protected IsInWhenPresent(Collection values) { super(values.stream().filter(Objects::nonNull).collect(Collectors.toList())); } - @Override - public boolean shouldRender(RenderingContext renderingContext) { - return !isEmpty(); - } - @Override public String operator() { return "in"; //$NON-NLS-1$ @@ -55,13 +49,12 @@ public IsInWhenPresent filter(Predicate predicate) { } /** - * If renderable, apply the mapping to each value in the list return a new condition with the mapped values. - * Else return a condition that will not render (this). + * If not empty, apply the mapping to each value in the list return a new condition with the mapped values. + * Else return an empty condition (this). * - * @param mapper a mapping function to apply to the values, if renderable + * @param mapper a mapping function to apply to the values, if not empty * @param type of the new condition - * @return a new condition with mapped values if renderable, otherwise a condition - * that will not render. + * @return a new condition with mapped values if renderable, otherwise an empty condition */ public IsInWhenPresent map(Function mapper) { Function, IsInWhenPresent> constructor = IsInWhenPresent::new; diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotIn.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotIn.java index 1bb1e1067..dc7358b2a 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotIn.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotIn.java @@ -22,6 +22,7 @@ import java.util.function.Predicate; import org.mybatis.dynamic.sql.AbstractListValueCondition; +import org.mybatis.dynamic.sql.render.RenderingContext; public class IsNotIn extends AbstractListValueCondition { private static final IsNotIn EMPTY = new IsNotIn<>(Collections.emptyList()); @@ -36,6 +37,11 @@ protected IsNotIn(Collection values) { super(values); } + @Override + public boolean shouldRender(RenderingContext renderingContext) { + return true; + } + @Override public String operator() { return "not in"; //$NON-NLS-1$ @@ -47,13 +53,12 @@ public IsNotIn filter(Predicate predicate) { } /** - * If renderable, apply the mapping to each value in the list return a new condition with the mapped values. - * Else return a condition that will not render (this). + * If not empty, apply the mapping to each value in the list return a new condition with the mapped values. + * Else return an empty condition (this). * - * @param mapper a mapping function to apply to the values, if renderable + * @param mapper a mapping function to apply to the values, if not empty * @param type of the new condition - * @return a new condition with mapped values if renderable, otherwise a condition - * that will not render. + * @return a new condition with mapped values if renderable, otherwise an empty condition */ public IsNotIn map(Function mapper) { Function, IsNotIn> constructor = IsNotIn::new; diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInCaseInsensitive.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInCaseInsensitive.java index 2ccb065f7..fa43af0b6 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInCaseInsensitive.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInCaseInsensitive.java @@ -22,6 +22,7 @@ import java.util.function.UnaryOperator; import org.mybatis.dynamic.sql.AbstractListValueCondition; +import org.mybatis.dynamic.sql.render.RenderingContext; import org.mybatis.dynamic.sql.util.StringUtilities; public class IsNotInCaseInsensitive extends AbstractListValueCondition @@ -36,6 +37,11 @@ protected IsNotInCaseInsensitive(Collection values) { super(values); } + @Override + public boolean shouldRender(RenderingContext renderingContext) { + return true; + } + @Override public String operator() { return "not in"; //$NON-NLS-1$ @@ -47,12 +53,11 @@ public IsNotInCaseInsensitive filter(Predicate predicate) { } /** - * If renderable, apply the mapping to each value in the list return a new condition with the mapped values. - * Else return a condition that will not render (this). + * If not empty, apply the mapping to each value in the list return a new condition with the mapped values. + * Else return an empty condition (this). * - * @param mapper a mapping function to apply to the values, if renderable - * @return a new condition with mapped values if renderable, otherwise a condition - * that will not render. + * @param mapper a mapping function to apply to the values, if not empty + * @return a new condition with mapped values if renderable, otherwise an empty condition */ public IsNotInCaseInsensitive map(UnaryOperator mapper) { return mapSupport(mapper, IsNotInCaseInsensitive::new, IsNotInCaseInsensitive::empty); diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInCaseInsensitiveWhenPresent.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInCaseInsensitiveWhenPresent.java index 1bafb1660..58f0b347e 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInCaseInsensitiveWhenPresent.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInCaseInsensitiveWhenPresent.java @@ -24,7 +24,6 @@ import java.util.stream.Collectors; import org.mybatis.dynamic.sql.AbstractListValueCondition; -import org.mybatis.dynamic.sql.render.RenderingContext; import org.mybatis.dynamic.sql.util.StringUtilities; public class IsNotInCaseInsensitiveWhenPresent extends AbstractListValueCondition @@ -39,11 +38,6 @@ protected IsNotInCaseInsensitiveWhenPresent(Collection values) { super(values.stream().filter(Objects::nonNull).collect(Collectors.toList())); } - @Override - public boolean shouldRender(RenderingContext renderingContext) { - return !isEmpty(); - } - @Override public String operator() { return "not in"; //$NON-NLS-1$ @@ -55,12 +49,11 @@ public IsNotInCaseInsensitiveWhenPresent filter(Predicate predic } /** - * If renderable, apply the mapping to each value in the list return a new condition with the mapped values. - * Else return a condition that will not render (this). + * If not empty, apply the mapping to each value in the list return a new condition with the mapped values. + * Else return an empty condition (this). * - * @param mapper a mapping function to apply to the values, if renderable - * @return a new condition with mapped values if renderable, otherwise a condition - * that will not render. + * @param mapper a mapping function to apply to the values, if not empty + * @return a new condition with mapped values if renderable, otherwise an empty condition */ public IsNotInCaseInsensitiveWhenPresent map(UnaryOperator mapper) { return mapSupport(mapper, IsNotInCaseInsensitiveWhenPresent::new, IsNotInCaseInsensitiveWhenPresent::empty); diff --git a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInWhenPresent.java b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInWhenPresent.java index 4add4a8a9..8115413ef 100644 --- a/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInWhenPresent.java +++ b/src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotInWhenPresent.java @@ -24,7 +24,6 @@ import java.util.stream.Collectors; import org.mybatis.dynamic.sql.AbstractListValueCondition; -import org.mybatis.dynamic.sql.render.RenderingContext; public class IsNotInWhenPresent extends AbstractListValueCondition { private static final IsNotInWhenPresent EMPTY = new IsNotInWhenPresent<>(Collections.emptyList()); @@ -39,11 +38,6 @@ protected IsNotInWhenPresent(Collection values) { super(values.stream().filter(Objects::nonNull).collect(Collectors.toList())); } - @Override - public boolean shouldRender(RenderingContext renderingContext) { - return !isEmpty(); - } - @Override public String operator() { return "not in"; //$NON-NLS-1$ @@ -55,13 +49,12 @@ public IsNotInWhenPresent filter(Predicate predicate) { } /** - * If renderable, apply the mapping to each value in the list return a new condition with the mapped values. - * Else return a condition that will not render (this). + * If not empty, apply the mapping to each value in the list return a new condition with the mapped values. + * Else return an empty condition (this). * - * @param mapper a mapping function to apply to the values, if renderable + * @param mapper a mapping function to apply to the values, if not empty * @param type of the new condition - * @return a new condition with mapped values if renderable, otherwise a condition - * that will not render. + * @return a new condition with mapped values if renderable, otherwise an empty condition */ public IsNotInWhenPresent map(Function mapper) { Function, IsNotInWhenPresent> constructor = IsNotInWhenPresent::new; diff --git a/src/test/java/examples/animal/data/AnimalDataTest.java b/src/test/java/examples/animal/data/AnimalDataTest.java index bf1b6e142..a051434dc 100644 --- a/src/test/java/examples/animal/data/AnimalDataTest.java +++ b/src/test/java/examples/animal/data/AnimalDataTest.java @@ -693,8 +693,7 @@ void testInConditionWithEventuallyEmptyListForceRendering() { SelectModel selectModel = select(id, animalName, bodyWeight, brainWeight) .from(animalData) - .where(id, isIn(inValues).filter(Objects::nonNull).filter(i -> i != 22)) - .configureStatement(c -> c.setEmptyListConditionRenderingAllowed(false)) + .where(id, isInWhenPresent(inValues).filter(Objects::nonNull).filter(i -> i != 22)) .build(); assertThatExceptionOfType(NonRenderingWhereClauseException.class).isThrownBy(() -> @@ -706,8 +705,7 @@ void testInConditionWithEventuallyEmptyListForceRendering() { void testInConditionWithEmptyList() { SelectModel selectModel = select(id, animalName, bodyWeight, brainWeight) .from(animalData) - .where(id, isIn(Collections.emptyList())) - .configureStatement(c -> c.setEmptyListConditionRenderingAllowed(false)) + .where(id, isInWhenPresent(Collections.emptyList())) .build(); assertThatExceptionOfType(NonRenderingWhereClauseException.class).isThrownBy(() -> @@ -802,9 +800,8 @@ void testNotInConditionWithEventuallyEmptyList() { void testNotInConditionWithEventuallyEmptyListForceRendering() { SelectModel selectModel = select(id, animalName, bodyWeight, brainWeight) .from(animalData) - .where(id, isNotIn(null, 22, null) + .where(id, isNotInWhenPresent(null, 22, null) .filter(Objects::nonNull).filter(i -> i != 22)) - .configureStatement(c -> c.setEmptyListConditionRenderingAllowed(false)) .build(); assertThatExceptionOfType(NonRenderingWhereClauseException.class).isThrownBy(() -> diff --git a/src/test/java/org/mybatis/dynamic/sql/select/SelectStatementTest.java b/src/test/java/org/mybatis/dynamic/sql/select/SelectStatementTest.java index 2f231cf68..91ca56390 100644 --- a/src/test/java/org/mybatis/dynamic/sql/select/SelectStatementTest.java +++ b/src/test/java/org/mybatis/dynamic/sql/select/SelectStatementTest.java @@ -290,8 +290,7 @@ void testInEmptyList() { List emptyList = Collections.emptyList(); SelectModel selectModel = select(column1, column3) .from(table, "a") - .where(column3, isIn(emptyList)) - .configureStatement(c -> c.setEmptyListConditionRenderingAllowed(false)) + .where(column3, isInWhenPresent(emptyList)) .build(); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> @@ -304,8 +303,7 @@ void testNotInEmptyList() { List emptyList = Collections.emptyList(); SelectModel selectModel = select(column1, column3) .from(table, "a") - .where(column3, isNotIn(emptyList)) - .configureStatement(c -> c.setEmptyListConditionRenderingAllowed(false)) + .where(column3, isNotInWhenPresent(emptyList)) .build(); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> @@ -330,8 +328,7 @@ void testInWhenPresentEmptyList() { void testInCaseInsensitiveEmptyList() { SelectModel selectModel = select(column1, column3) .from(table, "a") - .where(column3, isInCaseInsensitive(Collections.emptyList())) - .configureStatement(c -> c.setEmptyListConditionRenderingAllowed(false)) + .where(column3, isInCaseInsensitiveWhenPresent(Collections.emptyList())) .build(); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> @@ -368,8 +365,7 @@ void testNotInWhenPresentEmptyList() { void testNotInCaseInsensitiveEmptyList() { SelectModel selectModel = select(column1, column3) .from(table, "a") - .where(column3, isNotInCaseInsensitive(Collections.emptyList())) - .configureStatement(c -> c.setEmptyListConditionRenderingAllowed(false)) + .where(column3, isNotInCaseInsensitiveWhenPresent(Collections.emptyList())) .build(); assertThatExceptionOfType(NonRenderingWhereClauseException.class).isThrownBy(() -> diff --git a/src/test/kotlin/examples/kotlin/mybatis3/canonical/PersonMapperTest.kt b/src/test/kotlin/examples/kotlin/mybatis3/canonical/PersonMapperTest.kt index a0774bdc6..e36174be6 100644 --- a/src/test/kotlin/examples/kotlin/mybatis3/canonical/PersonMapperTest.kt +++ b/src/test/kotlin/examples/kotlin/mybatis3/canonical/PersonMapperTest.kt @@ -911,7 +911,6 @@ class PersonMapperTest { val selectStatement = select(id, firstName, lastName, birthDate, employed, occupation, addressId) { from(person) where { id isIn emptyList() } - configureStatement { isEmptyListConditionRenderingAllowed = true } } val expected = "select id, first_name, last_name, birth_date, employed, occupation, address_id from Person " + From c154eab4a8dc36c849a64723922a382b061101b3 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Thu, 16 May 2024 10:25:32 -0400 Subject: [PATCH 05/11] Remove unnecessary if statements --- src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java b/src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java index cef5eae5f..6516696f6 100644 --- a/src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java +++ b/src/main/java/org/mybatis/dynamic/sql/SqlBuilder.java @@ -769,7 +769,7 @@ static IsInWithSubselect isIn(Buildable selectModelBuilder) @SafeVarargs static IsInWhenPresent isInWhenPresent(T... values) { - return values == null ? IsInWhenPresent.empty() : IsInWhenPresent.of(values); + return IsInWhenPresent.of(values); } static IsInWhenPresent isInWhenPresent(Collection values) { @@ -791,7 +791,7 @@ static IsNotInWithSubselect isNotIn(Buildable selectModelBui @SafeVarargs static IsNotInWhenPresent isNotInWhenPresent(T... values) { - return values == null ? IsNotInWhenPresent.empty() : IsNotInWhenPresent.of(values); + return IsNotInWhenPresent.of(values); } static IsNotInWhenPresent isNotInWhenPresent(Collection values) { @@ -914,7 +914,7 @@ static IsInCaseInsensitive isInCaseInsensitive(Collection values) { } static IsInCaseInsensitiveWhenPresent isInCaseInsensitiveWhenPresent(String... values) { - return values == null ? IsInCaseInsensitiveWhenPresent.empty() : IsInCaseInsensitiveWhenPresent.of(values); + return IsInCaseInsensitiveWhenPresent.of(values); } static IsInCaseInsensitiveWhenPresent isInCaseInsensitiveWhenPresent(Collection values) { @@ -930,8 +930,7 @@ static IsNotInCaseInsensitive isNotInCaseInsensitive(Collection values) } static IsNotInCaseInsensitiveWhenPresent isNotInCaseInsensitiveWhenPresent(String... values) { - return values == null ? IsNotInCaseInsensitiveWhenPresent.empty() : - IsNotInCaseInsensitiveWhenPresent.of(values); + return IsNotInCaseInsensitiveWhenPresent.of(values); } static IsNotInCaseInsensitiveWhenPresent isNotInCaseInsensitiveWhenPresent(Collection values) { From 7634e5facfca686b042c068d3ef7604ddb4e019e Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Thu, 16 May 2024 17:15:30 -0400 Subject: [PATCH 06/11] Tests for various rendering scenarios and coverage --- .../data/VariousListConditionsTest.java | 439 ++++++++++++++++++ 1 file changed, 439 insertions(+) create mode 100644 src/test/java/examples/animal/data/VariousListConditionsTest.java diff --git a/src/test/java/examples/animal/data/VariousListConditionsTest.java b/src/test/java/examples/animal/data/VariousListConditionsTest.java new file mode 100644 index 000000000..469b64718 --- /dev/null +++ b/src/test/java/examples/animal/data/VariousListConditionsTest.java @@ -0,0 +1,439 @@ +/* + * Copyright 2016-2024 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package examples.animal.data; + +import static examples.animal.data.AnimalDataDynamicSqlSupport.animalData; +import static examples.animal.data.AnimalDataDynamicSqlSupport.animalName; +import static examples.animal.data.AnimalDataDynamicSqlSupport.id; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.mybatis.dynamic.sql.SqlBuilder.isIn; +import static org.mybatis.dynamic.sql.SqlBuilder.isInCaseInsensitive; +import static org.mybatis.dynamic.sql.SqlBuilder.isInCaseInsensitiveWhenPresent; +import static org.mybatis.dynamic.sql.SqlBuilder.isInWhenPresent; +import static org.mybatis.dynamic.sql.SqlBuilder.isNotIn; +import static org.mybatis.dynamic.sql.SqlBuilder.isNotInCaseInsensitive; +import static org.mybatis.dynamic.sql.SqlBuilder.isNotInCaseInsensitiveWhenPresent; +import static org.mybatis.dynamic.sql.SqlBuilder.isNotInWhenPresent; +import static org.mybatis.dynamic.sql.SqlBuilder.select; + +import java.io.InputStream; +import java.io.InputStreamReader; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLSyntaxErrorException; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.apache.ibatis.datasource.unpooled.UnpooledDataSource; +import org.apache.ibatis.exceptions.PersistenceException; +import org.apache.ibatis.jdbc.ScriptRunner; +import org.apache.ibatis.mapping.Environment; +import org.apache.ibatis.session.Configuration; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.ibatis.session.SqlSessionFactoryBuilder; +import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mybatis.dynamic.sql.render.RenderingStrategies; +import org.mybatis.dynamic.sql.select.render.SelectStatementProvider; +import org.mybatis.dynamic.sql.util.mybatis3.CommonSelectMapper; + +class VariousListConditionsTest { + private static final String JDBC_URL = "jdbc:hsqldb:mem:aname"; + private static final String JDBC_DRIVER = "org.hsqldb.jdbcDriver"; + + private SqlSessionFactory sqlSessionFactory; + + @BeforeEach + void setup() throws Exception { + Class.forName(JDBC_DRIVER); + InputStream is = getClass().getResourceAsStream("/examples/animal/data/CreateAnimalData.sql"); + assert is != null; + try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "")) { + ScriptRunner sr = new ScriptRunner(connection); + sr.setLogWriter(null); + sr.runScript(new InputStreamReader(is)); + } + + UnpooledDataSource ds = new UnpooledDataSource(JDBC_DRIVER, JDBC_URL, "sa", ""); + Environment environment = new Environment("test", new JdbcTransactionFactory(), ds); + Configuration config = new Configuration(environment); + config.addMapper(CommonSelectMapper.class); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(config); + } + + @Test + void testInWithNull() { + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { + CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); + + SelectStatementProvider selectStatement = select(id, animalName) + .from(animalData) + .where(id, isIn(2, 3, null)) + .orderBy(id) + .build() + .render(RenderingStrategies.MYBATIS3); + + assertThat(selectStatement.getSelectStatement()).isEqualTo( + "select id, animal_name from AnimalData where id " + + "in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER},#{parameters.p3,jdbcType=INTEGER}) " + + "order by id" + ); + assertThat(selectStatement.getParameters()).containsEntry("p1", 2); + assertThat(selectStatement.getParameters()).containsEntry("p2", 3); + assertThat(selectStatement.getParameters()).containsEntry("p3", null); + + List> rows = mapper.selectManyMappedRows(selectStatement); + assertThat(rows).hasSize(2); + + assertThat(rows.get(0)).containsEntry("ID", 2); + } + } + + @Test + void testInWhenPresentWithNull() { + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { + CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); + + SelectStatementProvider selectStatement = select(id, animalName) + .from(animalData) + .where(id, isInWhenPresent(2, 3, null)) + .orderBy(id) + .build() + .render(RenderingStrategies.MYBATIS3); + + assertThat(selectStatement.getSelectStatement()).isEqualTo( + "select id, animal_name from AnimalData " + + "where id in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER}) " + + "order by id" + ); + assertThat(selectStatement.getParameters()).containsEntry("p1", 2); + assertThat(selectStatement.getParameters()).containsEntry("p2", 3); + + List> rows = mapper.selectManyMappedRows(selectStatement); + assertThat(rows).hasSize(2); + + assertThat(rows.get(0)).containsEntry("ID", 2); + } + } + + @Test + void testInWithEmptyList() { + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { + CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); + + SelectStatementProvider selectStatement = select(id, animalName) + .from(animalData) + .where(id, isIn(Collections.emptyList())) + .orderBy(id) + .build() + .render(RenderingStrategies.MYBATIS3); + + assertThat(selectStatement.getSelectStatement()).isEqualTo( + "select id, animal_name from AnimalData " + + "where id in () " + + "order by id" + ); + + assertThatExceptionOfType(PersistenceException.class).isThrownBy(() -> + mapper.selectManyMappedRows(selectStatement) + ).withCauseInstanceOf(SQLSyntaxErrorException.class); + } + } + + @Test + void testInWhenPresentWithEmptyList() { + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { + CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); + + SelectStatementProvider selectStatement = select(id, animalName) + .from(animalData) + .where(id, isInWhenPresent(Collections.emptyList())) + .orderBy(id) + .configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true)) + .build() + .render(RenderingStrategies.MYBATIS3); + + assertThat(selectStatement.getSelectStatement()).isEqualTo( + "select id, animal_name from AnimalData " + + "order by id"); + + List> rows = mapper.selectManyMappedRows(selectStatement); + assertThat(rows).hasSize(65); + + assertThat(rows.get(0)).containsEntry("ID", 1); + } + } + + @Test + void testInWithNullList() { + assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> + isIn((Collection) null) + ); + } + + @Test + void testInWhenPresentWithNullList() { + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { + CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); + + SelectStatementProvider selectStatement = select(id, animalName) + .from(animalData) + .where(id, isInWhenPresent((Collection) null)) + .orderBy(id) + .configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true)) + .build() + .render(RenderingStrategies.MYBATIS3); + + assertThat(selectStatement.getSelectStatement()).isEqualTo( + "select id, animal_name from AnimalData " + + "order by id"); + + List> rows = mapper.selectManyMappedRows(selectStatement); + assertThat(rows).hasSize(65); + + assertThat(rows.get(0)).containsEntry("ID", 1); + } + } + + @Test + void testInWhenPresentMap() { + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { + CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); + + SelectStatementProvider selectStatement = select(id, animalName) + .from(animalData) + .where(id, isInWhenPresent(2, 3).map(i -> i + 3)) + .orderBy(id) + .build() + .render(RenderingStrategies.MYBATIS3); + + assertThat(selectStatement.getSelectStatement()).isEqualTo( + "select id, animal_name from AnimalData " + + "where id in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER}) " + + "order by id" + ); + assertThat(selectStatement.getParameters()).containsEntry("p1", 5); + assertThat(selectStatement.getParameters()).containsEntry("p2", 6); + + List> rows = mapper.selectManyMappedRows(selectStatement); + assertThat(rows).hasSize(2); + + assertThat(rows.get(0)).containsEntry("ID", 5); + } + } + + @Test + void testNotInWhenPresentMap() { + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { + CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); + + SelectStatementProvider selectStatement = select(id, animalName) + .from(animalData) + .where(id, isNotInWhenPresent(2, 3).map(i -> i + 3)) + .orderBy(id) + .build() + .render(RenderingStrategies.MYBATIS3); + + assertThat(selectStatement.getSelectStatement()).isEqualTo( + "select id, animal_name from AnimalData " + + "where id not in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER}) " + + "order by id" + ); + assertThat(selectStatement.getParameters()).containsEntry("p1", 5); + assertThat(selectStatement.getParameters()).containsEntry("p2", 6); + + List> rows = mapper.selectManyMappedRows(selectStatement); + assertThat(rows).hasSize(63); + + assertThat(rows.get(0)).containsEntry("ID", 1); + } + } + + @Test + void testInCaseInsensitiveWhenPresentMap() { + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { + CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); + + SelectStatementProvider selectStatement = select(id, animalName) + .from(animalData) + .where(animalName, isInCaseInsensitiveWhenPresent("Fred", "Betty").filter(s -> false)) + .orderBy(id) + .configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true)) + .build() + .render(RenderingStrategies.MYBATIS3); + + assertThat(selectStatement.getSelectStatement()).isEqualTo( + "select id, animal_name from AnimalData " + + "order by id" + ); + + List> rows = mapper.selectManyMappedRows(selectStatement); + assertThat(rows).hasSize(65); + + assertThat(rows.get(0)).containsEntry("ID", 1); + } + } + + @Test + void testNotInCaseInsensitiveWhenPresentMap() { + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { + CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); + + SelectStatementProvider selectStatement = select(id, animalName) + .from(animalData) + .where(animalName, isNotInCaseInsensitiveWhenPresent("Fred", "Betty").filter(s -> false)) + .orderBy(id) + .configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true)) + .build() + .render(RenderingStrategies.MYBATIS3); + + assertThat(selectStatement.getSelectStatement()).isEqualTo( + "select id, animal_name from AnimalData " + + "order by id" + ); + + List> rows = mapper.selectManyMappedRows(selectStatement); + assertThat(rows).hasSize(65); + + assertThat(rows.get(0)).containsEntry("ID", 1); + } + } + + @Test + void testInEventuallyEmpty() { + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { + CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); + + SelectStatementProvider selectStatement = select(id, animalName) + .from(animalData) + .where(id, isIn(1, 2).filter(s -> false)) + .orderBy(id) + .build() + .render(RenderingStrategies.MYBATIS3); + + assertThat(selectStatement.getSelectStatement()).isEqualTo( + "select id, animal_name from AnimalData " + + "where id in () " + + "order by id" + ); + + assertThatExceptionOfType(PersistenceException.class).isThrownBy( + () -> mapper.selectManyMappedRows(selectStatement)) + .withCauseInstanceOf(SQLSyntaxErrorException.class); + } + } + + @Test + void testInCaseInsensitiveEventuallyEmpty() { + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { + CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); + + SelectStatementProvider selectStatement = select(id, animalName) + .from(animalData) + .where(animalName, isInCaseInsensitive("Fred", "Betty").filter(s -> false)) + .orderBy(id) + .build() + .render(RenderingStrategies.MYBATIS3); + + assertThat(selectStatement.getSelectStatement()).isEqualTo( + "select id, animal_name from AnimalData " + + "where upper(animal_name) in () " + + "order by id" + ); + + assertThatExceptionOfType(PersistenceException.class).isThrownBy( + () -> mapper.selectManyMappedRows(selectStatement)) + .withCauseInstanceOf(SQLSyntaxErrorException.class); + } + } + + @Test + void testNotInEventuallyEmpty() { + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { + CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); + + SelectStatementProvider selectStatement = select(id, animalName) + .from(animalData) + .where(id, isNotIn(1, 2).filter(s -> false)) + .orderBy(id) + .build() + .render(RenderingStrategies.MYBATIS3); + + assertThat(selectStatement.getSelectStatement()).isEqualTo( + "select id, animal_name from AnimalData " + + "where id not in () " + + "order by id" + ); + + assertThatExceptionOfType(PersistenceException.class).isThrownBy( + () -> mapper.selectManyMappedRows(selectStatement)) + .withCauseInstanceOf(SQLSyntaxErrorException.class); + } + } + + @Test + void testNotInCaseInsensitiveEventuallyEmpty() { + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { + CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); + + SelectStatementProvider selectStatement = select(id, animalName) + .from(animalData) + .where(animalName, isNotInCaseInsensitive("Fred", "Betty").filter(s -> false)) + .orderBy(id) + .build() + .render(RenderingStrategies.MYBATIS3); + + assertThat(selectStatement.getSelectStatement()).isEqualTo( + "select id, animal_name from AnimalData " + + "where upper(animal_name) not in () " + + "order by id" + ); + + assertThatExceptionOfType(PersistenceException.class).isThrownBy( + () -> mapper.selectManyMappedRows(selectStatement)) + .withCauseInstanceOf(SQLSyntaxErrorException.class); + } + } + + @Test + void testInEventuallyEmptyDoubleFilter() { + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { + CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); + + SelectStatementProvider selectStatement = select(id, animalName) + .from(animalData) + .where(id, isIn(1, 2).filter(s -> false).filter(s -> false)) + .orderBy(id) + .build() + .render(RenderingStrategies.MYBATIS3); + + assertThat(selectStatement.getSelectStatement()).isEqualTo( + "select id, animal_name from AnimalData " + + "where id in () " + + "order by id" + ); + + assertThatExceptionOfType(PersistenceException.class).isThrownBy( + () -> mapper.selectManyMappedRows(selectStatement)) + .withCauseInstanceOf(SQLSyntaxErrorException.class); + } + } +} From 5e9ed3d8e41606150d54ae88356f6be628a7cbed Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Thu, 16 May 2024 17:57:01 -0400 Subject: [PATCH 07/11] Refactor tests to stop IntelliJ nag --- .../examples/animal/data/AnimalDataTest.java | 626 +++++++----------- ...onditionsWithPredicatesAnimalDataTest.java | 357 ++++------ 2 files changed, 371 insertions(+), 612 deletions(-) diff --git a/src/test/java/examples/animal/data/AnimalDataTest.java b/src/test/java/examples/animal/data/AnimalDataTest.java index a051434dc..1a0dfbe3d 100644 --- a/src/test/java/examples/animal/data/AnimalDataTest.java +++ b/src/test/java/examples/animal/data/AnimalDataTest.java @@ -19,7 +19,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.within; -import static org.junit.jupiter.api.Assertions.assertAll; import static org.mybatis.dynamic.sql.SqlBuilder.*; import java.io.InputStream; @@ -97,10 +96,8 @@ void testSelectAllRows() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(animals).hasSize(65), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(animals).hasSize(65); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -116,10 +113,8 @@ void testSelectAllRowsWithRowBounds() { RowBounds rowBounds = new RowBounds(4, 6); List animals = mapper.selectManyWithRowBounds(selectStatement, rowBounds); - assertAll( - () -> assertThat(animals).hasSize(6), - () -> assertThat(animals.get(0).getId()).isEqualTo(5) - ); + assertThat(animals).hasSize(6); + assertThat(animals.get(0).getId()).isEqualTo(5); } } @@ -133,10 +128,8 @@ void testSelectAllRowsWithOrder() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(animals).hasSize(65), - () -> assertThat(animals.get(0).getId()).isEqualTo(65) - ); + assertThat(animals).hasSize(65); + assertThat(animals.get(0).getId()).isEqualTo(65); } } @@ -150,12 +143,10 @@ void testSelectAllRowsAllColumns() { .build() .render(RenderingStrategies.MYBATIS3); List> animals = mapper.selectManyMappedRows(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData order by id DESC"), - () -> assertThat(animals).hasSize(65), - () -> assertThat(animals.get(0)).containsEntry("ID", 65), - () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "Brachiosaurus") - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData order by id DESC"); + assertThat(animals).hasSize(65); + assertThat(animals.get(0)).containsEntry("ID", 65); + assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); } } @@ -169,11 +160,9 @@ void testSelectAllRowsAllColumnsWithOrder() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData order by id DESC"), - () -> assertThat(animals).hasSize(65), - () -> assertThat(animals.get(0).getId()).isEqualTo(65) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData order by id DESC"); + assertThat(animals).hasSize(65); + assertThat(animals.get(0).getId()).isEqualTo(65); } } @@ -187,11 +176,9 @@ void testSelectAllRowsAllColumnsWithOrderAndAlias() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select ad.* from AnimalData ad order by id DESC"), - () -> assertThat(animals).hasSize(65), - () -> assertThat(animals.get(0).getId()).isEqualTo(65) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select ad.* from AnimalData ad order by id DESC"); + assertThat(animals).hasSize(65); + assertThat(animals.get(0).getId()).isEqualTo(65); } } @@ -404,13 +391,11 @@ void testUnionSelectWithWhere() { + "where id > #{parameters.p2,jdbcType=INTEGER}"; List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(44), - () -> assertThat(selectStatement.getParameters()).hasSize(2), - () -> assertThat(selectStatement.getParameters()).containsEntry("p1", 20), - () -> assertThat(selectStatement.getParameters()).containsEntry("p2", 40) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(44); + assertThat(selectStatement.getParameters()).hasSize(2); + assertThat(selectStatement.getParameters()).containsEntry("p1", 20); + assertThat(selectStatement.getParameters()).containsEntry("p2", 40); } } @@ -436,11 +421,9 @@ void testUnionSelectWithoutWhere() { + "order by id"; List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(65), - () -> assertThat(selectStatement.getParameters()).isEmpty() - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(65); + assertThat(selectStatement.getParameters()).isEmpty(); } } @@ -466,11 +449,9 @@ void testUnionAllSelectWithoutWhere() { + "order by id"; List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(130), - () -> assertThat(selectStatement.getParameters()).isEmpty() - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(130); + assertThat(selectStatement.getParameters()).isEmpty(); } } @@ -500,14 +481,11 @@ void testUnionSelectWithTableAliases() { + "order by id"; List animals = mapper.selectMany(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(44), - () -> assertThat(selectStatement.getParameters()).hasSize(2), - () -> assertThat(selectStatement.getParameters()).containsEntry("p1", 20), - () -> assertThat(selectStatement.getParameters()).containsEntry("p2", 40) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(44); + assertThat(selectStatement.getParameters()).hasSize(2); + assertThat(selectStatement.getParameters()).containsEntry("p1", 20); + assertThat(selectStatement.getParameters()).containsEntry("p2", 40); } } @@ -537,14 +515,11 @@ void testUnionAllSelectWithTableAliases() { + "order by id"; List animals = mapper.selectMany(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(44), - () -> assertThat(selectStatement.getParameters()).hasSize(2), - () -> assertThat(selectStatement.getParameters()).containsEntry("p1", 20), - () -> assertThat(selectStatement.getParameters()).containsEntry("p2", 40) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(44); + assertThat(selectStatement.getParameters()).hasSize(2); + assertThat(selectStatement.getParameters()).containsEntry("p1", 20); + assertThat(selectStatement.getParameters()).containsEntry("p2", 40); } } @@ -574,14 +549,11 @@ void testUnionSelectWithTableAndColumnAliases() { + "order by animalId"; List animals = mapper.selectMany(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(44), - () -> assertThat(selectStatement.getParameters()).hasSize(2), - () -> assertThat(selectStatement.getParameters()).containsEntry("p1", 20), - () -> assertThat(selectStatement.getParameters()).containsEntry("p2", 40) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(44); + assertThat(selectStatement.getParameters()).hasSize(2); + assertThat(selectStatement.getParameters()).containsEntry("p1", 20); + assertThat(selectStatement.getParameters()).containsEntry("p2", 40); } } @@ -837,12 +809,9 @@ void testLikeCaseInsensitive() { .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - - assertAll( - () -> assertThat(animals).hasSize(2), - () -> assertThat(animals.get(0).getAnimalName()).isEqualTo("Ground squirrel"), - () -> assertThat(animals.get(1).getAnimalName()).isEqualTo("Artic ground squirrel") - ); + assertThat(animals).hasSize(2); + assertThat(animals.get(0).getAnimalName()).isEqualTo("Ground squirrel"); + assertThat(animals.get(1).getAnimalName()).isEqualTo("Artic ground squirrel"); } } @@ -858,12 +827,9 @@ void testLikeLowerCase() { .render(RenderingStrategies.MYBATIS3); List> animals = mapper.selectManyMappedRows(selectStatement); - - assertAll( - () -> assertThat(animals).hasSize(2), - () -> assertThat(animals.get(0)).containsEntry("ANIMALNAME", "ground squirrel"), - () -> assertThat(animals.get(1)).containsEntry("ANIMALNAME", "artic ground squirrel") - ); + assertThat(animals).hasSize(2); + assertThat(animals.get(0)).containsEntry("ANIMALNAME", "ground squirrel"); + assertThat(animals.get(1)).containsEntry("ANIMALNAME", "artic ground squirrel"); } } @@ -879,12 +845,9 @@ void testLikeUpperCase() { .render(RenderingStrategies.MYBATIS3); List> animals = mapper.selectManyMappedRows(selectStatement); - - assertAll( - () -> assertThat(animals).hasSize(2), - () -> assertThat(animals.get(0)).containsEntry("ANIMALNAME", "GROUND SQUIRREL"), - () -> assertThat(animals.get(1)).containsEntry("ANIMALNAME", "ARTIC GROUND SQUIRREL") - ); + assertThat(animals).hasSize(2); + assertThat(animals.get(0)).containsEntry("ANIMALNAME", "GROUND SQUIRREL"); + assertThat(animals.get(1)).containsEntry("ANIMALNAME", "ARTIC GROUND SQUIRREL"); } } @@ -924,17 +887,14 @@ void testNumericConstant() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(3), - () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), - () -> assertThat(animals.get(0)).containsEntry("SOME_NUMBER", 3), - () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), - () -> assertThat(animals.get(1)).containsEntry("SOME_NUMBER", 3), - () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), - () -> assertThat(animals.get(2)).containsEntry("SOME_NUMBER", 3) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(3); + assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); + assertThat(animals.get(0)).containsEntry("SOME_NUMBER", 3); + assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); + assertThat(animals.get(1)).containsEntry("SOME_NUMBER", 3); + assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); + assertThat(animals.get(2)).containsEntry("SOME_NUMBER", 3); } } @@ -954,17 +914,14 @@ void testStringConstant() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(3), - () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), - () -> assertThat(animals.get(0)).containsEntry("SOME_STRING", "fred"), - () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), - () -> assertThat(animals.get(1)).containsEntry("SOME_STRING", "fred"), - () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), - () -> assertThat(animals.get(2)).containsEntry("SOME_STRING", "fred") - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(3); + assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); + assertThat(animals.get(0)).containsEntry("SOME_STRING", "fred"); + assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); + assertThat(animals.get(1)).containsEntry("SOME_STRING", "fred"); + assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); + assertThat(animals.get(2)).containsEntry("SOME_STRING", "fred"); } } @@ -984,17 +941,14 @@ void testAdd() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(3), - () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), - () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 12366.0), - () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), - () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 11750.0), - () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), - () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 87154.5) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(3); + assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); + assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 12366.0); + assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); + assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 11750.0); + assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); + assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 87154.5); } } @@ -1014,17 +968,14 @@ void testAddConstant() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(3), - () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), - () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 5767.0), - () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), - () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 105.0), - () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), - () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 209.5) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(3); + assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); + assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 5767.0); + assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); + assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 105.0); + assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); + assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 209.5); } } @@ -1044,17 +995,14 @@ void testAddConstantWithConstantFirst() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(3), - () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), - () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 5767.0), - () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), - () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 105.0), - () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), - () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 209.5) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(3); + assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); + assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 5767.0); + assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); + assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 105.0); + assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); + assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 209.5); } } @@ -1074,14 +1022,11 @@ void testConcat() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(3), - () -> assertThat(animals.get(0)).containsEntry("DISPLAY_NAME", "African elephant - The Legend"), - () -> assertThat(animals.get(1)).containsEntry("DISPLAY_NAME", "Dipliodocus - The Legend"), - () -> assertThat(animals.get(2)).containsEntry("DISPLAY_NAME", "Brachiosaurus - The Legend") - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(3); + assertThat(animals.get(0)).containsEntry("DISPLAY_NAME", "African elephant - The Legend"); + assertThat(animals.get(1)).containsEntry("DISPLAY_NAME", "Dipliodocus - The Legend"); + assertThat(animals.get(2)).containsEntry("DISPLAY_NAME", "Brachiosaurus - The Legend"); } } @@ -1101,14 +1046,11 @@ void testConcatenate() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(3), - () -> assertThat(animals.get(0)).containsEntry("DISPLAY_NAME", "African elephant - The Legend"), - () -> assertThat(animals.get(1)).containsEntry("DISPLAY_NAME", "Dipliodocus - The Legend"), - () -> assertThat(animals.get(2)).containsEntry("DISPLAY_NAME", "Brachiosaurus - The Legend") - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(3); + assertThat(animals.get(0)).containsEntry("DISPLAY_NAME", "African elephant - The Legend"); + assertThat(animals.get(1)).containsEntry("DISPLAY_NAME", "Dipliodocus - The Legend"); + assertThat(animals.get(2)).containsEntry("DISPLAY_NAME", "Brachiosaurus - The Legend"); } } @@ -1128,14 +1070,11 @@ void testConcatenateConstantFirst() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(3), - () -> assertThat(animals.get(0)).containsEntry("DISPLAY_NAME", "Name: African elephant"), - () -> assertThat(animals.get(1)).containsEntry("DISPLAY_NAME", "Name: Dipliodocus"), - () -> assertThat(animals.get(2)).containsEntry("DISPLAY_NAME", "Name: Brachiosaurus") - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(3); + assertThat(animals.get(0)).containsEntry("DISPLAY_NAME", "Name: African elephant"); + assertThat(animals.get(1)).containsEntry("DISPLAY_NAME", "Name: Dipliodocus"); + assertThat(animals.get(2)).containsEntry("DISPLAY_NAME", "Name: Brachiosaurus"); } } @@ -1155,17 +1094,14 @@ void testDivide() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(3), - () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), - () -> assertThat((Double) animals.get(0).get("CALCULATED_WEIGHT")).isEqualTo(0.858, within(0.001)), - () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), - () -> assertThat((Double) animals.get(1).get("CALCULATED_WEIGHT")).isEqualTo(0.004, within(0.001)), - () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), - () -> assertThat((Double) animals.get(2).get("CALCULATED_WEIGHT")).isEqualTo(0.001, within(0.001)) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(3); + assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); + assertThat((Double) animals.get(0).get("CALCULATED_WEIGHT")).isEqualTo(0.858, within(0.001)); + assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); + assertThat((Double) animals.get(1).get("CALCULATED_WEIGHT")).isEqualTo(0.004, within(0.001)); + assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); + assertThat((Double) animals.get(2).get("CALCULATED_WEIGHT")).isEqualTo(0.001, within(0.001)); } } @@ -1185,17 +1121,14 @@ void testDivideConstant() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(3), - () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), - () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 571.2), - () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), - () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 5.0), - () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), - () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 15.45) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(3); + assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); + assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 571.2); + assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); + assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 5.0); + assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); + assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 15.45); } } @@ -1215,17 +1148,14 @@ void testMultiply() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(3), - () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), - () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 38007648.0), - () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), - () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 585000.0), - () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), - () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 13441500.0) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(3); + assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); + assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 38007648.0); + assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); + assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 585000.0); + assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); + assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 13441500.0); } } @@ -1245,17 +1175,14 @@ void testMultiplyConstant() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(3), - () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), - () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 11424.0), - () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), - () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 100.0), - () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), - () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 309.0) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(3); + assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); + assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 11424.0); + assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); + assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 100.0); + assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); + assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 309.0); } } @@ -1275,17 +1202,14 @@ void testSubtract() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(3), - () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), - () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", -942.0), - () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), - () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", -11650.0), - () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), - () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", -86845.5) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(3); + assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); + assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", -942.0); + assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); + assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", -11650.0); + assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); + assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", -86845.5); } } @@ -1305,17 +1229,14 @@ void testSubtractConstant() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(3), - () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), - () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 5706.5), - () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), - () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 44.5), - () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), - () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 149.0) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(3); + assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); + assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 5706.5); + assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); + assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 44.5); + assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); + assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 149.0); } } @@ -1335,17 +1256,14 @@ void testGeneralOperator() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(3), - () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), - () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", -942.0), - () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), - () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", -11650.0), - () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), - () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", -86845.5) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(3); + assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); + assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", -942.0); + assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); + assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", -11650.0); + assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); + assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", -86845.5); } } @@ -1365,17 +1283,14 @@ void testComplexExpression() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), - () -> assertThat(animals).hasSize(3), - () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), - () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 38068.0), - () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), - () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 11973.0), - () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), - () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 87847.75) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); + assertThat(animals).hasSize(3); + assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); + assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 38068.0); + assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); + assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 11973.0); + assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); + assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 87847.75); } } @@ -1637,16 +1552,13 @@ record = new AnimalData(); .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - - assertAll( - () -> assertThat(animals).hasSize(2), - () -> assertThat(animals.get(0).getId()).isEqualTo(100), - () -> assertThat(animals.get(0).getBrainWeight()).isEqualTo(1.2), - () -> assertThat(animals.get(0).getAnimalName()).isNull(), - () -> assertThat(animals.get(1).getId()).isEqualTo(101), - () -> assertThat(animals.get(1).getBrainWeight()).isEqualTo(1.2), - () -> assertThat(animals.get(1).getAnimalName()).isNull() - ); + assertThat(animals).hasSize(2); + assertThat(animals.get(0).getId()).isEqualTo(100); + assertThat(animals.get(0).getBrainWeight()).isEqualTo(1.2); + assertThat(animals.get(0).getAnimalName()).isNull(); + assertThat(animals.get(1).getId()).isEqualTo(101); + assertThat(animals.get(1).getBrainWeight()).isEqualTo(1.2); + assertThat(animals.get(1).getAnimalName()).isNull(); } } @@ -1687,16 +1599,13 @@ record = new AnimalData(); .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - - assertAll( - () -> assertThat(animals).hasSize(2), - () -> assertThat(animals.get(0).getId()).isEqualTo(100), - () -> assertThat(animals.get(0).getBrainWeight()).isEqualTo(1.2), - () -> assertThat(animals.get(0).getAnimalName()).isEqualTo("Old Fred"), - () -> assertThat(animals.get(1).getId()).isEqualTo(101), - () -> assertThat(animals.get(1).getBrainWeight()).isEqualTo(1.2), - () -> assertThat(animals.get(1).getAnimalName()).isEqualTo("Old Fred") - ); + assertThat(animals).hasSize(2); + assertThat(animals.get(0).getId()).isEqualTo(100); + assertThat(animals.get(0).getBrainWeight()).isEqualTo(1.2); + assertThat(animals.get(0).getAnimalName()).isEqualTo("Old Fred"); + assertThat(animals.get(1).getId()).isEqualTo(101); + assertThat(animals.get(1).getBrainWeight()).isEqualTo(1.2); + assertThat(animals.get(1).getAnimalName()).isEqualTo("Old Fred"); } } @@ -1714,11 +1623,8 @@ void testOrderByAndDistinct() { .render(RenderingStrategies.MYBATIS3); List rows = mapper.selectMany(selectStatement); - - assertAll( - () -> assertThat(rows).hasSize(14), - () -> assertThat(rows.get(0).getId()).isEqualTo(65) - ); + assertThat(rows).hasSize(14); + assertThat(rows.get(0).getId()).isEqualTo(65); } } @@ -1736,11 +1642,8 @@ void testOrderByWithFullClause() { .render(RenderingStrategies.MYBATIS3); List rows = mapper.selectMany(selectStatement); - - assertAll( - () -> assertThat(rows).hasSize(14), - () -> assertThat(rows.get(0).getId()).isEqualTo(65) - ); + assertThat(rows).hasSize(14); + assertThat(rows.get(0).getId()).isEqualTo(65); } } @@ -1755,11 +1658,8 @@ void testCount() { .render(RenderingStrategies.MYBATIS3); Long count = mapper.selectOneLong(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select count(*) as total from AnimalData a"), - () -> assertThat(count).isEqualTo(65) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select count(*) as total from AnimalData a"); + assertThat(count).isEqualTo(65); } } @@ -1774,11 +1674,8 @@ void testCountField() { .render(RenderingStrategies.MYBATIS3); Long count = mapper.selectOneLong(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select count(a.brain_weight) as total from AnimalData a"), - () -> assertThat(count).isEqualTo(65) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select count(a.brain_weight) as total from AnimalData a"); + assertThat(count).isEqualTo(65); } } @@ -1793,11 +1690,8 @@ void testCountNoAlias() { .render(RenderingStrategies.MYBATIS3); Long count = mapper.selectOneLong(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select count(*) from AnimalData"), - () -> assertThat(count).isEqualTo(65) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select count(*) from AnimalData"); + assertThat(count).isEqualTo(65); } } @@ -1812,11 +1706,8 @@ void testMax() { .render(RenderingStrategies.MYBATIS3); Double max = mapper.selectOneDouble(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select max(a.brain_weight) as total from AnimalData a"), - () -> assertThat(max).isEqualTo(87000.0) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select max(a.brain_weight) as total from AnimalData a"); + assertThat(max).isEqualTo(87000.0); } } @@ -1831,11 +1722,8 @@ void testMaxNoAlias() { .render(RenderingStrategies.MYBATIS3); Double max = mapper.selectOneDouble(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select max(brain_weight) from AnimalData"), - () -> assertThat(max).isEqualTo(87000.0) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select max(brain_weight) from AnimalData"); + assertThat(max).isEqualTo(87000.0); } } @@ -1851,12 +1739,9 @@ void testMaxSubselect() { .render(RenderingStrategies.MYBATIS3); List records = mapper.selectMany(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight = (select max(b.brain_weight) from AnimalData b)"), - () -> assertThat(records).hasSize(1), - () -> assertThat(records.get(0).getAnimalName()).isEqualTo("Brachiosaurus") - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight = (select max(b.brain_weight) from AnimalData b)"); + assertThat(records).hasSize(1); + assertThat(records.get(0).getAnimalName()).isEqualTo("Brachiosaurus"); } } @@ -1871,11 +1756,8 @@ void testMin() { .render(RenderingStrategies.MYBATIS3); Double min = mapper.selectOneDouble(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select min(a.brain_weight) as total from AnimalData a"), - () -> assertThat(min).isEqualTo(0.005) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select min(a.brain_weight) as total from AnimalData a"); + assertThat(min).isEqualTo(0.005); } } @@ -1890,11 +1772,8 @@ void testMinNoAlias() { .render(RenderingStrategies.MYBATIS3); Double min = mapper.selectOneDouble(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select min(brain_weight) from AnimalData"), - () -> assertThat(min).isEqualTo(0.005) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select min(brain_weight) from AnimalData"); + assertThat(min).isEqualTo(0.005); } } @@ -1911,12 +1790,9 @@ void testMinSubselect() { .render(RenderingStrategies.MYBATIS3); List records = mapper.selectMany(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight <> (select min(b.brain_weight) from AnimalData b) order by animal_name"), - () -> assertThat(records).hasSize(64), - () -> assertThat(records.get(0).getAnimalName()).isEqualTo("African elephant") - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight <> (select min(b.brain_weight) from AnimalData b) order by animal_name"); + assertThat(records).hasSize(64); + assertThat(records.get(0).getAnimalName()).isEqualTo("African elephant"); } } @@ -1933,12 +1809,9 @@ void testMinSubselectNoAlias() { .render(RenderingStrategies.MYBATIS3); List records = mapper.selectMany(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where brain_weight <> (select min(brain_weight) from AnimalData) order by animal_name"), - () -> assertThat(records).hasSize(64), - () -> assertThat(records.get(0).getAnimalName()).isEqualTo("African elephant") - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where brain_weight <> (select min(brain_weight) from AnimalData) order by animal_name"); + assertThat(records).hasSize(64); + assertThat(records.get(0).getAnimalName()).isEqualTo("African elephant"); } } @@ -1953,11 +1826,8 @@ void testAvg() { .render(RenderingStrategies.MYBATIS3); Double average = mapper.selectOneDouble(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select avg(a.brain_weight) as average from AnimalData a"), - () -> assertThat(average).isEqualTo(1852.69, within(.01)) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select avg(a.brain_weight) as average from AnimalData a"); + assertThat(average).isEqualTo(1852.69, within(.01)); } } @@ -1972,11 +1842,8 @@ void testSum() { .render(RenderingStrategies.MYBATIS3); Double total = mapper.selectOneDouble(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select sum(brain_weight) as total from AnimalData"), - () -> assertThat(total).isEqualTo(120424.97, within(.01)) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select sum(brain_weight) as total from AnimalData"); + assertThat(total).isEqualTo(120424.97, within(.01)); } } @@ -1992,11 +1859,8 @@ void testLessThanSubselect() { .render(RenderingStrategies.MYBATIS3); List records = mapper.selectMany(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight < (select max(b.brain_weight) from AnimalData b)"), - () -> assertThat(records).hasSize(64) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight < (select max(b.brain_weight) from AnimalData b)"); + assertThat(records).hasSize(64); } } @@ -2012,11 +1876,8 @@ void testLessThanOrEqualToSubselect() { .render(RenderingStrategies.MYBATIS3); List records = mapper.selectMany(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight <= (select max(b.brain_weight) from AnimalData b)"), - () -> assertThat(records).hasSize(65) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight <= (select max(b.brain_weight) from AnimalData b)"); + assertThat(records).hasSize(65); } } @@ -2032,11 +1893,8 @@ void testGreaterThanSubselect() { .render(RenderingStrategies.MYBATIS3); List records = mapper.selectMany(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight > (select min(b.brain_weight) from AnimalData b)"), - () -> assertThat(records).hasSize(64) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight > (select min(b.brain_weight) from AnimalData b)"); + assertThat(records).hasSize(64); } } @@ -2052,11 +1910,8 @@ void testGreaterThanOrEqualToSubselect() { .render(RenderingStrategies.MYBATIS3); List records = mapper.selectMany(selectStatement); - - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight >= (select min(b.brain_weight) from AnimalData b)"), - () -> assertThat(records).hasSize(65) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight >= (select min(b.brain_weight) from AnimalData b)"); + assertThat(records).hasSize(65); } } @@ -2078,13 +1933,10 @@ void testInsertSelectWithColumnList() { + "where id < #{parameters.p1,jdbcType=INTEGER}"; int rows = mapper.insertSelect(insertSelectStatement); - - assertAll( - () -> assertThat(insertSelectStatement.getInsertStatement()).isEqualTo(expected), - () -> assertThat(insertSelectStatement.getParameters()).hasSize(1), - () -> assertThat(insertSelectStatement.getParameters()).containsEntry("p1", 22), - () -> assertThat(rows).isEqualTo(21) - ); + assertThat(insertSelectStatement.getInsertStatement()).isEqualTo(expected); + assertThat(insertSelectStatement.getParameters()).hasSize(1); + assertThat(insertSelectStatement.getParameters()).containsEntry("p1", 22); + assertThat(rows).isEqualTo(21); } } @@ -2104,13 +1956,10 @@ void testInsertSelectWithoutColumnList() { + "from AnimalData " + "where id < #{parameters.p1,jdbcType=INTEGER}"; int rows = mapper.insertSelect(insertSelectStatement); - - assertAll( - () -> assertThat(insertSelectStatement.getInsertStatement()).isEqualTo(expected), - () -> assertThat(insertSelectStatement.getParameters()).hasSize(1), - () -> assertThat(insertSelectStatement.getParameters()).containsEntry("p1", 33), - () -> assertThat(rows).isEqualTo(32) - ); + assertThat(insertSelectStatement.getInsertStatement()).isEqualTo(expected); + assertThat(insertSelectStatement.getParameters()).hasSize(1); + assertThat(insertSelectStatement.getParameters()).containsEntry("p1", 33); + assertThat(rows).isEqualTo(32); } } @@ -2210,14 +2059,11 @@ void testUpdateWithSelect() { + "set brain_weight = (select avg(brain_weight) from AnimalData where brain_weight > #{parameters.p1,jdbcType=DOUBLE}) " + "where brain_weight < #{parameters.p2,jdbcType=DOUBLE}"; int rows = mapper.update(updateStatement); - - assertAll( - () -> assertThat(updateStatement.getUpdateStatement()).isEqualTo(expected), - () -> assertThat(updateStatement.getParameters()).hasSize(2), - () -> assertThat(updateStatement.getParameters()).containsEntry("p1", 22.0), - () -> assertThat(updateStatement.getParameters()).containsEntry("p2", 1.0), - () -> assertThat(rows).isEqualTo(20) - ); + assertThat(updateStatement.getUpdateStatement()).isEqualTo(expected); + assertThat(updateStatement.getParameters()).hasSize(2); + assertThat(updateStatement.getParameters()).containsEntry("p1", 22.0); + assertThat(updateStatement.getParameters()).containsEntry("p2", 1.0); + assertThat(rows).isEqualTo(20); } } diff --git a/src/test/java/examples/animal/data/OptionalConditionsWithPredicatesAnimalDataTest.java b/src/test/java/examples/animal/data/OptionalConditionsWithPredicatesAnimalDataTest.java index 2cfaab8bb..3b011f83b 100644 --- a/src/test/java/examples/animal/data/OptionalConditionsWithPredicatesAnimalDataTest.java +++ b/src/test/java/examples/animal/data/OptionalConditionsWithPredicatesAnimalDataTest.java @@ -21,7 +21,6 @@ import static examples.animal.data.AnimalDataDynamicSqlSupport.brainWeight; import static examples.animal.data.AnimalDataDynamicSqlSupport.id; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertAll; import static org.mybatis.dynamic.sql.SqlBuilder.*; import java.io.InputStream; @@ -83,12 +82,10 @@ void testAllIgnored() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData order by id"), - () -> assertThat(animals).hasSize(65), - () -> assertThat(animals.get(0).getId()).isEqualTo(1), - () -> assertThat(animals.get(1).getId()).isEqualTo(2) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData order by id"); + assertThat(animals).hasSize(65); + assertThat(animals.get(0).getId()).isEqualTo(1); + assertThat(animals.get(1).getId()).isEqualTo(2); } } @@ -105,12 +102,10 @@ void testIgnoredBetweenRendered() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(2), - () -> assertThat(animals.get(0).getId()).isEqualTo(3), - () -> assertThat(animals.get(1).getId()).isEqualTo(4) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(2); + assertThat(animals.get(0).getId()).isEqualTo(3); + assertThat(animals.get(1).getId()).isEqualTo(4); } } @@ -127,12 +122,10 @@ void testIgnoredInWhere() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(2), - () -> assertThat(animals.get(0).getId()).isEqualTo(3), - () -> assertThat(animals.get(1).getId()).isEqualTo(4) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(2); + assertThat(animals.get(0).getId()).isEqualTo(3); + assertThat(animals.get(1).getId()).isEqualTo(4); } } @@ -150,12 +143,10 @@ void testManyIgnored() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(2), - () -> assertThat(animals.get(0).getId()).isEqualTo(3), - () -> assertThat(animals.get(1).getId()).isEqualTo(4) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(2); + assertThat(animals.get(0).getId()).isEqualTo(3); + assertThat(animals.get(1).getId()).isEqualTo(4); } } @@ -171,12 +162,10 @@ void testIgnoredInitialWhere() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(2), - () -> assertThat(animals.get(0).getId()).isEqualTo(3), - () -> assertThat(animals.get(1).getId()).isEqualTo(4) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(2); + assertThat(animals.get(0).getId()).isEqualTo(3); + assertThat(animals.get(1).getId()).isEqualTo(4); } } @@ -191,11 +180,9 @@ void testEqualWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(1), - () -> assertThat(animals.get(0).getId()).isEqualTo(4) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(1); + assertThat(animals.get(0).getId()).isEqualTo(4); } } @@ -211,11 +198,9 @@ void testEqualWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(10), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(10); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -231,11 +216,9 @@ void testNotEqualWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <> #{parameters.p1,jdbcType=INTEGER} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(9), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <> #{parameters.p1,jdbcType=INTEGER} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(9); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -251,11 +234,9 @@ void testNotEqualWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(10), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(10); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -271,11 +252,9 @@ void testGreaterThanWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id > #{parameters.p1,jdbcType=INTEGER} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(6), - () -> assertThat(animals.get(0).getId()).isEqualTo(5) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id > #{parameters.p1,jdbcType=INTEGER} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(6); + assertThat(animals.get(0).getId()).isEqualTo(5); } } @@ -291,11 +270,9 @@ void testGreaterThanWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(10), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(10); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -311,11 +288,9 @@ void testGreaterThanOrEqualToWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id >= #{parameters.p1,jdbcType=INTEGER} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(7), - () -> assertThat(animals.get(0).getId()).isEqualTo(4) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id >= #{parameters.p1,jdbcType=INTEGER} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(7); + assertThat(animals.get(0).getId()).isEqualTo(4); } } @@ -331,11 +306,9 @@ void testGreaterThanOrEqualToWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(10), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(10); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -350,11 +323,9 @@ void testLessThanWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id < #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(3), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id < #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(3); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -370,11 +341,9 @@ void testLessThanWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(10), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(10); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -389,11 +358,9 @@ void testLessThanOrEqualToWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(4), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(4); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -409,11 +376,9 @@ void testLessThanOrEqualToWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(10), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(10); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -428,11 +393,9 @@ void testIsInWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER},#{parameters.p3,jdbcType=INTEGER}) order by id"), - () -> assertThat(animals).hasSize(3), - () -> assertThat(animals.get(0).getId()).isEqualTo(4) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER},#{parameters.p3,jdbcType=INTEGER}) order by id"); + assertThat(animals).hasSize(3); + assertThat(animals.get(0).getId()).isEqualTo(4); } } @@ -447,12 +410,10 @@ void testIsInWhenWithSomeValues() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER}) order by id"), - () -> assertThat(animals).hasSize(2), - () -> assertThat(animals.get(0).getId()).isEqualTo(6), - () -> assertThat(animals.get(1).getId()).isEqualTo(8) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER}) order by id"); + assertThat(animals).hasSize(2); + assertThat(animals.get(0).getId()).isEqualTo(6); + assertThat(animals.get(1).getId()).isEqualTo(8); } } @@ -467,11 +428,9 @@ void testIsInCaseInsensitiveWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) order by id"), - () -> assertThat(animals).hasSize(2), - () -> assertThat(animals.get(0).getId()).isEqualTo(4) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) order by id"); + assertThat(animals).hasSize(2); + assertThat(animals.get(0).getId()).isEqualTo(4); } } @@ -489,11 +448,9 @@ void testValueStreamTransformer() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) order by id"), - () -> assertThat(animals).hasSize(2), - () -> assertThat(animals.get(0).getId()).isEqualTo(4) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) order by id"); + assertThat(animals).hasSize(2); + assertThat(animals.get(0).getId()).isEqualTo(4); } } @@ -508,11 +465,9 @@ void testValueStreamTransformerWithCustomCondition() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) order by id"), - () -> assertThat(animals).hasSize(2), - () -> assertThat(animals.get(0).getId()).isEqualTo(4) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) order by id"); + assertThat(animals).hasSize(2); + assertThat(animals.get(0).getId()).isEqualTo(4); } } @@ -528,11 +483,9 @@ void testIsInCaseInsensitiveWhenWithNoValues() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(10), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(10); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -548,11 +501,9 @@ void testIsNotInWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id not in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER},#{parameters.p3,jdbcType=INTEGER}) and id <= #{parameters.p4,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(7), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id not in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER},#{parameters.p3,jdbcType=INTEGER}) and id <= #{parameters.p4,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(7); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -568,11 +519,9 @@ void testIsNotInWhenWithSomeValues() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id not in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER}) and id <= #{parameters.p3,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(8), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id not in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER}) and id <= #{parameters.p3,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(8); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -588,11 +537,9 @@ void testIsNotInCaseInsensitiveWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) not in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) and id <= #{parameters.p3,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(8), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) not in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) and id <= #{parameters.p3,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(8); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -608,11 +555,9 @@ void testIsNotInCaseInsensitiveWhenWithNoValues() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(10), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(10); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -627,11 +572,9 @@ void testIsBetweenWhenWithValues() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id between #{parameters.p1,jdbcType=INTEGER} and #{parameters.p2,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(4), - () -> assertThat(animals.get(0).getId()).isEqualTo(3) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id between #{parameters.p1,jdbcType=INTEGER} and #{parameters.p2,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(4); + assertThat(animals.get(0).getId()).isEqualTo(3); } } @@ -647,11 +590,9 @@ void testIsBetweenWhenWithFirstMissing() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(10), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(10); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -667,11 +608,9 @@ void testIsBetweenWhenWithSecondMissing() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(10), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(10); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -687,11 +626,9 @@ void testIsBetweenWhenWithBothMissing() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(10), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(10); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -707,11 +644,9 @@ void testIsNotBetweenWhenWithValues() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id not between #{parameters.p1,jdbcType=INTEGER} and #{parameters.p2,jdbcType=INTEGER} and id <= #{parameters.p3,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(6), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id not between #{parameters.p1,jdbcType=INTEGER} and #{parameters.p2,jdbcType=INTEGER} and id <= #{parameters.p3,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(6); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -727,11 +662,9 @@ void testIsNotBetweenWhenWithFirstMissing() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(10), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(10); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -747,11 +680,9 @@ void testIsNotBetweenWhenWithSecondMissing() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(10), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(10); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -767,11 +698,9 @@ void testIsNotBetweenWhenWithBothMissing() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(10), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(10); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -787,11 +716,9 @@ void testIsLikeWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(2), - () -> assertThat(animals.get(0).getId()).isEqualTo(6) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(2); + assertThat(animals.get(0).getId()).isEqualTo(6); } } @@ -807,11 +734,9 @@ void testIsLikeWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(10), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(10); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -827,11 +752,9 @@ void testIsLikeCaseInsensitiveWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(2), - () -> assertThat(animals.get(0).getId()).isEqualTo(6) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(2); + assertThat(animals.get(0).getId()).isEqualTo(6); } } @@ -847,11 +770,9 @@ void testIsLikeCaseInsensitiveWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(10), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(10); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -867,11 +788,9 @@ void testIsNotLikeWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name not like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(8), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name not like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(8); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -887,11 +806,9 @@ void testIsNotLikeWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(10), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(10); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -907,11 +824,9 @@ void testIsNotLikeCaseInsensitiveWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) not like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(8), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) not like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(8); + assertThat(animals.get(0).getId()).isEqualTo(1); } } @@ -927,11 +842,9 @@ void testIsNotLikeCaseInsensitiveWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertAll( - () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), - () -> assertThat(animals).hasSize(10), - () -> assertThat(animals.get(0).getId()).isEqualTo(1) - ); + assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); + assertThat(animals).hasSize(10); + assertThat(animals.get(0).getId()).isEqualTo(1); } } } From 00c04a27fe029ba1ccf7c2b5b115cdf97b3b80c2 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Sat, 18 May 2024 08:37:59 -0400 Subject: [PATCH 08/11] Revert "Refactor tests to stop IntelliJ nag" This reverts commit 5e9ed3d8e41606150d54ae88356f6be628a7cbed. --- .../examples/animal/data/AnimalDataTest.java | 626 +++++++++++------- ...onditionsWithPredicatesAnimalDataTest.java | 357 ++++++---- 2 files changed, 612 insertions(+), 371 deletions(-) diff --git a/src/test/java/examples/animal/data/AnimalDataTest.java b/src/test/java/examples/animal/data/AnimalDataTest.java index 1a0dfbe3d..a051434dc 100644 --- a/src/test/java/examples/animal/data/AnimalDataTest.java +++ b/src/test/java/examples/animal/data/AnimalDataTest.java @@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.within; +import static org.junit.jupiter.api.Assertions.assertAll; import static org.mybatis.dynamic.sql.SqlBuilder.*; import java.io.InputStream; @@ -96,8 +97,10 @@ void testSelectAllRows() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(animals).hasSize(65); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(animals).hasSize(65), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -113,8 +116,10 @@ void testSelectAllRowsWithRowBounds() { RowBounds rowBounds = new RowBounds(4, 6); List animals = mapper.selectManyWithRowBounds(selectStatement, rowBounds); - assertThat(animals).hasSize(6); - assertThat(animals.get(0).getId()).isEqualTo(5); + assertAll( + () -> assertThat(animals).hasSize(6), + () -> assertThat(animals.get(0).getId()).isEqualTo(5) + ); } } @@ -128,8 +133,10 @@ void testSelectAllRowsWithOrder() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(animals).hasSize(65); - assertThat(animals.get(0).getId()).isEqualTo(65); + assertAll( + () -> assertThat(animals).hasSize(65), + () -> assertThat(animals.get(0).getId()).isEqualTo(65) + ); } } @@ -143,10 +150,12 @@ void testSelectAllRowsAllColumns() { .build() .render(RenderingStrategies.MYBATIS3); List> animals = mapper.selectManyMappedRows(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData order by id DESC"); - assertThat(animals).hasSize(65); - assertThat(animals.get(0)).containsEntry("ID", 65); - assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData order by id DESC"), + () -> assertThat(animals).hasSize(65), + () -> assertThat(animals.get(0)).containsEntry("ID", 65), + () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "Brachiosaurus") + ); } } @@ -160,9 +169,11 @@ void testSelectAllRowsAllColumnsWithOrder() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData order by id DESC"); - assertThat(animals).hasSize(65); - assertThat(animals.get(0).getId()).isEqualTo(65); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select * from AnimalData order by id DESC"), + () -> assertThat(animals).hasSize(65), + () -> assertThat(animals.get(0).getId()).isEqualTo(65) + ); } } @@ -176,9 +187,11 @@ void testSelectAllRowsAllColumnsWithOrderAndAlias() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select ad.* from AnimalData ad order by id DESC"); - assertThat(animals).hasSize(65); - assertThat(animals.get(0).getId()).isEqualTo(65); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select ad.* from AnimalData ad order by id DESC"), + () -> assertThat(animals).hasSize(65), + () -> assertThat(animals.get(0).getId()).isEqualTo(65) + ); } } @@ -391,11 +404,13 @@ void testUnionSelectWithWhere() { + "where id > #{parameters.p2,jdbcType=INTEGER}"; List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(44); - assertThat(selectStatement.getParameters()).hasSize(2); - assertThat(selectStatement.getParameters()).containsEntry("p1", 20); - assertThat(selectStatement.getParameters()).containsEntry("p2", 40); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(44), + () -> assertThat(selectStatement.getParameters()).hasSize(2), + () -> assertThat(selectStatement.getParameters()).containsEntry("p1", 20), + () -> assertThat(selectStatement.getParameters()).containsEntry("p2", 40) + ); } } @@ -421,9 +436,11 @@ void testUnionSelectWithoutWhere() { + "order by id"; List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(65); - assertThat(selectStatement.getParameters()).isEmpty(); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(65), + () -> assertThat(selectStatement.getParameters()).isEmpty() + ); } } @@ -449,9 +466,11 @@ void testUnionAllSelectWithoutWhere() { + "order by id"; List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(130); - assertThat(selectStatement.getParameters()).isEmpty(); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(130), + () -> assertThat(selectStatement.getParameters()).isEmpty() + ); } } @@ -481,11 +500,14 @@ void testUnionSelectWithTableAliases() { + "order by id"; List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(44); - assertThat(selectStatement.getParameters()).hasSize(2); - assertThat(selectStatement.getParameters()).containsEntry("p1", 20); - assertThat(selectStatement.getParameters()).containsEntry("p2", 40); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(44), + () -> assertThat(selectStatement.getParameters()).hasSize(2), + () -> assertThat(selectStatement.getParameters()).containsEntry("p1", 20), + () -> assertThat(selectStatement.getParameters()).containsEntry("p2", 40) + ); } } @@ -515,11 +537,14 @@ void testUnionAllSelectWithTableAliases() { + "order by id"; List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(44); - assertThat(selectStatement.getParameters()).hasSize(2); - assertThat(selectStatement.getParameters()).containsEntry("p1", 20); - assertThat(selectStatement.getParameters()).containsEntry("p2", 40); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(44), + () -> assertThat(selectStatement.getParameters()).hasSize(2), + () -> assertThat(selectStatement.getParameters()).containsEntry("p1", 20), + () -> assertThat(selectStatement.getParameters()).containsEntry("p2", 40) + ); } } @@ -549,11 +574,14 @@ void testUnionSelectWithTableAndColumnAliases() { + "order by animalId"; List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(44); - assertThat(selectStatement.getParameters()).hasSize(2); - assertThat(selectStatement.getParameters()).containsEntry("p1", 20); - assertThat(selectStatement.getParameters()).containsEntry("p2", 40); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(44), + () -> assertThat(selectStatement.getParameters()).hasSize(2), + () -> assertThat(selectStatement.getParameters()).containsEntry("p1", 20), + () -> assertThat(selectStatement.getParameters()).containsEntry("p2", 40) + ); } } @@ -809,9 +837,12 @@ void testLikeCaseInsensitive() { .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(animals).hasSize(2); - assertThat(animals.get(0).getAnimalName()).isEqualTo("Ground squirrel"); - assertThat(animals.get(1).getAnimalName()).isEqualTo("Artic ground squirrel"); + + assertAll( + () -> assertThat(animals).hasSize(2), + () -> assertThat(animals.get(0).getAnimalName()).isEqualTo("Ground squirrel"), + () -> assertThat(animals.get(1).getAnimalName()).isEqualTo("Artic ground squirrel") + ); } } @@ -827,9 +858,12 @@ void testLikeLowerCase() { .render(RenderingStrategies.MYBATIS3); List> animals = mapper.selectManyMappedRows(selectStatement); - assertThat(animals).hasSize(2); - assertThat(animals.get(0)).containsEntry("ANIMALNAME", "ground squirrel"); - assertThat(animals.get(1)).containsEntry("ANIMALNAME", "artic ground squirrel"); + + assertAll( + () -> assertThat(animals).hasSize(2), + () -> assertThat(animals.get(0)).containsEntry("ANIMALNAME", "ground squirrel"), + () -> assertThat(animals.get(1)).containsEntry("ANIMALNAME", "artic ground squirrel") + ); } } @@ -845,9 +879,12 @@ void testLikeUpperCase() { .render(RenderingStrategies.MYBATIS3); List> animals = mapper.selectManyMappedRows(selectStatement); - assertThat(animals).hasSize(2); - assertThat(animals.get(0)).containsEntry("ANIMALNAME", "GROUND SQUIRREL"); - assertThat(animals.get(1)).containsEntry("ANIMALNAME", "ARTIC GROUND SQUIRREL"); + + assertAll( + () -> assertThat(animals).hasSize(2), + () -> assertThat(animals.get(0)).containsEntry("ANIMALNAME", "GROUND SQUIRREL"), + () -> assertThat(animals.get(1)).containsEntry("ANIMALNAME", "ARTIC GROUND SQUIRREL") + ); } } @@ -887,14 +924,17 @@ void testNumericConstant() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(3); - assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); - assertThat(animals.get(0)).containsEntry("SOME_NUMBER", 3); - assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); - assertThat(animals.get(1)).containsEntry("SOME_NUMBER", 3); - assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); - assertThat(animals.get(2)).containsEntry("SOME_NUMBER", 3); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(3), + () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), + () -> assertThat(animals.get(0)).containsEntry("SOME_NUMBER", 3), + () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), + () -> assertThat(animals.get(1)).containsEntry("SOME_NUMBER", 3), + () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), + () -> assertThat(animals.get(2)).containsEntry("SOME_NUMBER", 3) + ); } } @@ -914,14 +954,17 @@ void testStringConstant() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(3); - assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); - assertThat(animals.get(0)).containsEntry("SOME_STRING", "fred"); - assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); - assertThat(animals.get(1)).containsEntry("SOME_STRING", "fred"); - assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); - assertThat(animals.get(2)).containsEntry("SOME_STRING", "fred"); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(3), + () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), + () -> assertThat(animals.get(0)).containsEntry("SOME_STRING", "fred"), + () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), + () -> assertThat(animals.get(1)).containsEntry("SOME_STRING", "fred"), + () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), + () -> assertThat(animals.get(2)).containsEntry("SOME_STRING", "fred") + ); } } @@ -941,14 +984,17 @@ void testAdd() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(3); - assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); - assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 12366.0); - assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); - assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 11750.0); - assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); - assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 87154.5); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(3), + () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), + () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 12366.0), + () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), + () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 11750.0), + () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), + () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 87154.5) + ); } } @@ -968,14 +1014,17 @@ void testAddConstant() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(3); - assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); - assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 5767.0); - assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); - assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 105.0); - assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); - assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 209.5); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(3), + () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), + () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 5767.0), + () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), + () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 105.0), + () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), + () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 209.5) + ); } } @@ -995,14 +1044,17 @@ void testAddConstantWithConstantFirst() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(3); - assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); - assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 5767.0); - assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); - assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 105.0); - assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); - assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 209.5); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(3), + () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), + () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 5767.0), + () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), + () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 105.0), + () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), + () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 209.5) + ); } } @@ -1022,11 +1074,14 @@ void testConcat() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(3); - assertThat(animals.get(0)).containsEntry("DISPLAY_NAME", "African elephant - The Legend"); - assertThat(animals.get(1)).containsEntry("DISPLAY_NAME", "Dipliodocus - The Legend"); - assertThat(animals.get(2)).containsEntry("DISPLAY_NAME", "Brachiosaurus - The Legend"); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(3), + () -> assertThat(animals.get(0)).containsEntry("DISPLAY_NAME", "African elephant - The Legend"), + () -> assertThat(animals.get(1)).containsEntry("DISPLAY_NAME", "Dipliodocus - The Legend"), + () -> assertThat(animals.get(2)).containsEntry("DISPLAY_NAME", "Brachiosaurus - The Legend") + ); } } @@ -1046,11 +1101,14 @@ void testConcatenate() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(3); - assertThat(animals.get(0)).containsEntry("DISPLAY_NAME", "African elephant - The Legend"); - assertThat(animals.get(1)).containsEntry("DISPLAY_NAME", "Dipliodocus - The Legend"); - assertThat(animals.get(2)).containsEntry("DISPLAY_NAME", "Brachiosaurus - The Legend"); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(3), + () -> assertThat(animals.get(0)).containsEntry("DISPLAY_NAME", "African elephant - The Legend"), + () -> assertThat(animals.get(1)).containsEntry("DISPLAY_NAME", "Dipliodocus - The Legend"), + () -> assertThat(animals.get(2)).containsEntry("DISPLAY_NAME", "Brachiosaurus - The Legend") + ); } } @@ -1070,11 +1128,14 @@ void testConcatenateConstantFirst() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(3); - assertThat(animals.get(0)).containsEntry("DISPLAY_NAME", "Name: African elephant"); - assertThat(animals.get(1)).containsEntry("DISPLAY_NAME", "Name: Dipliodocus"); - assertThat(animals.get(2)).containsEntry("DISPLAY_NAME", "Name: Brachiosaurus"); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(3), + () -> assertThat(animals.get(0)).containsEntry("DISPLAY_NAME", "Name: African elephant"), + () -> assertThat(animals.get(1)).containsEntry("DISPLAY_NAME", "Name: Dipliodocus"), + () -> assertThat(animals.get(2)).containsEntry("DISPLAY_NAME", "Name: Brachiosaurus") + ); } } @@ -1094,14 +1155,17 @@ void testDivide() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(3); - assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); - assertThat((Double) animals.get(0).get("CALCULATED_WEIGHT")).isEqualTo(0.858, within(0.001)); - assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); - assertThat((Double) animals.get(1).get("CALCULATED_WEIGHT")).isEqualTo(0.004, within(0.001)); - assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); - assertThat((Double) animals.get(2).get("CALCULATED_WEIGHT")).isEqualTo(0.001, within(0.001)); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(3), + () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), + () -> assertThat((Double) animals.get(0).get("CALCULATED_WEIGHT")).isEqualTo(0.858, within(0.001)), + () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), + () -> assertThat((Double) animals.get(1).get("CALCULATED_WEIGHT")).isEqualTo(0.004, within(0.001)), + () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), + () -> assertThat((Double) animals.get(2).get("CALCULATED_WEIGHT")).isEqualTo(0.001, within(0.001)) + ); } } @@ -1121,14 +1185,17 @@ void testDivideConstant() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(3); - assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); - assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 571.2); - assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); - assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 5.0); - assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); - assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 15.45); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(3), + () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), + () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 571.2), + () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), + () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 5.0), + () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), + () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 15.45) + ); } } @@ -1148,14 +1215,17 @@ void testMultiply() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(3); - assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); - assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 38007648.0); - assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); - assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 585000.0); - assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); - assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 13441500.0); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(3), + () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), + () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 38007648.0), + () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), + () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 585000.0), + () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), + () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 13441500.0) + ); } } @@ -1175,14 +1245,17 @@ void testMultiplyConstant() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(3); - assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); - assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 11424.0); - assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); - assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 100.0); - assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); - assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 309.0); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(3), + () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), + () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 11424.0), + () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), + () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 100.0), + () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), + () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 309.0) + ); } } @@ -1202,14 +1275,17 @@ void testSubtract() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(3); - assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); - assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", -942.0); - assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); - assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", -11650.0); - assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); - assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", -86845.5); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(3), + () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), + () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", -942.0), + () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), + () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", -11650.0), + () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), + () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", -86845.5) + ); } } @@ -1229,14 +1305,17 @@ void testSubtractConstant() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(3); - assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); - assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 5706.5); - assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); - assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 44.5); - assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); - assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 149.0); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(3), + () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), + () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 5706.5), + () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), + () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 44.5), + () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), + () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 149.0) + ); } } @@ -1256,14 +1335,17 @@ void testGeneralOperator() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(3); - assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); - assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", -942.0); - assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); - assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", -11650.0); - assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); - assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", -86845.5); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(3), + () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), + () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", -942.0), + () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), + () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", -11650.0), + () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), + () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", -86845.5) + ); } } @@ -1283,14 +1365,17 @@ void testComplexExpression() { + "where (a.body_weight + a.brain_weight) > #{parameters.p1,jdbcType=DOUBLE}"; List> animals = mapper.selectManyMappedRows(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo(expected); - assertThat(animals).hasSize(3); - assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"); - assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 38068.0); - assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"); - assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 11973.0); - assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"); - assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 87847.75); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo(expected), + () -> assertThat(animals).hasSize(3), + () -> assertThat(animals.get(0)).containsEntry("ANIMAL_NAME", "African elephant"), + () -> assertThat(animals.get(0)).containsEntry("CALCULATED_WEIGHT", 38068.0), + () -> assertThat(animals.get(1)).containsEntry("ANIMAL_NAME", "Dipliodocus"), + () -> assertThat(animals.get(1)).containsEntry("CALCULATED_WEIGHT", 11973.0), + () -> assertThat(animals.get(2)).containsEntry("ANIMAL_NAME", "Brachiosaurus"), + () -> assertThat(animals.get(2)).containsEntry("CALCULATED_WEIGHT", 87847.75) + ); } } @@ -1552,13 +1637,16 @@ record = new AnimalData(); .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(animals).hasSize(2); - assertThat(animals.get(0).getId()).isEqualTo(100); - assertThat(animals.get(0).getBrainWeight()).isEqualTo(1.2); - assertThat(animals.get(0).getAnimalName()).isNull(); - assertThat(animals.get(1).getId()).isEqualTo(101); - assertThat(animals.get(1).getBrainWeight()).isEqualTo(1.2); - assertThat(animals.get(1).getAnimalName()).isNull(); + + assertAll( + () -> assertThat(animals).hasSize(2), + () -> assertThat(animals.get(0).getId()).isEqualTo(100), + () -> assertThat(animals.get(0).getBrainWeight()).isEqualTo(1.2), + () -> assertThat(animals.get(0).getAnimalName()).isNull(), + () -> assertThat(animals.get(1).getId()).isEqualTo(101), + () -> assertThat(animals.get(1).getBrainWeight()).isEqualTo(1.2), + () -> assertThat(animals.get(1).getAnimalName()).isNull() + ); } } @@ -1599,13 +1687,16 @@ record = new AnimalData(); .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(animals).hasSize(2); - assertThat(animals.get(0).getId()).isEqualTo(100); - assertThat(animals.get(0).getBrainWeight()).isEqualTo(1.2); - assertThat(animals.get(0).getAnimalName()).isEqualTo("Old Fred"); - assertThat(animals.get(1).getId()).isEqualTo(101); - assertThat(animals.get(1).getBrainWeight()).isEqualTo(1.2); - assertThat(animals.get(1).getAnimalName()).isEqualTo("Old Fred"); + + assertAll( + () -> assertThat(animals).hasSize(2), + () -> assertThat(animals.get(0).getId()).isEqualTo(100), + () -> assertThat(animals.get(0).getBrainWeight()).isEqualTo(1.2), + () -> assertThat(animals.get(0).getAnimalName()).isEqualTo("Old Fred"), + () -> assertThat(animals.get(1).getId()).isEqualTo(101), + () -> assertThat(animals.get(1).getBrainWeight()).isEqualTo(1.2), + () -> assertThat(animals.get(1).getAnimalName()).isEqualTo("Old Fred") + ); } } @@ -1623,8 +1714,11 @@ void testOrderByAndDistinct() { .render(RenderingStrategies.MYBATIS3); List rows = mapper.selectMany(selectStatement); - assertThat(rows).hasSize(14); - assertThat(rows.get(0).getId()).isEqualTo(65); + + assertAll( + () -> assertThat(rows).hasSize(14), + () -> assertThat(rows.get(0).getId()).isEqualTo(65) + ); } } @@ -1642,8 +1736,11 @@ void testOrderByWithFullClause() { .render(RenderingStrategies.MYBATIS3); List rows = mapper.selectMany(selectStatement); - assertThat(rows).hasSize(14); - assertThat(rows.get(0).getId()).isEqualTo(65); + + assertAll( + () -> assertThat(rows).hasSize(14), + () -> assertThat(rows.get(0).getId()).isEqualTo(65) + ); } } @@ -1658,8 +1755,11 @@ void testCount() { .render(RenderingStrategies.MYBATIS3); Long count = mapper.selectOneLong(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select count(*) as total from AnimalData a"); - assertThat(count).isEqualTo(65); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select count(*) as total from AnimalData a"), + () -> assertThat(count).isEqualTo(65) + ); } } @@ -1674,8 +1774,11 @@ void testCountField() { .render(RenderingStrategies.MYBATIS3); Long count = mapper.selectOneLong(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select count(a.brain_weight) as total from AnimalData a"); - assertThat(count).isEqualTo(65); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select count(a.brain_weight) as total from AnimalData a"), + () -> assertThat(count).isEqualTo(65) + ); } } @@ -1690,8 +1793,11 @@ void testCountNoAlias() { .render(RenderingStrategies.MYBATIS3); Long count = mapper.selectOneLong(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select count(*) from AnimalData"); - assertThat(count).isEqualTo(65); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select count(*) from AnimalData"), + () -> assertThat(count).isEqualTo(65) + ); } } @@ -1706,8 +1812,11 @@ void testMax() { .render(RenderingStrategies.MYBATIS3); Double max = mapper.selectOneDouble(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select max(a.brain_weight) as total from AnimalData a"); - assertThat(max).isEqualTo(87000.0); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select max(a.brain_weight) as total from AnimalData a"), + () -> assertThat(max).isEqualTo(87000.0) + ); } } @@ -1722,8 +1831,11 @@ void testMaxNoAlias() { .render(RenderingStrategies.MYBATIS3); Double max = mapper.selectOneDouble(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select max(brain_weight) from AnimalData"); - assertThat(max).isEqualTo(87000.0); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select max(brain_weight) from AnimalData"), + () -> assertThat(max).isEqualTo(87000.0) + ); } } @@ -1739,9 +1851,12 @@ void testMaxSubselect() { .render(RenderingStrategies.MYBATIS3); List records = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight = (select max(b.brain_weight) from AnimalData b)"); - assertThat(records).hasSize(1); - assertThat(records.get(0).getAnimalName()).isEqualTo("Brachiosaurus"); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight = (select max(b.brain_weight) from AnimalData b)"), + () -> assertThat(records).hasSize(1), + () -> assertThat(records.get(0).getAnimalName()).isEqualTo("Brachiosaurus") + ); } } @@ -1756,8 +1871,11 @@ void testMin() { .render(RenderingStrategies.MYBATIS3); Double min = mapper.selectOneDouble(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select min(a.brain_weight) as total from AnimalData a"); - assertThat(min).isEqualTo(0.005); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select min(a.brain_weight) as total from AnimalData a"), + () -> assertThat(min).isEqualTo(0.005) + ); } } @@ -1772,8 +1890,11 @@ void testMinNoAlias() { .render(RenderingStrategies.MYBATIS3); Double min = mapper.selectOneDouble(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select min(brain_weight) from AnimalData"); - assertThat(min).isEqualTo(0.005); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select min(brain_weight) from AnimalData"), + () -> assertThat(min).isEqualTo(0.005) + ); } } @@ -1790,9 +1911,12 @@ void testMinSubselect() { .render(RenderingStrategies.MYBATIS3); List records = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight <> (select min(b.brain_weight) from AnimalData b) order by animal_name"); - assertThat(records).hasSize(64); - assertThat(records.get(0).getAnimalName()).isEqualTo("African elephant"); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight <> (select min(b.brain_weight) from AnimalData b) order by animal_name"), + () -> assertThat(records).hasSize(64), + () -> assertThat(records.get(0).getAnimalName()).isEqualTo("African elephant") + ); } } @@ -1809,9 +1933,12 @@ void testMinSubselectNoAlias() { .render(RenderingStrategies.MYBATIS3); List records = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where brain_weight <> (select min(brain_weight) from AnimalData) order by animal_name"); - assertThat(records).hasSize(64); - assertThat(records.get(0).getAnimalName()).isEqualTo("African elephant"); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where brain_weight <> (select min(brain_weight) from AnimalData) order by animal_name"), + () -> assertThat(records).hasSize(64), + () -> assertThat(records.get(0).getAnimalName()).isEqualTo("African elephant") + ); } } @@ -1826,8 +1953,11 @@ void testAvg() { .render(RenderingStrategies.MYBATIS3); Double average = mapper.selectOneDouble(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select avg(a.brain_weight) as average from AnimalData a"); - assertThat(average).isEqualTo(1852.69, within(.01)); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select avg(a.brain_weight) as average from AnimalData a"), + () -> assertThat(average).isEqualTo(1852.69, within(.01)) + ); } } @@ -1842,8 +1972,11 @@ void testSum() { .render(RenderingStrategies.MYBATIS3); Double total = mapper.selectOneDouble(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select sum(brain_weight) as total from AnimalData"); - assertThat(total).isEqualTo(120424.97, within(.01)); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select sum(brain_weight) as total from AnimalData"), + () -> assertThat(total).isEqualTo(120424.97, within(.01)) + ); } } @@ -1859,8 +1992,11 @@ void testLessThanSubselect() { .render(RenderingStrategies.MYBATIS3); List records = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight < (select max(b.brain_weight) from AnimalData b)"); - assertThat(records).hasSize(64); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight < (select max(b.brain_weight) from AnimalData b)"), + () -> assertThat(records).hasSize(64) + ); } } @@ -1876,8 +2012,11 @@ void testLessThanOrEqualToSubselect() { .render(RenderingStrategies.MYBATIS3); List records = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight <= (select max(b.brain_weight) from AnimalData b)"); - assertThat(records).hasSize(65); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight <= (select max(b.brain_weight) from AnimalData b)"), + () -> assertThat(records).hasSize(65) + ); } } @@ -1893,8 +2032,11 @@ void testGreaterThanSubselect() { .render(RenderingStrategies.MYBATIS3); List records = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight > (select min(b.brain_weight) from AnimalData b)"); - assertThat(records).hasSize(64); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight > (select min(b.brain_weight) from AnimalData b)"), + () -> assertThat(records).hasSize(64) + ); } } @@ -1910,8 +2052,11 @@ void testGreaterThanOrEqualToSubselect() { .render(RenderingStrategies.MYBATIS3); List records = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight >= (select min(b.brain_weight) from AnimalData b)"); - assertThat(records).hasSize(65); + + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select a.id, a.animal_name, a.body_weight, a.brain_weight from AnimalData a where a.brain_weight >= (select min(b.brain_weight) from AnimalData b)"), + () -> assertThat(records).hasSize(65) + ); } } @@ -1933,10 +2078,13 @@ void testInsertSelectWithColumnList() { + "where id < #{parameters.p1,jdbcType=INTEGER}"; int rows = mapper.insertSelect(insertSelectStatement); - assertThat(insertSelectStatement.getInsertStatement()).isEqualTo(expected); - assertThat(insertSelectStatement.getParameters()).hasSize(1); - assertThat(insertSelectStatement.getParameters()).containsEntry("p1", 22); - assertThat(rows).isEqualTo(21); + + assertAll( + () -> assertThat(insertSelectStatement.getInsertStatement()).isEqualTo(expected), + () -> assertThat(insertSelectStatement.getParameters()).hasSize(1), + () -> assertThat(insertSelectStatement.getParameters()).containsEntry("p1", 22), + () -> assertThat(rows).isEqualTo(21) + ); } } @@ -1956,10 +2104,13 @@ void testInsertSelectWithoutColumnList() { + "from AnimalData " + "where id < #{parameters.p1,jdbcType=INTEGER}"; int rows = mapper.insertSelect(insertSelectStatement); - assertThat(insertSelectStatement.getInsertStatement()).isEqualTo(expected); - assertThat(insertSelectStatement.getParameters()).hasSize(1); - assertThat(insertSelectStatement.getParameters()).containsEntry("p1", 33); - assertThat(rows).isEqualTo(32); + + assertAll( + () -> assertThat(insertSelectStatement.getInsertStatement()).isEqualTo(expected), + () -> assertThat(insertSelectStatement.getParameters()).hasSize(1), + () -> assertThat(insertSelectStatement.getParameters()).containsEntry("p1", 33), + () -> assertThat(rows).isEqualTo(32) + ); } } @@ -2059,11 +2210,14 @@ void testUpdateWithSelect() { + "set brain_weight = (select avg(brain_weight) from AnimalData where brain_weight > #{parameters.p1,jdbcType=DOUBLE}) " + "where brain_weight < #{parameters.p2,jdbcType=DOUBLE}"; int rows = mapper.update(updateStatement); - assertThat(updateStatement.getUpdateStatement()).isEqualTo(expected); - assertThat(updateStatement.getParameters()).hasSize(2); - assertThat(updateStatement.getParameters()).containsEntry("p1", 22.0); - assertThat(updateStatement.getParameters()).containsEntry("p2", 1.0); - assertThat(rows).isEqualTo(20); + + assertAll( + () -> assertThat(updateStatement.getUpdateStatement()).isEqualTo(expected), + () -> assertThat(updateStatement.getParameters()).hasSize(2), + () -> assertThat(updateStatement.getParameters()).containsEntry("p1", 22.0), + () -> assertThat(updateStatement.getParameters()).containsEntry("p2", 1.0), + () -> assertThat(rows).isEqualTo(20) + ); } } diff --git a/src/test/java/examples/animal/data/OptionalConditionsWithPredicatesAnimalDataTest.java b/src/test/java/examples/animal/data/OptionalConditionsWithPredicatesAnimalDataTest.java index 3b011f83b..2cfaab8bb 100644 --- a/src/test/java/examples/animal/data/OptionalConditionsWithPredicatesAnimalDataTest.java +++ b/src/test/java/examples/animal/data/OptionalConditionsWithPredicatesAnimalDataTest.java @@ -21,6 +21,7 @@ import static examples.animal.data.AnimalDataDynamicSqlSupport.brainWeight; import static examples.animal.data.AnimalDataDynamicSqlSupport.id; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; import static org.mybatis.dynamic.sql.SqlBuilder.*; import java.io.InputStream; @@ -82,10 +83,12 @@ void testAllIgnored() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData order by id"); - assertThat(animals).hasSize(65); - assertThat(animals.get(0).getId()).isEqualTo(1); - assertThat(animals.get(1).getId()).isEqualTo(2); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData order by id"), + () -> assertThat(animals).hasSize(65), + () -> assertThat(animals.get(0).getId()).isEqualTo(1), + () -> assertThat(animals.get(1).getId()).isEqualTo(2) + ); } } @@ -102,10 +105,12 @@ void testIgnoredBetweenRendered() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(2); - assertThat(animals.get(0).getId()).isEqualTo(3); - assertThat(animals.get(1).getId()).isEqualTo(4); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(2), + () -> assertThat(animals.get(0).getId()).isEqualTo(3), + () -> assertThat(animals.get(1).getId()).isEqualTo(4) + ); } } @@ -122,10 +127,12 @@ void testIgnoredInWhere() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(2); - assertThat(animals.get(0).getId()).isEqualTo(3); - assertThat(animals.get(1).getId()).isEqualTo(4); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(2), + () -> assertThat(animals.get(0).getId()).isEqualTo(3), + () -> assertThat(animals.get(1).getId()).isEqualTo(4) + ); } } @@ -143,10 +150,12 @@ void testManyIgnored() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(2); - assertThat(animals.get(0).getId()).isEqualTo(3); - assertThat(animals.get(1).getId()).isEqualTo(4); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(2), + () -> assertThat(animals.get(0).getId()).isEqualTo(3), + () -> assertThat(animals.get(1).getId()).isEqualTo(4) + ); } } @@ -162,10 +171,12 @@ void testIgnoredInitialWhere() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(2); - assertThat(animals.get(0).getId()).isEqualTo(3); - assertThat(animals.get(1).getId()).isEqualTo(4); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} or id = #{parameters.p2,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(2), + () -> assertThat(animals.get(0).getId()).isEqualTo(3), + () -> assertThat(animals.get(1).getId()).isEqualTo(4) + ); } } @@ -180,9 +191,11 @@ void testEqualWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(1); - assertThat(animals.get(0).getId()).isEqualTo(4); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id = #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(1), + () -> assertThat(animals.get(0).getId()).isEqualTo(4) + ); } } @@ -198,9 +211,11 @@ void testEqualWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(10); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(10), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -216,9 +231,11 @@ void testNotEqualWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <> #{parameters.p1,jdbcType=INTEGER} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(9); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <> #{parameters.p1,jdbcType=INTEGER} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(9), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -234,9 +251,11 @@ void testNotEqualWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(10); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(10), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -252,9 +271,11 @@ void testGreaterThanWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id > #{parameters.p1,jdbcType=INTEGER} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(6); - assertThat(animals.get(0).getId()).isEqualTo(5); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id > #{parameters.p1,jdbcType=INTEGER} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(6), + () -> assertThat(animals.get(0).getId()).isEqualTo(5) + ); } } @@ -270,9 +291,11 @@ void testGreaterThanWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(10); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(10), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -288,9 +311,11 @@ void testGreaterThanOrEqualToWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id >= #{parameters.p1,jdbcType=INTEGER} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(7); - assertThat(animals.get(0).getId()).isEqualTo(4); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id >= #{parameters.p1,jdbcType=INTEGER} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(7), + () -> assertThat(animals.get(0).getId()).isEqualTo(4) + ); } } @@ -306,9 +331,11 @@ void testGreaterThanOrEqualToWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(10); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(10), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -323,9 +350,11 @@ void testLessThanWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id < #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(3); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id < #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(3), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -341,9 +370,11 @@ void testLessThanWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(10); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(10), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -358,9 +389,11 @@ void testLessThanOrEqualToWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(4); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(4), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -376,9 +409,11 @@ void testLessThanOrEqualToWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(10); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(10), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -393,9 +428,11 @@ void testIsInWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER},#{parameters.p3,jdbcType=INTEGER}) order by id"); - assertThat(animals).hasSize(3); - assertThat(animals.get(0).getId()).isEqualTo(4); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER},#{parameters.p3,jdbcType=INTEGER}) order by id"), + () -> assertThat(animals).hasSize(3), + () -> assertThat(animals.get(0).getId()).isEqualTo(4) + ); } } @@ -410,10 +447,12 @@ void testIsInWhenWithSomeValues() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER}) order by id"); - assertThat(animals).hasSize(2); - assertThat(animals.get(0).getId()).isEqualTo(6); - assertThat(animals.get(1).getId()).isEqualTo(8); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER}) order by id"), + () -> assertThat(animals).hasSize(2), + () -> assertThat(animals.get(0).getId()).isEqualTo(6), + () -> assertThat(animals.get(1).getId()).isEqualTo(8) + ); } } @@ -428,9 +467,11 @@ void testIsInCaseInsensitiveWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) order by id"); - assertThat(animals).hasSize(2); - assertThat(animals.get(0).getId()).isEqualTo(4); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) order by id"), + () -> assertThat(animals).hasSize(2), + () -> assertThat(animals.get(0).getId()).isEqualTo(4) + ); } } @@ -448,9 +489,11 @@ void testValueStreamTransformer() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) order by id"); - assertThat(animals).hasSize(2); - assertThat(animals.get(0).getId()).isEqualTo(4); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) order by id"), + () -> assertThat(animals).hasSize(2), + () -> assertThat(animals.get(0).getId()).isEqualTo(4) + ); } } @@ -465,9 +508,11 @@ void testValueStreamTransformerWithCustomCondition() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) order by id"); - assertThat(animals).hasSize(2); - assertThat(animals.get(0).getId()).isEqualTo(4); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) order by id"), + () -> assertThat(animals).hasSize(2), + () -> assertThat(animals.get(0).getId()).isEqualTo(4) + ); } } @@ -483,9 +528,11 @@ void testIsInCaseInsensitiveWhenWithNoValues() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(10); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(10), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -501,9 +548,11 @@ void testIsNotInWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id not in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER},#{parameters.p3,jdbcType=INTEGER}) and id <= #{parameters.p4,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(7); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id not in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER},#{parameters.p3,jdbcType=INTEGER}) and id <= #{parameters.p4,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(7), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -519,9 +568,11 @@ void testIsNotInWhenWithSomeValues() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id not in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER}) and id <= #{parameters.p3,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(8); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id not in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER}) and id <= #{parameters.p3,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(8), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -537,9 +588,11 @@ void testIsNotInCaseInsensitiveWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) not in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) and id <= #{parameters.p3,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(8); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) not in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) and id <= #{parameters.p3,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(8), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -555,9 +608,11 @@ void testIsNotInCaseInsensitiveWhenWithNoValues() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(10); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(10), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -572,9 +627,11 @@ void testIsBetweenWhenWithValues() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id between #{parameters.p1,jdbcType=INTEGER} and #{parameters.p2,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(4); - assertThat(animals.get(0).getId()).isEqualTo(3); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id between #{parameters.p1,jdbcType=INTEGER} and #{parameters.p2,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(4), + () -> assertThat(animals.get(0).getId()).isEqualTo(3) + ); } } @@ -590,9 +647,11 @@ void testIsBetweenWhenWithFirstMissing() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(10); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(10), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -608,9 +667,11 @@ void testIsBetweenWhenWithSecondMissing() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(10); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(10), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -626,9 +687,11 @@ void testIsBetweenWhenWithBothMissing() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(10); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(10), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -644,9 +707,11 @@ void testIsNotBetweenWhenWithValues() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id not between #{parameters.p1,jdbcType=INTEGER} and #{parameters.p2,jdbcType=INTEGER} and id <= #{parameters.p3,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(6); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id not between #{parameters.p1,jdbcType=INTEGER} and #{parameters.p2,jdbcType=INTEGER} and id <= #{parameters.p3,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(6), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -662,9 +727,11 @@ void testIsNotBetweenWhenWithFirstMissing() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(10); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(10), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -680,9 +747,11 @@ void testIsNotBetweenWhenWithSecondMissing() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(10); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(10), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -698,9 +767,11 @@ void testIsNotBetweenWhenWithBothMissing() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(10); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(10), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -716,9 +787,11 @@ void testIsLikeWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(2); - assertThat(animals.get(0).getId()).isEqualTo(6); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(2), + () -> assertThat(animals.get(0).getId()).isEqualTo(6) + ); } } @@ -734,9 +807,11 @@ void testIsLikeWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(10); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(10), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -752,9 +827,11 @@ void testIsLikeCaseInsensitiveWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(2); - assertThat(animals.get(0).getId()).isEqualTo(6); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(2), + () -> assertThat(animals.get(0).getId()).isEqualTo(6) + ); } } @@ -770,9 +847,11 @@ void testIsLikeCaseInsensitiveWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(10); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(10), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -788,9 +867,11 @@ void testIsNotLikeWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name not like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(8); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where animal_name not like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(8), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -806,9 +887,11 @@ void testIsNotLikeWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(10); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(10), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -824,9 +907,11 @@ void testIsNotLikeCaseInsensitiveWhenWithValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) not like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(8); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) not like #{parameters.p1,jdbcType=VARCHAR} and id <= #{parameters.p2,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(8), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } @@ -842,9 +927,11 @@ void testIsNotLikeCaseInsensitiveWhenWithoutValue() { .build() .render(RenderingStrategies.MYBATIS3); List animals = mapper.selectMany(selectStatement); - assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"); - assertThat(animals).hasSize(10); - assertThat(animals.get(0).getId()).isEqualTo(1); + assertAll( + () -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id <= #{parameters.p1,jdbcType=INTEGER} order by id"), + () -> assertThat(animals).hasSize(10), + () -> assertThat(animals.get(0).getId()).isEqualTo(1) + ); } } } From 2e52e4f4743a0d0ba4af1b3cf57479b703e71bb2 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Sat, 18 May 2024 08:58:18 -0400 Subject: [PATCH 09/11] Documentation --- CHANGELOG.md | 13 +- src/site/markdown/docs/conditions.md | 218 ++++++++++++++---------- src/site/markdown/docs/configuration.md | 1 - 3 files changed, 137 insertions(+), 95 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ce1aa731..0358768c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,16 @@ This log will detail notable changes to MyBatis Dynamic SQL. Full details are av ## Release 1.5.2 - Unreleased -This is a small maintenance release with improvements to the Kotlin DSL for CASE expressions. We worked on this soon -after the 1.5.1 release, so wanted to get it out quickly. -See this PR for details: ([#785](https://github.com/mybatis/mybatis-dynamic-sql/pull/785)) +This is a small maintenance release with the following changes: + +1. Improvements to the Kotlin DSL for CASE expressions (infix methods for "else" and "then"). See this PR for + details: ([#785](https://github.com/mybatis/mybatis-dynamic-sql/pull/785)) +2. **Potentially Breaking Change**: the "in" conditions ("isIn", "isNotIn", "isInCaseInsensitive", + "isNotInCaseInsensitive") will now render if the input list of values is empty. This will lead + to a runtime exception. This change was made out of an abundance of caution and is the safest choice. + If you wish to allow "in" conditions to be removed from where clauses when the list is empty, + then use the "when present" versions of those conditions. Please see the discussion here for details + https://github.com/mybatis/mybatis-dynamic-sql/issues/788 GitHub milestone: [https://github.com/mybatis/mybatis-dynamic-sql/milestone/14?closed=1](https://github.com/mybatis/mybatis-dynamic-sql/milestone/14?closed=1) diff --git a/src/site/markdown/docs/conditions.md b/src/site/markdown/docs/conditions.md index 4c52e6d3b..699393ce0 100644 --- a/src/site/markdown/docs/conditions.md +++ b/src/site/markdown/docs/conditions.md @@ -11,56 +11,56 @@ In the following examples: Simple conditions are the most common - they render the basic SQL operators. -| Condition | Example | Result | -|-----------|---------|--------| -| Between | where(foo, isBetween(x).and(y)) | `where foo between ? and ?` | -| Equals | where(foo, isEqualTo(x)) | `where foo = ?` | -| Greater Than | where(foo, isGreaterThan(x)) | `where foo > ?` | -| Greater Than or Equals | where(foo, isGreaterThanOrEqualTo(x)) | `where foo >= ?` | -| In | where(foo, isIn(x, y)) | `where foo in (?,?)` | -| In (case insensitive) | where(foo, isInCaseInsensitive(x, y)) | `where upper(foo) in (?,?)` (the framework will transform the values for x and y to upper case)| -| Less Than | where(foo, isLessThan(x)) | `where foo < ?` | -| Less Than or Equals | where(foo, isLessThanOrEqualTo(x)) | `where foo <= ?` | -| Like | where(foo, isLike(x)) | `where foo like ?` (the framework DOES NOT add the SQL wild cards to the value - you will need to do that yourself) | -| Like (case insensitive) | where(foo, isLikeCaseInsensitive(x)) | `where upper(foo) like ?` (the framework DOES NOT add the SQL wild cards to the value - you will need to do that yourself, the framework will transform the value of x to upper case) | -| Not Between | where(foo, isNotBetween(x).and(y)) | `where foo not between ? and ?` | -| Not Equals | where(foo, isNotEqualTo(x)) | `where foo <> ?` | -| Not In | where(foo, isNotIn(x, y)) | `where foo not in (?,?)` | -| Not In (case insensitive) | where(foo, isNotInCaseInsensitive(x, y)) | `where upper(foo) not in (?,?)` (the framework will transform the values for x and y to upper case)| -| Not Like | where(foo, isNotLike(x)) | `where foo not like ?` (the framework DOES NOT add the SQL wild cards to the value - you will need to do that yourself) | -| Not Like (case insensitive) | where(foo, isNotLikeCaseInsensitive(x)) | `where upper(foo) not like ?` (the framework DOES NOT add the SQL wild cards to the value - you will need to do that yourself, the framework will transform the value of x to upper case) | -| Not Null | where(foo, isNotNull()) | `where foo is not null` | -| Null | where(foo, isNull()) | `where foo is null` | +| Condition | Example | Result | +|-----------------------------|------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Between | where(foo, isBetween(x).and(y)) | `where foo between ? and ?` | +| Equals | where(foo, isEqualTo(x)) | `where foo = ?` | +| Greater Than | where(foo, isGreaterThan(x)) | `where foo > ?` | +| Greater Than or Equals | where(foo, isGreaterThanOrEqualTo(x)) | `where foo >= ?` | +| In | where(foo, isIn(x, y)) | `where foo in (?,?)` | +| In (case insensitive) | where(foo, isInCaseInsensitive(x, y)) | `where upper(foo) in (?,?)` (the framework will transform the values for x and y to upper case) | +| Less Than | where(foo, isLessThan(x)) | `where foo < ?` | +| Less Than or Equals | where(foo, isLessThanOrEqualTo(x)) | `where foo <= ?` | +| Like | where(foo, isLike(x)) | `where foo like ?` (the framework DOES NOT add the SQL wild cards to the value - you will need to do that yourself) | +| Like (case insensitive) | where(foo, isLikeCaseInsensitive(x)) | `where upper(foo) like ?` (the framework DOES NOT add the SQL wild cards to the value - you will need to do that yourself, the framework will transform the value of x to upper case) | +| Not Between | where(foo, isNotBetween(x).and(y)) | `where foo not between ? and ?` | +| Not Equals | where(foo, isNotEqualTo(x)) | `where foo <> ?` | +| Not In | where(foo, isNotIn(x, y)) | `where foo not in (?,?)` | +| Not In (case insensitive) | where(foo, isNotInCaseInsensitive(x, y)) | `where upper(foo) not in (?,?)` (the framework will transform the values for x and y to upper case) | +| Not Like | where(foo, isNotLike(x)) | `where foo not like ?` (the framework DOES NOT add the SQL wild cards to the value - you will need to do that yourself) | +| Not Like (case insensitive) | where(foo, isNotLikeCaseInsensitive(x)) | `where upper(foo) not like ?` (the framework DOES NOT add the SQL wild cards to the value - you will need to do that yourself, the framework will transform the value of x to upper case) | +| Not Null | where(foo, isNotNull()) | `where foo is not null` | +| Null | where(foo, isNull()) | `where foo is null` | ## Subqueries Many conditions can be rendered with subqueries. -| Condition | Example | Result | -|-----------|---------|--------| -| Equals | where(foo, isEqualTo(select(bar).from(table2).where(bar, isEqualTo(x))) | `where foo = (select bar from table2 where bar = ?)` | -| Greater Than | where(foo, isGreaterThan(select(bar).from(table2).where(bar, isEqualTo(x))) | `where foo > (select bar from table2 where bar = ?)` | -| Greater Than or Equals | where(foo, isGreaterThanOrEqualTo(select(bar).from(table2).where(bar, isEqualTo(x))) | `where foo >= (select bar from table2 where bar = ?)` | -| In | where(foo, isIn(select(bar).from(table2).where(bar, isLessThan(x))) | `where foo in (select bar from table2 where bar < ?)` | -| Less Than | where(foo, isLessThan(select(bar).from(table2).where(bar, isEqualTo(x))) | `where foo < (select bar from table2 where bar = ?)` | -| Less Than or Equals | where(foo, isLessThanOrEqualTo(select(bar).from(table2).where(bar, isEqualTo(x))) | `where foo <= (select bar from table2 where bar = ?)` | -| Not Equals | where(foo, isNotEqualTo(select(bar).from(table2).where(bar, isEqualTo(x))) | `where foo <> (select bar from table2 where bar = ?)` | -| Not In | where(foo, isNotIn(select(bar).from(table2).where(bar, isLessThan(x))) | `where foo not in (select bar from table2 where bar < ?)` | +| Condition | Example | Result | +|-------------------------|--------------------------------------------------------------------------------------|-----------------------------------------------------------| +| Equals | where(foo, isEqualTo(select(bar).from(table2).where(bar, isEqualTo(x))) | `where foo = (select bar from table2 where bar = ?)` | +| Greater Than | where(foo, isGreaterThan(select(bar).from(table2).where(bar, isEqualTo(x))) | `where foo > (select bar from table2 where bar = ?)` | +| Greater Than or Equals | where(foo, isGreaterThanOrEqualTo(select(bar).from(table2).where(bar, isEqualTo(x))) | `where foo >= (select bar from table2 where bar = ?)` | +| In | where(foo, isIn(select(bar).from(table2).where(bar, isLessThan(x))) | `where foo in (select bar from table2 where bar < ?)` | +| Less Than | where(foo, isLessThan(select(bar).from(table2).where(bar, isEqualTo(x))) | `where foo < (select bar from table2 where bar = ?)` | +| Less Than or Equals | where(foo, isLessThanOrEqualTo(select(bar).from(table2).where(bar, isEqualTo(x))) | `where foo <= (select bar from table2 where bar = ?)` | +| Not Equals | where(foo, isNotEqualTo(select(bar).from(table2).where(bar, isEqualTo(x))) | `where foo <> (select bar from table2 where bar = ?)` | +| Not In | where(foo, isNotIn(select(bar).from(table2).where(bar, isLessThan(x))) | `where foo not in (select bar from table2 where bar < ?)` | ## Column Comparison Conditions Column comparison conditions can be used to write where clauses comparing the values of columns in a table. -| Condition | Example | Result | -|-----------|---------|--------| -| Equals | where(foo, isEqualTo(bar)) | `where foo = bar` | -| Greater Than | where(foo, isGreaterThan(bar)) | `where foo > bar` | +| Condition | Example | Result | +|------------------------|-----------------------------------------|--------------------| +| Equals | where(foo, isEqualTo(bar)) | `where foo = bar` | +| Greater Than | where(foo, isGreaterThan(bar)) | `where foo > bar` | | Greater Than or Equals | where(foo, isGreaterThanOrEqualTo(bar)) | `where foo >= bar` | -| Less Than | where(foo, isLessThan(bar)) | `where foo < bar` | -| Less Than or Equals | where(foo, isLessThanOrEqualTo(bar)) | `where foo <= bar` | -| Not Equals | where(foo, isNotEqualTo(bar)) | `where foo <> bar` | +| Less Than | where(foo, isLessThan(bar)) | `where foo < bar` | +| Less Than or Equals | where(foo, isLessThanOrEqualTo(bar)) | `where foo <= bar` | +| Not Equals | where(foo, isNotEqualTo(bar)) | `where foo <> bar` | ## Value Transformation @@ -69,14 +69,14 @@ associated with the condition before the statement is rendered. The map function standard `map` functions on Streams and Optionals - it allows you to transform a value and change the data type. For example, suppose you want to code a wild card search with the SQL `like` operator. To make this work, you will -need to append SQL wildcards to the search value. This can be accomplished directly i the condition with a `map` +need to append SQL wildcards to the search value. This can be accomplished directly in the condition with a `map` method as follows: ```java List search(String searchName) { SelectStatementProvider selectStatement=select(id,animalName,bodyWeight,brainWeight) .from(animalData) - .where(animalName,isLike(searchName).map(s->"%"+s+"%")) + .where(animalName,isLike(searchName).map(s -> "%"+s+"%")) .orderBy(id) .build() .render(RenderingStrategies.MYBATIS3); @@ -85,7 +85,7 @@ List search(String searchName) { } ``` -You can see the `map` method accepts a lambda that adds SQL wildcards to the `searchName` field. This is more succint +You can see the `map` method accepts a lambda that adds SQL wildcards to the `searchName` field. This is more succinct if you use a method reference: ```java @@ -111,7 +111,7 @@ below: 1. The `Between` and `NotBetween` conditions have `map` methods that accept one or two map functions. If you pass one function, it will be applied to both values in the condition. If you supply two functions, then they will be applied to the first and second values respectively. -1. The `In` and `NotIn` conditions accept a single mapping function and it will be applied to all values in the +2. The `In` and `NotIn` conditions accept a single mapping function, and it will be applied to all values in the collection of values in the condition. ## Optional Conditions @@ -146,43 +146,43 @@ The lambdas will all be of standard JDK types (either `java.util.function.Boolea `java.util.function.Predicate`, or `java.util.function.BiPredicate` depending on the type of condition). The following table lists the optional conditions and shows how to use them: -| Condition | Example | Rendering Rules | -|-----------|---------|-----------------| -| Between| where(foo, isBetween(x).and(y).filter(BiPredicate)) | The library will pass x and y to the BiPredicate's test method. The condition will render if BiPredicate.test(x, y) returns true | -| Between| where(foo, isBetween(x).and(y).filter(Predicate)) | The library will invoke the Predicate's test method twice - once with x, once with y. The condition will render if both function calls return true | -| Equals | where(foo, isEqualTo(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | -| Greater Than | where(id, isGreaterThan(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | -| Greater Than or Equals | where(id, isGreaterThanOrEqualTo(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | -| Less Than | where(id, isLessThan(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | -| Less Than or Equals | where(id, isLessThanOrEqualTo(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | -| Like | where(id, isLike(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | -| Like Case Insensitive | where(id, isLikeCaseInsensitive(x).filter(Predicate<String>)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | -| Not Between | where(id, isNotBetween(x).and(y).filter(BiPredicate)) | The library will pass x and y to the BiPredicate's test method. The condition will render if BiPredicate.test(x, y) returns true | -| Not Between| where(foo, isNotBetween(x).and(y).filter(Predicate)) | The library will invoke the Predicate's test method twice - once with x, once with y. The condition will render if both function calls return true | -| Not Equals | where(id, isNotEqualTo(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | -| Not Like | where(id, isNotLike(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | -| Not Like Case Insensitive | where(id, isNotLikeCaseInsensitive(x).filter(Predicate<String>)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | -| Not Null | where(id, isNotNull().filter(BooleanSupplier) | The condition will render if BooleanSupplier.getAsBoolean() returns true | -| Null | where(id, isNull().filter(BooleanSupplier) | The condition will render if BooleanSupplier.getAsBoolean() returns true | +| Condition | Example | Rendering Rules | +|---------------------------|------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------| +| Between | where(foo, isBetween(x).and(y).filter(BiPredicate)) | The library will pass x and y to the BiPredicate's test method. The condition will render if BiPredicate.test(x, y) returns true | +| Between | where(foo, isBetween(x).and(y).filter(Predicate)) | The library will invoke the Predicate's test method twice - once with x, once with y. The condition will render if both function calls return true | +| Equals | where(foo, isEqualTo(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | +| Greater Than | where(id, isGreaterThan(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | +| Greater Than or Equals | where(id, isGreaterThanOrEqualTo(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | +| Less Than | where(id, isLessThan(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | +| Less Than or Equals | where(id, isLessThanOrEqualTo(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | +| Like | where(id, isLike(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | +| Like Case Insensitive | where(id, isLikeCaseInsensitive(x).filter(Predicate<String>)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | +| Not Between | where(id, isNotBetween(x).and(y).filter(BiPredicate)) | The library will pass x and y to the BiPredicate's test method. The condition will render if BiPredicate.test(x, y) returns true | +| Not Between | where(foo, isNotBetween(x).and(y).filter(Predicate)) | The library will invoke the Predicate's test method twice - once with x, once with y. The condition will render if both function calls return true | +| Not Equals | where(id, isNotEqualTo(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | +| Not Like | where(id, isNotLike(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | +| Not Like Case Insensitive | where(id, isNotLikeCaseInsensitive(x).filter(Predicate<String>)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true | +| Not Null | where(id, isNotNull().filter(BooleanSupplier) | The condition will render if BooleanSupplier.getAsBoolean() returns true | +| Null | where(id, isNull().filter(BooleanSupplier) | The condition will render if BooleanSupplier.getAsBoolean() returns true | ### "When Present" Condition Builders The library supplies several methods that supply conditions to be used in the common case of checking for null values. The table below lists the rendering rules for each of these "when present" condition builder methods. -| Condition | Example | Rendering Rules | -|-----------|---------|-----------------| -| Between| where(foo, isBetweenWhenPresent(x).and(y)) | The condition will render if both x and y values are non-null | -| Equals | where(foo, isEqualToWhenPresent(x)) | The condition will render if x is non-null | -| Greater Than | where(id, isGreaterThanWhenPresent(x)) | The condition will render if x is non-null | -| Greater Than or Equals | where(id, isGreaterThanOrEqualToWhenPresent(x)) | The condition will render if x is non-null | -| Less Than | where(id, isLessThanWhenPresent(x)) | The condition will render if x is non-null | -| Less Than orEquals | where(id, isLessThanOrEqualToWhenPresent(x)) | The condition will render if x is non-null | -| Like | where(id, isLikeWhenPresent(x)) | The condition will render if x is non-null | -| Like Case Insensitive | where(id, isLikeCaseInsensitiveWhenPresent(x)) | The condition will render if x is non-null | -| Not Between | where(id, isNotBetweenWhenPresent(x).and(y)) | The condition will render if both x and y values are non-null | -| Not Equals | where(id, isNotEqualToWhenPresent(x)) | The condition will render if x is non-null | -| Not Like | where(id, isNotLikeWhenPresent(x)) | The condition will render if x is non-null | -| Not Like Case Insensitive | where(id, isNotLikeCaseInsensitiveWhenPresent(x)) | The condition will render if x is non-null | +| Condition | Example | Rendering Rules | +|---------------------------|---------------------------------------------------|---------------------------------------------------------------| +| Between | where(foo, isBetweenWhenPresent(x).and(y)) | The condition will render if both x and y values are non-null | +| Equals | where(foo, isEqualToWhenPresent(x)) | The condition will render if x is non-null | +| Greater Than | where(id, isGreaterThanWhenPresent(x)) | The condition will render if x is non-null | +| Greater Than or Equals | where(id, isGreaterThanOrEqualToWhenPresent(x)) | The condition will render if x is non-null | +| Less Than | where(id, isLessThanWhenPresent(x)) | The condition will render if x is non-null | +| Less Than orEquals | where(id, isLessThanOrEqualToWhenPresent(x)) | The condition will render if x is non-null | +| Like | where(id, isLikeWhenPresent(x)) | The condition will render if x is non-null | +| Like Case Insensitive | where(id, isLikeCaseInsensitiveWhenPresent(x)) | The condition will render if x is non-null | +| Not Between | where(id, isNotBetweenWhenPresent(x).and(y)) | The condition will render if both x and y values are non-null | +| Not Equals | where(id, isNotEqualToWhenPresent(x)) | The condition will render if x is non-null | +| Not Like | where(id, isNotLikeWhenPresent(x)) | The condition will render if x is non-null | +| Not Like Case Insensitive | where(id, isNotLikeCaseInsensitiveWhenPresent(x)) | The condition will render if x is non-null | Note that these methods simply apply a "NotNull" filter to a condition. For example: @@ -193,34 +193,70 @@ Note that these methods simply apply a "NotNull" filter to a condition. For exa ``` ### Optionality with the "In" Conditions -Optionality with the "in" and "not in" conditions is a bit more complex than the other types of conditions. The first -thing to know is that no "in" or "not in" condition will render if the list of values is empty. For example, there -will never be rendered SQL like `where name in ()`. So optionality of the "in" conditions is more about optionality +Optionality with the "in" and "not in" conditions is a bit more complex than the other types of conditions. The rules +are different for the base conditions ("isIn", "isNotIn", etc.) and the "when present" conditions ("isInWhenPresent", +"isNotInWhenPresent", etc.). + +Optionality of the "in" conditions is more about optionality of the *values* of the condition. The library comes with functions that will filter out null values, and will upper -case String values to enable case insensitive queries. There are extension points to add additional filtering and +case String values to enable case-insensitive queries. There are extension points to add additional filtering and mapping if you so desire. -The following table shows the different supplied In conditions and how they will render for different sets of inputs. +Starting with version 1.5.2, we made a change to the rendering rules for the "in" conditions. This was done to limit the +danger of conditions failing to render and thus affecting more rows than expected. For the base conditions ("isIn", +"isNotIn", etc.), if the list of values is empty, then the condition will still render, but the resulting SQL will +be invalid and will cause a runtime exception. We believe this is the safest outcome. For example, suppose +a DELETE statement was coded as follows: + +```java + delete.from(foo) + .where(status, isTrue()) + .and(id, isIn(Collections.emptyList())); +``` + +This statement will be rendered as follows: + +```sql + delete from foo where status = ? and id in () +``` + +This will cause a runtime error due to invalid SQL, but it eliminates the possibility of deleting ALL active rows with +active status. If you want to allow the "in" condition to drop from the SQL if the list is empty, then use the +"inWhenPresent" condition. + +The following table shows the effect of different inputs on "in" and "inWhenPresent". The same rules apply to "notIn" +and the case-insensitive versions of these conditions: + +| Input | Effect | +|------------------------------------------|-----------------------------------------------------------------------------------| +| isIn(null) | NullPointerException | +| isIn(Collections.emptyList()) | Rendered as "in ()" (Invalid SQL) | +| isIn(2, 3, null) | Rendered as "in (?, ?, ?)" (Parameter values are 2, 3, and null) | +| isInWhenPresent(null) | Condition Not Rendered | +| isInWhenPresent(Collections.emptyList()) | Condition Not Rendered | +| isInWhenPresent(2, 3, null) | Rendered as "in (?, ?)" (Parameter values are 2 and 3. The null value is dropped) | + + +The following table shows the different "in" conditions and how they will render for different sets of inputs. The table assumes the following types of input: - Example 1 assumes an input list of ("foo", null, "bar") - like `where(name, isIn("foo", null, "bar"))` - Example 2 assumes an input list of (null) - like `where(name, isIn((String)null))` -| Condition | Nulls Filtered | Strings Mapped to Uppercase | Example 1 Rendering | Example 2 Rendering | -|-----------|----------------|--------------------|---------------------|---------------------| -| IsIn| No | No| name in ('foo', null, 'bar') | name in (null) | -| IsInWhenPresent | Yes | No | name in ('foo', 'bar') | No Render | -| IsInCaseInsensitive | No | Yes | upper(name) in ('FOO', null, 'BAR') | upper(name) in (null) | -| IsInCaseInsensitiveWhenPresent | Yes | Yes | upper(name) in ('FOO', 'BAR') | No Render | -| IsNotIn| No | No| name not in ('foo', null, 'bar') | name not in (null) | -| IsNotInWhenPresent | Yes | No | name not in ('foo', 'bar') | No render | -| IsNotInCaseInsensitive | No | Yes | upper(name) not in ('FOO', null, 'BAR') | upper(name) not in (null) | -| IsNotInCaseInsensitiveWhenPresent | Yes | Yes | upper(name) not in ('FOO', 'BAR') | No Render | +| Condition | Nulls Filtered | Strings Mapped to Uppercase | Example 1 Rendering | Example 2 Rendering | +|-----------------------------------|----------------|-----------------------------|-----------------------------------------|---------------------------| +| IsIn | No | No | name in ('foo', null, 'bar') | name in (null) | +| IsInWhenPresent | Yes | No | name in ('foo', 'bar') | Not Rendered | +| IsInCaseInsensitive | No | Yes | upper(name) in ('FOO', null, 'BAR') | upper(name) in (null) | +| IsInCaseInsensitiveWhenPresent | Yes | Yes | upper(name) in ('FOO', 'BAR') | Not Rendered | +| IsNotIn | No | No | name not in ('foo', null, 'bar') | name not in (null) | +| IsNotInWhenPresent | Yes | No | name not in ('foo', 'bar') | Not Rendered | +| IsNotInCaseInsensitive | No | Yes | upper(name) not in ('FOO', null, 'BAR') | upper(name) not in (null) | +| IsNotInCaseInsensitiveWhenPresent | Yes | Yes | upper(name) not in ('FOO', 'BAR') | Not Rendered | If none of these options meet your needs, the "In" conditions also support "map" and "filter" methods for the values. -This gives you great flexibility to alter or filter the value list before the condition -is rendered. +This gives you great flexibility to alter or filter the value list before the condition is rendered. For example, suppose you wanted to code an "in" condition that accepted a list of strings, but you want to filter out any null or blank string, and you want to trim all strings. This can be accomplished with code like this: @@ -266,7 +302,7 @@ Then the condition could be used in a query as follows: ## Potential for Non Rendering Where Clauses -An "in" condition will always be dropped from rendering if the list of values is empty. Other conditions could be +An "inWhenPresent" condition will be dropped from rendering if the list of values is empty. Other conditions could be dropped from a where clause due to filtering. If all conditions fail to render, then the entire where clause will be dropped from the rendered SQL. In general, we think it is a good thing that the library will not render invalid SQL. But this stance does present a danger - if a where clause is dropped from the rendered SQL, then the statement could diff --git a/src/site/markdown/docs/configuration.md b/src/site/markdown/docs/configuration.md index 0d24672bc..4c228a55d 100644 --- a/src/site/markdown/docs/configuration.md +++ b/src/site/markdown/docs/configuration.md @@ -20,7 +20,6 @@ The configuration file is a standard Java properties file. The possible values a | Property | Default | Available in Version | Meaning | |------------------------------------|---------|----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| emptyListConditionRenderingAllowed | false | 1.5.1+ | If a list condition ("in", "not in", etc.) has an empty list - either though its initial values, or through filtering, the condition will be dropped from the where clause by default. If you set this value to true, then the condition will render even though the resulting SQL will be invalid. This will likely cause an SQLException at runtime, but it could be viewed as a protective measure so that statements do not effect more rows than desired. | | nonRenderingWhereClauseAllowed | false | 1.4.1+ | If a where clause is specified, but fails to render, then the library will throw a `NonRenderingWhereClauseException` by default. If you set this value to true, then no exception will be thrown. This could enable statements to be rendered without where clauses that affect all rows in a table. | ## Statement Configuration From 7b4947591f26dbbc818cabb82ac513442e0f4f71 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Sat, 18 May 2024 09:01:40 -0400 Subject: [PATCH 10/11] Documentation --- src/site/markdown/docs/conditions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/site/markdown/docs/conditions.md b/src/site/markdown/docs/conditions.md index 699393ce0..b7fde71bf 100644 --- a/src/site/markdown/docs/conditions.md +++ b/src/site/markdown/docs/conditions.md @@ -220,7 +220,7 @@ This statement will be rendered as follows: delete from foo where status = ? and id in () ``` -This will cause a runtime error due to invalid SQL, but it eliminates the possibility of deleting ALL active rows with +This will cause a runtime error due to invalid SQL, but it eliminates the possibility of deleting ALLs rows with active status. If you want to allow the "in" condition to drop from the SQL if the list is empty, then use the "inWhenPresent" condition. From f5a53189a93a71e32d75c41943e557a207df930c Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Sun, 19 May 2024 13:56:45 -0400 Subject: [PATCH 11/11] Documentation --- CHANGELOG.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0358768c3..1f9c7a154 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,8 +12,9 @@ This is a small maintenance release with the following changes: "isNotInCaseInsensitive") will now render if the input list of values is empty. This will lead to a runtime exception. This change was made out of an abundance of caution and is the safest choice. If you wish to allow "in" conditions to be removed from where clauses when the list is empty, - then use the "when present" versions of those conditions. Please see the discussion here for details - https://github.com/mybatis/mybatis-dynamic-sql/issues/788 + then use the "when present" versions of those conditions. If you are unsure how this works, please + read the documentation here: https://mybatis.org/mybatis-dynamic-sql/docs/conditions.html#optionality-with-the-%E2%80%9Cin%E2%80%9D-conditions + For background on the reason for the change, see the discussion here: https://github.com/mybatis/mybatis-dynamic-sql/issues/788 GitHub milestone: [https://github.com/mybatis/mybatis-dynamic-sql/milestone/14?closed=1](https://github.com/mybatis/mybatis-dynamic-sql/milestone/14?closed=1) @@ -41,8 +42,8 @@ We've tested this extensively and the code is, of course, 100% covered by test c covered every scenario. Please let us know if you find issues. Full documentation is available here: -- [Java Case Expression DSL Documentation](caseExpressions.md) -- [Kotlin Case Expression DSL Documentation](kotlinCaseExpressions.md) +- [Java Case Expression DSL Documentation](https://mybatis.org/mybatis-dynamic-sql/docs/caseExpressions.html) +- [Kotlin Case Expression DSL Documentation](https://mybatis.org/mybatis-dynamic-sql/docs/kotlinCaseExpressions.html) The pull request for this change is ([#761](https://github.com/mybatis/mybatis-dynamic-sql/pull/761))