diff --git a/src/main/java/org/mybatis/dynamic/sql/AbstractListValueCondition.java b/src/main/java/org/mybatis/dynamic/sql/AbstractListValueCondition.java index 3de332ca8..bfd841df7 100644 --- a/src/main/java/org/mybatis/dynamic/sql/AbstractListValueCondition.java +++ b/src/main/java/org/mybatis/dynamic/sql/AbstractListValueCondition.java @@ -17,7 +17,6 @@ import java.util.Collection; import java.util.Objects; -import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Predicate; import java.util.function.Supplier; @@ -27,32 +26,8 @@ public abstract class AbstractListValueCondition implements VisitableCondition { protected final Collection values; - /** - * Callback to execute when the list is empty. - * - * @deprecated in favor of the statement configuration functions - */ - @Deprecated - protected final Callback emptyCallback; - protected AbstractListValueCondition(Collection values) { - this(values, () -> { }); - } - - /** - * Construct a new condition with a callback. - * - * @param values - * values - * @param emptyCallback - * empty callback - * - * @deprecated in favor of the statement configuration functions - */ - @Deprecated - protected AbstractListValueCondition(Collection values, Callback emptyCallback) { this.values = Objects.requireNonNull(values); - this.emptyCallback = Objects.requireNonNull(emptyCallback); } public final Stream mapValues(Function mapper) { @@ -64,11 +39,6 @@ public boolean shouldRender() { return !values.isEmpty(); } - @Override - public void renderingSkipped() { - emptyCallback.call(); - } - @Override public R accept(ConditionVisitor visitor) { return visitor.visit(this); @@ -85,19 +55,19 @@ private Collection applyFilter(Predicate predicate) { } protected > S filterSupport(Predicate predicate, - BiFunction, Callback, S> constructor, S self, Supplier emptySupplier) { + Function, S> constructor, S self, Supplier emptySupplier) { if (shouldRender()) { Collection filtered = applyFilter(predicate); - return filtered.isEmpty() ? emptySupplier.get() : constructor.apply(filtered, emptyCallback); + return filtered.isEmpty() ? emptySupplier.get() : constructor.apply(filtered); } else { return self; } } protected > S mapSupport(Function mapper, - BiFunction, Callback, S> constructor, Supplier emptySupplier) { + Function, S> constructor, Supplier emptySupplier) { if (shouldRender()) { - return constructor.apply(applyMapper(mapper), emptyCallback); + return constructor.apply(applyMapper(mapper)); } else { return emptySupplier.get(); } @@ -115,18 +85,5 @@ protected > S mapSupport(Function filter(Predicate predicate); - /** - * Specifies a callback function to be called if the value list is empty when rendered. - * - * @param callback - * a callback function - typically throws an exception to block the statement from executing - * - * @return this condition - * - * @deprecated in favor of the statement configuration functions - */ - @Deprecated - public abstract AbstractListValueCondition withListEmptyCallback(Callback callback); - public abstract String renderCondition(String columnName, Stream placeholders); } diff --git a/src/main/java/org/mybatis/dynamic/sql/Callback.java b/src/main/java/org/mybatis/dynamic/sql/Callback.java deleted file mode 100644 index a950e7f01..000000000 --- a/src/main/java/org/mybatis/dynamic/sql/Callback.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2016-2022 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * 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; - -import java.util.function.Function; - -/** - * Provides a callback function for empty "in" conditions. - * - * @deprecated in favor of the new statement configuration functionality - */ -@Deprecated -@FunctionalInterface -public interface Callback { - void call(); - - static Callback exceptionThrowingCallback(String message) { - return exceptionThrowingCallback(message, RuntimeException::new); - } - - static Callback exceptionThrowingCallback(String message, - Function exceptionBuilder) { - return () -> { - throw exceptionBuilder.apply(message); - }; - } -} diff --git a/src/main/java/org/mybatis/dynamic/sql/insert/render/DefaultInsertStatementProvider.java b/src/main/java/org/mybatis/dynamic/sql/insert/render/DefaultInsertStatementProvider.java index 8b4cb6c39..f554f4daa 100644 --- a/src/main/java/org/mybatis/dynamic/sql/insert/render/DefaultInsertStatementProvider.java +++ b/src/main/java/org/mybatis/dynamic/sql/insert/render/DefaultInsertStatementProvider.java @@ -24,6 +24,9 @@ public class DefaultInsertStatementProvider implements InsertStatementProvide // need to keep both row and record for now so we don't break // old code. The MyBatis reflection utilities don't handle // the case where the attribute name is different from the getter. + // + // MyBatis Generator version 1.4.1 (March 8, 2022) changed to use "row" instead of "record". + // Target March 2023 for removing "record" from MyBatis Dynamic SQL. private final T record; private final T row; 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 2a68dd84c..3fd7e9ee1 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 @@ -20,14 +20,12 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; import org.mybatis.dynamic.sql.AbstractListValueCondition; -import org.mybatis.dynamic.sql.Callback; public class IsIn extends AbstractListValueCondition { private static final IsIn EMPTY = new IsIn<>(Collections.emptyList()); @@ -38,62 +36,19 @@ public static IsIn empty() { return t; } - /** - * Build an empty condition. - * - * @return a new empty condition - * - * @deprecated in favor of the statement configuration functions - */ - @Deprecated - private IsIn emptyWithCallBack() { - return new IsIn<>(Collections.emptyList(), emptyCallback); - } - protected IsIn(Collection values) { super(values); } - /** - * Build a new condition with a callback. - * - * @param values - * values - * @param emptyCallback - * empty callback - * - * @deprecated in favor of the statement configuration functions - */ - @Deprecated - protected IsIn(Collection values, Callback emptyCallback) { - super(values, emptyCallback); - } - @Override public String renderCondition(String columnName, Stream placeholders) { return spaceAfter(columnName) + placeholders.collect(Collectors.joining(",", "in (", ")")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } - /** - * Build a new condition with a callback. - * - * @param callback - * a callback function - typically throws an exception to block the statement from executing - * - * @return this condition - * - * @deprecated in favor of the statement configuration functions - */ - @Deprecated - @Override - public IsIn withListEmptyCallback(Callback callback) { - return new IsIn<>(values, callback); - } - @Override public IsIn filter(Predicate predicate) { - return filterSupport(predicate, IsIn::new, this, this::emptyWithCallBack); + return filterSupport(predicate, IsIn::new, this, IsIn::empty); } /** @@ -106,8 +61,8 @@ public IsIn filter(Predicate predicate) { * that will not render. */ public IsIn map(Function mapper) { - BiFunction, Callback, IsIn> constructor = IsIn::new; - return mapSupport(mapper, constructor, this::emptyWithCallBack); + Function, IsIn> constructor = IsIn::new; + return mapSupport(mapper, constructor, IsIn::empty); } @SafeVarargs 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 390868dc4..8f10945a8 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 @@ -24,7 +24,6 @@ import java.util.stream.Stream; import org.mybatis.dynamic.sql.AbstractListValueCondition; -import org.mybatis.dynamic.sql.Callback; import org.mybatis.dynamic.sql.util.StringUtilities; public class IsInCaseInsensitive extends AbstractListValueCondition { @@ -34,37 +33,10 @@ public static IsInCaseInsensitive empty() { return EMPTY; } - /** - * Build an empty condition. - * - * @return a new empty condition - * - * @deprecated in favor of the statement configuration functions - */ - @Deprecated - private IsInCaseInsensitive emptyWithCallback() { - return new IsInCaseInsensitive(Collections.emptyList(), emptyCallback); - } - protected IsInCaseInsensitive(Collection values) { super(values); } - /** - * Build a new instance with a callback. - * - * @param values - * values - * @param emptyCallback - * empty callback - * - * @deprecated in favor of the statement configuration functions - */ - @Deprecated - protected IsInCaseInsensitive(Collection values, Callback emptyCallback) { - super(values, emptyCallback); - } - @Override public String renderCondition(String columnName, Stream placeholders) { return "upper(" + columnName + ") " //$NON-NLS-1$ //$NON-NLS-2$ @@ -72,25 +44,9 @@ public String renderCondition(String columnName, Stream placeholders) { Collectors.joining(",", "in (", ")")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } - /** - * Build a new instance with a callback. - * - * @param callback - * a callback function - typically throws an exception to block the statement from executing - * - * @return this condition - * - * @deprecated in favor of the statement configuration functions - */ - @Deprecated - @Override - public IsInCaseInsensitive withListEmptyCallback(Callback callback) { - return new IsInCaseInsensitive(values, callback); - } - @Override public IsInCaseInsensitive filter(Predicate predicate) { - return filterSupport(predicate, IsInCaseInsensitive::new, this, this::emptyWithCallback); + return filterSupport(predicate, IsInCaseInsensitive::new, this, IsInCaseInsensitive::empty); } /** @@ -102,7 +58,7 @@ public IsInCaseInsensitive filter(Predicate predicate) { * that will not render. */ public IsInCaseInsensitive map(UnaryOperator mapper) { - return mapSupport(mapper, IsInCaseInsensitive::new, this::emptyWithCallback); + return mapSupport(mapper, IsInCaseInsensitive::new, IsInCaseInsensitive::empty); } public static IsInCaseInsensitive of(String... values) { 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 11323f954..ccbcfb173 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 @@ -20,14 +20,12 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; import org.mybatis.dynamic.sql.AbstractListValueCondition; -import org.mybatis.dynamic.sql.Callback; public class IsNotIn extends AbstractListValueCondition { private static final IsNotIn EMPTY = new IsNotIn<>(Collections.emptyList()); @@ -38,37 +36,10 @@ public static IsNotIn empty() { return t; } - /** - * Build an empty condition. - * - * @return a new empty condition - * - * @deprecated in favor of the statement configuration functions - */ - @Deprecated - private IsNotIn emptyWithCallback() { - return new IsNotIn<>(Collections.emptyList(), emptyCallback); - } - protected IsNotIn(Collection values) { super(values); } - /** - * Build a new condition with a callback. - * - * @param values - * values - * @param emptyCallback - * empty callback - * - * @deprecated in favor of the statement configuration functions - */ - @Deprecated - protected IsNotIn(Collection values, Callback emptyCallback) { - super(values, emptyCallback); - } - @Override public String renderCondition(String columnName, Stream placeholders) { return spaceAfter(columnName) @@ -76,25 +47,9 @@ public String renderCondition(String columnName, Stream placeholders) { Collectors.joining(",", "not in (", ")")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } - /** - * Build a new instance with a callback. - * - * @param callback - * a callback function - typically throws an exception to block the statement from executing - * - * @return this condition - * - * @deprecated in favor of the statement configuration functions - */ - @Deprecated - @Override - public IsNotIn withListEmptyCallback(Callback callback) { - return new IsNotIn<>(values, callback); - } - @Override public IsNotIn filter(Predicate predicate) { - return filterSupport(predicate, IsNotIn::new, this, this::emptyWithCallback); + return filterSupport(predicate, IsNotIn::new, this, IsNotIn::empty); } /** @@ -107,8 +62,8 @@ public IsNotIn filter(Predicate predicate) { * that will not render. */ public IsNotIn map(Function mapper) { - BiFunction, Callback, IsNotIn> constructor = IsNotIn::new; - return mapSupport(mapper, constructor, this::emptyWithCallback); + Function, IsNotIn> constructor = IsNotIn::new; + return mapSupport(mapper, constructor, IsNotIn::empty); } @SafeVarargs 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 93e4815e4..17a61e276 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 @@ -24,7 +24,6 @@ import java.util.stream.Stream; import org.mybatis.dynamic.sql.AbstractListValueCondition; -import org.mybatis.dynamic.sql.Callback; import org.mybatis.dynamic.sql.util.StringUtilities; public class IsNotInCaseInsensitive extends AbstractListValueCondition { @@ -34,37 +33,10 @@ public static IsNotInCaseInsensitive empty() { return EMPTY; } - /** - * Build an empty condition. - * - * @return a new empty condition - * - * @deprecated in favor of the statement configuration functions - */ - @Deprecated - private IsNotInCaseInsensitive emptyWithCallback() { - return new IsNotInCaseInsensitive(Collections.emptyList(), emptyCallback); - } - protected IsNotInCaseInsensitive(Collection values) { super(values); } - /** - * Build a new instance with a callback. - * - * @param values - * values - * @param emptyCallback - * empty callback - * - * @deprecated in favor of the statement configuration functions - */ - @Deprecated - protected IsNotInCaseInsensitive(Collection values, Callback emptyCallback) { - super(values, emptyCallback); - } - @Override public String renderCondition(String columnName, Stream placeholders) { return "upper(" + columnName + ") " //$NON-NLS-1$ //$NON-NLS-2$ @@ -72,25 +44,9 @@ public String renderCondition(String columnName, Stream placeholders) { Collectors.joining(",", "not in (", ")")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } - /** - * Build a new instance with a callback. - * - * @param callback - * a callback function - typically throws an exception to block the statement from executing - * - * @return this condition - * - * @deprecated in favor of the statement configuration functions - */ - @Deprecated - @Override - public IsNotInCaseInsensitive withListEmptyCallback(Callback callback) { - return new IsNotInCaseInsensitive(values, callback); - } - @Override public IsNotInCaseInsensitive filter(Predicate predicate) { - return filterSupport(predicate, IsNotInCaseInsensitive::new, this, this::emptyWithCallback); + return filterSupport(predicate, IsNotInCaseInsensitive::new, this, IsNotInCaseInsensitive::empty); } /** @@ -102,7 +58,7 @@ public IsNotInCaseInsensitive filter(Predicate predicate) { * that will not render. */ public IsNotInCaseInsensitive map(UnaryOperator mapper) { - return mapSupport(mapper, IsNotInCaseInsensitive::new, this::emptyWithCallback); + return mapSupport(mapper, IsNotInCaseInsensitive::new, IsNotInCaseInsensitive::empty); } public static IsNotInCaseInsensitive of(String... values) { diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/CriteriaCollector.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/CriteriaCollector.kt deleted file mode 100644 index d0a9c8c7b..000000000 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/CriteriaCollector.kt +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2016-2022 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * 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.util.kotlin - -import org.mybatis.dynamic.sql.BindableColumn -import org.mybatis.dynamic.sql.ColumnAndConditionCriterion -import org.mybatis.dynamic.sql.AndOrCriteriaGroup -import org.mybatis.dynamic.sql.ExistsCriterion -import org.mybatis.dynamic.sql.ExistsPredicate -import org.mybatis.dynamic.sql.SqlCriterion -import org.mybatis.dynamic.sql.VisitableCondition - -@Deprecated("Deprecated in favor of the new where clause DSL.") -typealias CriteriaReceiver = CriteriaCollector.() -> Unit - -@Deprecated("Deprecated in favor of the new where clause DSL.") -@MyBatisDslMarker -class CriteriaCollector { - val criteria = mutableListOf() - - fun and( - column: BindableColumn, - condition: VisitableCondition, - criteriaReceiver: CriteriaReceiver = {} - ): Unit = - addCriteriaGroup("and", buildCriterion(column, condition), criteriaReceiver) //$NON-NLS-1$ - - fun and(existsPredicate: ExistsPredicate, criteriaReceiver: CriteriaReceiver = {}): Unit = - addCriteriaGroup("and", buildCriterion(existsPredicate), criteriaReceiver) //$NON-NLS-1$ - - fun or( - column: BindableColumn, - condition: VisitableCondition, - criteriaReceiver: CriteriaReceiver = {} - ): Unit = - addCriteriaGroup("or", buildCriterion(column, condition), criteriaReceiver) //$NON-NLS-1$ - - fun or(existsPredicate: ExistsPredicate, criteriaReceiver: CriteriaReceiver = {}): Unit = - addCriteriaGroup("or", buildCriterion(existsPredicate), criteriaReceiver) //$NON-NLS-1$ - - private fun buildCriterion( - column: BindableColumn, - condition: VisitableCondition - ): ColumnAndConditionCriterion = - ColumnAndConditionCriterion.withColumn(column).withCondition(condition).build() - - private fun buildCriterion(existsPredicate: ExistsPredicate): ExistsCriterion = - ExistsCriterion.Builder().withExistsPredicate(existsPredicate).build() - - private fun addCriteriaGroup( - connector: String, - initialCriterion: SqlCriterion, - criteriaReceiver: CriteriaReceiver - ) { - criteria.add( - AndOrCriteriaGroup.Builder() - .withInitialCriterion(initialCriterion) - .withSubCriteria(CriteriaCollector().apply(criteriaReceiver).criteria) - .withConnector(connector) - .build() - ) - } -} diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/JoinCollector.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/JoinCollector.kt index 67578aa5f..739ceec5d 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/JoinCollector.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/JoinCollector.kt @@ -48,26 +48,6 @@ class JoinCollector { .build() ) } - - @Deprecated("Please use: on(leftColumn) equalTo rightColumn") - fun on(column: BasicColumn, condition: JoinCondition) { - onJoinCriterion = JoinCriterion.Builder() - .withConnector("on") //$NON-NLS-1$ - .withJoinColumn(column) - .withJoinCondition(condition) - .build() - } - - @Deprecated("Please use: and(leftColumn) equalTo rightColumn") - fun and(column: BasicColumn, condition: JoinCondition) { - andJoinCriteria.add( - JoinCriterion.Builder() - .withConnector("and") //$NON-NLS-1$ - .withJoinColumn(column) - .withJoinCondition(condition) - .build() - ) - } } class RightColumnCollector(private val joinConditionConsumer: (JoinCondition) -> Unit) { diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinBaseBuilders.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinBaseBuilders.kt index 8086d047c..2c33ab771 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinBaseBuilders.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinBaseBuilders.kt @@ -15,14 +15,10 @@ */ package org.mybatis.dynamic.sql.util.kotlin -import org.mybatis.dynamic.sql.BindableColumn import org.mybatis.dynamic.sql.AndOrCriteriaGroup -import org.mybatis.dynamic.sql.ExistsPredicate import org.mybatis.dynamic.sql.SqlTable -import org.mybatis.dynamic.sql.VisitableCondition import org.mybatis.dynamic.sql.configuration.StatementConfiguration import org.mybatis.dynamic.sql.select.AbstractQueryExpressionDSL -import org.mybatis.dynamic.sql.where.AbstractWhereDSL import org.mybatis.dynamic.sql.where.AbstractWhereSupport @Target(AnnotationTarget.CLASS, AnnotationTarget.TYPE) @@ -73,96 +69,6 @@ abstract class KotlinBaseBuilder> { fun applyWhere(whereApplier: WhereApplier) = whereApplier.invoke(this) - @Deprecated("Deprecated in favor of the new where clause DSL. Update by moving the column and condition " + - "into a lambda and rewriting the condition to use an infix function.") - fun where(column: BindableColumn, condition: VisitableCondition): Unit = - applyToWhere { - where(column, condition) - } - - @Deprecated("Deprecated in favor of the new where clause DSL. Update by moving the column and condition " + - "inside the lambda and rewriting the condition to use an infix function.") - fun where(column: BindableColumn, condition: VisitableCondition, subCriteria: CriteriaReceiver): Unit = - applyToWhere(subCriteria) { sc -> - where(column, condition, sc) - } - - @Deprecated( - message = "Deprecated in favor of the new where clause DSL.", - replaceWith = ReplaceWith("where { existsPredicate }") - ) - fun where(existsPredicate: ExistsPredicate): Unit = - applyToWhere { - where(existsPredicate) - } - - @Deprecated("Deprecated in favor of the new where clause DSL. Update by moving the exists expression " + - "into the lambda.") - fun where(existsPredicate: ExistsPredicate, subCriteria: CriteriaReceiver): Unit = - applyToWhere(subCriteria) { sc -> - where(existsPredicate, sc) - } - - @Deprecated("Deprecated in favor of the new where clause DSL. Update by moving the column and condition " + - "into a lambda and rewriting the condition to use an infix function.") - fun and(column: BindableColumn, condition: VisitableCondition): Unit = - applyToWhere { - and(column, condition) - } - - @Deprecated("Deprecated in favor of the new where clause DSL. Update by moving the column and condition " + - "inside the lambda and rewriting the condition to use an infix function.") - fun and(column: BindableColumn, condition: VisitableCondition, subCriteria: CriteriaReceiver): Unit = - applyToWhere(subCriteria) { sc -> - and(column, condition, sc) - } - - @Deprecated( - message = "Deprecated in favor of the new where clause DSL.", - replaceWith = ReplaceWith("and { existsPredicate }") - ) - fun and(existsPredicate: ExistsPredicate): Unit = - applyToWhere { - and(existsPredicate) - } - - @Deprecated("Deprecated in favor of the new where clause DSL. Update by moving the exists expression " + - "into the lambda.") - fun and(existsPredicate: ExistsPredicate, subCriteria: CriteriaReceiver): Unit = - applyToWhere(subCriteria) { sc -> - and(existsPredicate, sc) - } - - @Deprecated("Deprecated in favor of the new where clause DSL. Update by moving the column and condition " + - "into a lambda and rewriting the condition to use an infix function.") - fun or(column: BindableColumn, condition: VisitableCondition): Unit = - applyToWhere { - or(column, condition) - } - - @Deprecated("Deprecated in favor of the new where clause DSL. Update by moving the column and condition " + - "inside the lambda and rewriting the condition to use an infix function.") - fun or(column: BindableColumn, condition: VisitableCondition, subCriteria: CriteriaReceiver): Unit = - applyToWhere(subCriteria) { sc -> - or(column, condition, sc) - } - - @Deprecated( - message = "Deprecated in favor of the new where clause DSL.", - replaceWith = ReplaceWith("or { existsPredicate }") - ) - fun or(existsPredicate: ExistsPredicate): Unit = - applyToWhere { - or(existsPredicate) - } - - @Deprecated("Deprecated in favor of the new where clause DSL. Update by moving the exists expression " + - "into the lambda.") - fun or(existsPredicate: ExistsPredicate, subCriteria: CriteriaReceiver): Unit = - applyToWhere(subCriteria) { sc -> - or(existsPredicate, sc) - } - /** * This function does nothing, but it can be used to make some code snippets more understandable. * @@ -179,17 +85,6 @@ abstract class KotlinBaseBuilder> { // intentionally empty - this function exists for code beautification and clarity only } - private fun applyToWhere(block: AbstractWhereDSL<*>.() -> Unit) { - getDsl().where().apply(block) - } - - private fun applyToWhere( - subCriteria: CriteriaReceiver, - block: AbstractWhereDSL<*>.(List) -> Unit - ) { - getDsl().where().block(CriteriaCollector().apply(subCriteria).criteria) - } - protected abstract fun getDsl(): D } diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/InsertStatements.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/InsertStatements.kt deleted file mode 100644 index 7ec1d6dbf..000000000 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/InsertStatements.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2016-2022 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * 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.util.kotlin.elements - -import org.mybatis.dynamic.sql.SqlBuilder -import org.mybatis.dynamic.sql.insert.BatchInsertDSL -import org.mybatis.dynamic.sql.insert.InsertDSL -import org.mybatis.dynamic.sql.insert.MultiRowInsertDSL - -// These insert functions help avoid the use of org.mybatis.dynamic.sql.SqlBuilder in Kotlin - -@Deprecated("Please see the deprecation message on the following \"into\" function for advice") -fun insert(row: T): InsertDSL.IntoGatherer = SqlBuilder.insert(row) - -@Deprecated("Please see the deprecation message on the following \"into\" function for advice") -fun insertBatch(vararg records: T): BatchInsertDSL.IntoGatherer = insertBatch(records.asList()) - -@Deprecated("Please see the deprecation message on the following \"into\" function for advice") -fun insertBatch(records: Collection): BatchInsertDSL.IntoGatherer = SqlBuilder.insertBatch(records) - -@Deprecated("Please see the deprecation message on the following \"into\" function for advice") -fun insertMultiple(vararg records: T): MultiRowInsertDSL.IntoGatherer = insertMultiple(records.asList()) - -@Deprecated("Please see the deprecation message on the following \"into\" function for advice") -fun insertMultiple(records: Collection): MultiRowInsertDSL.IntoGatherer = SqlBuilder.insertMultiple(records) 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 b8fdaf898..b7af8c7c2 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 @@ -20,7 +20,6 @@ import org.mybatis.dynamic.sql.AndOrCriteriaGroup import org.mybatis.dynamic.sql.BasicColumn import org.mybatis.dynamic.sql.BindableColumn import org.mybatis.dynamic.sql.Constant -import org.mybatis.dynamic.sql.ExistsPredicate import org.mybatis.dynamic.sql.SortSpecification import org.mybatis.dynamic.sql.SqlBuilder import org.mybatis.dynamic.sql.SqlColumn @@ -41,7 +40,6 @@ import org.mybatis.dynamic.sql.select.function.OperatorFunction import org.mybatis.dynamic.sql.select.function.Substring import org.mybatis.dynamic.sql.select.function.Subtract import org.mybatis.dynamic.sql.select.function.Upper -import org.mybatis.dynamic.sql.select.join.EqualTo import org.mybatis.dynamic.sql.util.kotlin.GroupingCriteriaCollector import org.mybatis.dynamic.sql.util.kotlin.GroupingCriteriaReceiver import org.mybatis.dynamic.sql.util.kotlin.KotlinSubQueryBuilder @@ -78,10 +76,6 @@ import org.mybatis.dynamic.sql.where.condition.IsNotLikeCaseInsensitive import org.mybatis.dynamic.sql.where.condition.IsNotNull import org.mybatis.dynamic.sql.where.condition.IsNull -// join support -@Deprecated("Please use the infix function in the JoinCollector") -fun equalTo(column: BasicColumn): EqualTo = SqlBuilder.equalTo(column) - // support for criteria without initial conditions fun and(receiver: GroupingCriteriaReceiver): AndOrCriteriaGroup = with(GroupingCriteriaCollector().apply(receiver)) { @@ -172,16 +166,6 @@ fun isNull(): IsNull = SqlBuilder.isNull() fun isNotNull(): IsNotNull = SqlBuilder.isNotNull() -@Deprecated("Deprecated in favor of the new where clause DSL. " + - "Rewrite to use the exists function inside a lambda.") -fun exists(subQuery: KotlinSubQueryBuilder.() -> Unit): ExistsPredicate = - SqlBuilder.exists(KotlinSubQueryBuilder().apply(subQuery)) - -@Deprecated("Deprecated in favor of the new where clause DSL. " + - "Rewrite to use the exists function inside a \"not\" expression.") -fun notExists(subQuery: KotlinSubQueryBuilder.() -> Unit): ExistsPredicate = - SqlBuilder.notExists(KotlinSubQueryBuilder().apply(subQuery)) - fun isEqualTo(value: T & Any): IsEqualTo = SqlBuilder.isEqualTo(value) fun isEqualTo(subQuery: KotlinSubQueryBuilder.() -> Unit): IsEqualToWithSubselect = diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt index 0a0ef660d..85da13b47 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/model/ModelBuilderFunctions.kt @@ -20,13 +20,10 @@ import org.mybatis.dynamic.sql.BasicColumn import org.mybatis.dynamic.sql.SqlBuilder import org.mybatis.dynamic.sql.SqlTable import org.mybatis.dynamic.sql.delete.DeleteModel -import org.mybatis.dynamic.sql.insert.BatchInsertDSL import org.mybatis.dynamic.sql.insert.BatchInsertModel import org.mybatis.dynamic.sql.insert.GeneralInsertModel -import org.mybatis.dynamic.sql.insert.InsertDSL import org.mybatis.dynamic.sql.insert.InsertModel import org.mybatis.dynamic.sql.insert.InsertSelectModel -import org.mybatis.dynamic.sql.insert.MultiRowInsertDSL import org.mybatis.dynamic.sql.insert.MultiRowInsertModel import org.mybatis.dynamic.sql.select.SelectModel import org.mybatis.dynamic.sql.update.UpdateModel @@ -77,35 +74,9 @@ fun insertInto(table: SqlTable, completer: GeneralInsertCompleter): GeneralInser fun insertMultiple(rows: Collection, completer: KotlinMultiRowInsertCompleter): MultiRowInsertModel = KotlinMultiRowInsertBuilder(rows).apply(completer).build() -@Deprecated("Please use the new form - move the table into the lambda with into(table)") -fun insertSelect(table: SqlTable, completer: InsertSelectCompleter): InsertSelectModel = - with(KotlinInsertSelectSubQueryBuilder()) { - into(table) - apply(completer) - build() - } - fun insertSelect(completer: InsertSelectCompleter): InsertSelectModel = KotlinInsertSelectSubQueryBuilder().apply(completer).build() -@Deprecated("Please switch to the insertBatch statement in the model package") -fun BatchInsertDSL.IntoGatherer.into( - table: SqlTable, - completer: BatchInsertDSL.() -> Unit -): BatchInsertModel = - into(table).apply(completer).build() - -@Deprecated("Please switch to the insert statement in the model package") -fun InsertDSL.IntoGatherer.into(table: SqlTable, completer: InsertDSL.() -> Unit): InsertModel = - into(table).apply(completer).build() - -@Deprecated("Please switch to the insertMultiple statement in the model package") -fun MultiRowInsertDSL.IntoGatherer.into( - table: SqlTable, - completer: MultiRowInsertDSL.() -> Unit -): MultiRowInsertModel = - into(table).apply(completer).build() - fun select(vararg columns: BasicColumn, completer: SelectCompleter): SelectModel = select(columns.asList(), completer) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/ProviderBuilderFunctions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/ProviderBuilderFunctions.kt index cd588866f..7e238bef9 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/ProviderBuilderFunctions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/mybatis3/ProviderBuilderFunctions.kt @@ -19,9 +19,6 @@ package org.mybatis.dynamic.sql.util.kotlin.mybatis3 import org.mybatis.dynamic.sql.BasicColumn import org.mybatis.dynamic.sql.SqlTable import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider -import org.mybatis.dynamic.sql.insert.BatchInsertDSL -import org.mybatis.dynamic.sql.insert.InsertDSL -import org.mybatis.dynamic.sql.insert.MultiRowInsertDSL import org.mybatis.dynamic.sql.insert.render.BatchInsert import org.mybatis.dynamic.sql.insert.render.GeneralInsertStatementProvider import org.mybatis.dynamic.sql.insert.render.InsertSelectStatementProvider @@ -48,7 +45,6 @@ import org.mybatis.dynamic.sql.util.kotlin.model.insertBatch import org.mybatis.dynamic.sql.util.kotlin.model.insertInto import org.mybatis.dynamic.sql.util.kotlin.model.insertMultiple import org.mybatis.dynamic.sql.util.kotlin.model.insertSelect -import org.mybatis.dynamic.sql.util.kotlin.model.into import org.mybatis.dynamic.sql.util.kotlin.model.select import org.mybatis.dynamic.sql.util.kotlin.model.selectDistinct import org.mybatis.dynamic.sql.util.kotlin.model.update @@ -83,31 +79,9 @@ fun insertMultiple( ): MultiRowInsertStatementProvider = insertMultiple(rows, completer).render(RenderingStrategies.MYBATIS3) -@Deprecated("Please use the new form - move the table into the lambda with into(table)") -fun insertSelect(table: SqlTable, completer: InsertSelectCompleter): InsertSelectStatementProvider = - insertSelect(table, completer).render(RenderingStrategies.MYBATIS3) - fun insertSelect(completer: InsertSelectCompleter): InsertSelectStatementProvider = insertSelect(completer).render(RenderingStrategies.MYBATIS3) -@Deprecated("Please switch to the insertBatch statement in the mybatis3 package") -fun BatchInsertDSL.IntoGatherer.into(table: SqlTable, completer: BatchInsertDSL.() -> Unit): BatchInsert = - into(table, completer).render(RenderingStrategies.MYBATIS3) - -@Deprecated("Please switch to the insert statement in the mybatis3 package") -fun InsertDSL.IntoGatherer.into( - table: SqlTable, - completer: InsertDSL.() -> Unit -): InsertStatementProvider = - into(table, completer).render(RenderingStrategies.MYBATIS3) - -@Deprecated("Please switch to the insertMultiple statement in the mybatis3 package") -fun MultiRowInsertDSL.IntoGatherer.into( - table: SqlTable, - completer: MultiRowInsertDSL.() -> Unit -): MultiRowInsertStatementProvider = - into(table, completer).render(RenderingStrategies.MYBATIS3) - fun select(vararg columns: BasicColumn, completer: SelectCompleter): SelectStatementProvider = select(columns.asList(), completer).render(RenderingStrategies.MYBATIS3) diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt index c2b8dcad8..bd2e5a59e 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/NamedParameterJdbcTemplateExtensions.kt @@ -80,14 +80,6 @@ fun NamedParameterJdbcTemplate.insertBatch( ): IntArray = insertBatch(org.mybatis.dynamic.sql.util.kotlin.spring.insertBatch(records, completer)) -@Deprecated("Please move the into phrase inside the lambda") -fun NamedParameterJdbcTemplate.insertBatch(vararg records: T): BatchInsertHelper = - insertBatch(records.asList()) - -@Deprecated("Please move the into phrase inside the lambda") -fun NamedParameterJdbcTemplate.insertBatch(records: List): BatchInsertHelper = - BatchInsertHelper(records, this) - // single row insert fun NamedParameterJdbcTemplate.insert(insertStatement: InsertStatementProvider): Int = update(insertStatement.insertStatement, BeanPropertySqlParameterSource(insertStatement.row)) @@ -101,10 +93,6 @@ fun NamedParameterJdbcTemplate.insert( fun NamedParameterJdbcTemplate.insert(row: T, completer: KotlinInsertCompleter): Int = insert(org.mybatis.dynamic.sql.util.kotlin.spring.insert(row, completer)) -@Deprecated("Please move the into phrase inside the lambda") -fun NamedParameterJdbcTemplate.insert(row: T): SingleRowInsertHelper = - SingleRowInsertHelper(row, this) - // general insert fun NamedParameterJdbcTemplate.generalInsert(insertStatement: GeneralInsertStatementProvider): Int = update(insertStatement.insertStatement, insertStatement.parameters) @@ -131,14 +119,6 @@ fun NamedParameterJdbcTemplate.insertMultiple( ): Int = insertMultiple(org.mybatis.dynamic.sql.util.kotlin.spring.insertMultiple(records, completer)) -@Deprecated("Please move the into phrase inside the lambda") -fun NamedParameterJdbcTemplate.insertMultiple(vararg records: T): MultiRowInsertHelper = - insertMultiple(records.asList()) - -@Deprecated("Please move the into phrase inside the lambda") -fun NamedParameterJdbcTemplate.insertMultiple(records: List): MultiRowInsertHelper = - MultiRowInsertHelper(records, this) - fun NamedParameterJdbcTemplate.insertMultiple(insertStatement: MultiRowInsertStatementProvider): Int = update(insertStatement.insertStatement, BeanPropertySqlParameterSource(insertStatement)) @@ -148,10 +128,6 @@ fun NamedParameterJdbcTemplate.insertMultiple( ): Int = update(insertStatement.insertStatement, BeanPropertySqlParameterSource(insertStatement), keyHolder) -@Deprecated("Please use the new form - move the table into the lambda with into(table)") -fun NamedParameterJdbcTemplate.insertSelect(table: SqlTable, completer: InsertSelectCompleter): Int = - insertSelect(org.mybatis.dynamic.sql.util.kotlin.spring.insertSelect(table, completer)) - fun NamedParameterJdbcTemplate.insertSelect(completer: InsertSelectCompleter): Int = insertSelect(org.mybatis.dynamic.sql.util.kotlin.spring.insertSelect(completer)) @@ -291,10 +267,6 @@ class KeyHolderHelper(private val keyHolder: KeyHolder, private val template: Na fun insert(row: T, completer: KotlinInsertCompleter): Int = template.insert(org.mybatis.dynamic.sql.util.kotlin.spring.insert(row, completer), keyHolder) - @Deprecated("Please move the into phrase inside the lambda") - fun insert(row: T): SingleRowInsertWithKeyHolderHelper = - SingleRowInsertWithKeyHolderHelper(row, template, keyHolder) - fun insertMultiple(vararg records: T, completer: KotlinMultiRowInsertCompleter): Int = insertMultiple(records.asList(), completer) @@ -302,91 +274,6 @@ class KeyHolderHelper(private val keyHolder: KeyHolder, private val template: Na template.insertMultiple(org.mybatis.dynamic.sql.util.kotlin.spring.insertMultiple(records, completer), keyHolder) - @Deprecated("Please move the into phrase inside the lambda") - fun insertMultiple(vararg records: T): MultiRowInsertWithKeyHolderHelper = - insertMultiple(records.asList()) - - @Deprecated("Please move the into phrase inside the lambda") - fun insertMultiple(records: List): MultiRowInsertWithKeyHolderHelper = - MultiRowInsertWithKeyHolderHelper(records, template, keyHolder) - - fun insertSelect(table: SqlTable, completer: InsertSelectCompleter): Int = - template.insertSelect(org.mybatis.dynamic.sql.util.kotlin.spring.insertSelect(table, completer), keyHolder) -} - -@MyBatisDslMarker -class BatchInsertHelper(private val records: List, private val template: NamedParameterJdbcTemplate) { - fun into(table: SqlTable, completer: KotlinBatchInsertCompleter): IntArray = - template.insertBatch( - insertBatch(records) { - into(table) - run(completer) - } - ) -} - -@MyBatisDslMarker -class MultiRowInsertHelper( - private val records: List, - private val template: NamedParameterJdbcTemplate -) { - fun into(table: SqlTable, completer: KotlinMultiRowInsertCompleter): Int = - with( - insertMultiple(records) { - into(table) - run(completer) - } - ) { - template.insertMultiple(this) - } -} - -@MyBatisDslMarker -class MultiRowInsertWithKeyHolderHelper( - private val records: List, - private val template: NamedParameterJdbcTemplate, - private val keyHolder: KeyHolder -) { - fun into(table: SqlTable, completer: KotlinMultiRowInsertCompleter): Int = - with( - insertMultiple(records) { - into(table) - run(completer) - } - ) { - template.insertMultiple(this, keyHolder) - } -} - -@MyBatisDslMarker -class SingleRowInsertHelper( - private val row: T, - private val template: NamedParameterJdbcTemplate -) { - fun into(table: SqlTable, completer: KotlinInsertCompleter): Int = - with( - insert(row) { - into(table) - run(completer) - } - ) { - template.insert(this) - } -} - -@MyBatisDslMarker -class SingleRowInsertWithKeyHolderHelper( - private val row: T, - private val template: NamedParameterJdbcTemplate, - private val keyHolder: KeyHolder -) { - fun into(table: SqlTable, completer: KotlinInsertCompleter): Int = - with( - insert(row) { - into(table) - run(completer) - } - ) { - template.insert(this, keyHolder) - } + fun insertSelect(completer: InsertSelectCompleter): Int = + template.insertSelect(org.mybatis.dynamic.sql.util.kotlin.spring.insertSelect(completer), keyHolder) } diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/ProviderBuilderFunctions.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/ProviderBuilderFunctions.kt index 058645a99..4ed0fcbf9 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/ProviderBuilderFunctions.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/spring/ProviderBuilderFunctions.kt @@ -19,9 +19,6 @@ package org.mybatis.dynamic.sql.util.kotlin.spring import org.mybatis.dynamic.sql.BasicColumn import org.mybatis.dynamic.sql.SqlTable import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider -import org.mybatis.dynamic.sql.insert.BatchInsertDSL -import org.mybatis.dynamic.sql.insert.InsertDSL -import org.mybatis.dynamic.sql.insert.MultiRowInsertDSL import org.mybatis.dynamic.sql.insert.render.BatchInsert import org.mybatis.dynamic.sql.insert.render.GeneralInsertStatementProvider import org.mybatis.dynamic.sql.insert.render.InsertSelectStatementProvider @@ -48,7 +45,6 @@ import org.mybatis.dynamic.sql.util.kotlin.model.insertBatch import org.mybatis.dynamic.sql.util.kotlin.model.insertInto import org.mybatis.dynamic.sql.util.kotlin.model.insertMultiple import org.mybatis.dynamic.sql.util.kotlin.model.insertSelect -import org.mybatis.dynamic.sql.util.kotlin.model.into import org.mybatis.dynamic.sql.util.kotlin.model.select import org.mybatis.dynamic.sql.util.kotlin.model.selectDistinct import org.mybatis.dynamic.sql.util.kotlin.model.update @@ -83,31 +79,9 @@ fun insertMultiple( ): MultiRowInsertStatementProvider = insertMultiple(rows, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER) -@Deprecated("Please use the new form - move the table into the lambda with into(table)") -fun insertSelect(table: SqlTable, completer: InsertSelectCompleter): InsertSelectStatementProvider = - insertSelect(table, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER) - fun insertSelect(completer: InsertSelectCompleter): InsertSelectStatementProvider = insertSelect(completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER) -@Deprecated("Please switch to the insertBatch statement in the spring package") -fun BatchInsertDSL.IntoGatherer.into(table: SqlTable, completer: BatchInsertDSL.() -> Unit): BatchInsert = - into(table, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER) - -@Deprecated("Please switch to the insert statement in the spring package") -fun InsertDSL.IntoGatherer.into( - table: SqlTable, - completer: InsertDSL.() -> Unit -): InsertStatementProvider = - into(table, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER) - -@Deprecated("Please switch to the insertMultiple statement in the spring package") -fun MultiRowInsertDSL.IntoGatherer.into( - table: SqlTable, - completer: MultiRowInsertDSL.() -> Unit -): MultiRowInsertStatementProvider = - into(table, completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER) - fun select(vararg columns: BasicColumn, completer: SelectCompleter): SelectStatementProvider = select(columns.asList(), completer).render(RenderingStrategies.SPRING_NAMED_PARAMETER) diff --git a/src/test/java/examples/animal/data/AnimalDataTest.java b/src/test/java/examples/animal/data/AnimalDataTest.java index 742384421..607e30e00 100644 --- a/src/test/java/examples/animal/data/AnimalDataTest.java +++ b/src/test/java/examples/animal/data/AnimalDataTest.java @@ -27,8 +27,6 @@ import java.sql.Connection; import java.sql.DriverManager; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; @@ -47,9 +45,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mybatis.dynamic.sql.BasicColumn; -import org.mybatis.dynamic.sql.Callback; import org.mybatis.dynamic.sql.SqlTable; import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider; +import org.mybatis.dynamic.sql.exception.NonRenderingWhereClauseException; import org.mybatis.dynamic.sql.insert.render.BatchInsert; import org.mybatis.dynamic.sql.insert.render.GeneralInsertStatementProvider; import org.mybatis.dynamic.sql.insert.render.InsertSelectStatementProvider; @@ -61,8 +59,6 @@ import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider; import org.mybatis.dynamic.sql.util.mybatis3.CommonSelectMapper; import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils; -import org.mybatis.dynamic.sql.where.condition.IsIn; -import org.mybatis.dynamic.sql.where.condition.IsNotIn; import org.mybatis.dynamic.sql.where.render.WhereClauseProvider; class AnimalDataTest { @@ -677,28 +673,24 @@ void testInConditionWithEventuallyEmptyListForceRendering() { SelectModel selectModel = select(id, animalName, bodyWeight, brainWeight) .from(animalData) - .where(id, isInRequired(inValues).filter(Objects::nonNull).filter(i -> i != 22)) + .where(id, isIn(inValues).filter(Objects::nonNull).filter(i -> i != 22)) .build(); - assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> + assertThatExceptionOfType(NonRenderingWhereClauseException.class).isThrownBy(() -> selectModel.render(RenderingStrategies.MYBATIS3) - ).withMessage("Fred"); + ); } @Test void testInConditionWithEmptyList() { SelectModel selectModel = select(id, animalName, bodyWeight, brainWeight) .from(animalData) - .where(id, isInRequired(Collections.emptyList())) + .where(id, isIn(Collections.emptyList())) .build(); - assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> + assertThatExceptionOfType(NonRenderingWhereClauseException.class).isThrownBy(() -> selectModel.render(RenderingStrategies.MYBATIS3) - ).withMessage("Fred"); - } - - private static IsIn isInRequired(Collection values) { - return IsIn.of(values).withListEmptyCallback(Callback.exceptionThrowingCallback("Fred")); + ); } @Test @@ -788,18 +780,13 @@ void testNotInConditionWithEventuallyEmptyList() { void testNotInConditionWithEventuallyEmptyListForceRendering() { SelectModel selectModel = select(id, animalName, bodyWeight, brainWeight) .from(animalData) - .where(id, isNotInRequired(null, 22, null) + .where(id, isNotIn(null, 22, null) .filter(Objects::nonNull).filter(i -> i != 22)) .build(); - assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> + assertThatExceptionOfType(NonRenderingWhereClauseException.class).isThrownBy(() -> selectModel.render(RenderingStrategies.MYBATIS3) - ).withMessage("Fred"); - } - - @SafeVarargs - private static IsNotIn isNotInRequired(T...values) { - return IsNotIn.of(Arrays.asList(values)).withListEmptyCallback(Callback.exceptionThrowingCallback("Fred")); + ); } @Test 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 8f19af0d5..c267de9e7 100644 --- a/src/test/java/org/mybatis/dynamic/sql/select/SelectStatementTest.java +++ b/src/test/java/org/mybatis/dynamic/sql/select/SelectStatementTest.java @@ -29,10 +29,10 @@ import java.util.Map; import org.junit.jupiter.api.Test; -import org.mybatis.dynamic.sql.Callback; import org.mybatis.dynamic.sql.SortSpecification; import org.mybatis.dynamic.sql.SqlColumn; import org.mybatis.dynamic.sql.SqlTable; +import org.mybatis.dynamic.sql.exception.NonRenderingWhereClauseException; import org.mybatis.dynamic.sql.render.RenderingStrategies; import org.mybatis.dynamic.sql.select.render.SelectStatementProvider; @@ -290,13 +290,12 @@ void testInEmptyList() { List emptyList = Collections.emptyList(); SelectModel selectModel = select(column1, column3) .from(table, "a") - .where(column3, isIn(emptyList) - .withListEmptyCallback(Callback.exceptionThrowingCallback("Fred"))) + .where(column3, isIn(emptyList)) .build(); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> selectModel.render(RenderingStrategies.MYBATIS3) - ).withMessage("Fred"); + ); } @Test @@ -304,13 +303,12 @@ void testNotInEmptyList() { List emptyList = Collections.emptyList(); SelectModel selectModel = select(column1, column3) .from(table, "a") - .where(column3, isNotIn(emptyList) - .withListEmptyCallback(Callback.exceptionThrowingCallback("Fred"))) + .where(column3, isNotIn(emptyList)) .build(); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> selectModel.render(RenderingStrategies.MYBATIS3) - ).withMessage("Fred"); + ); } @Test @@ -318,39 +316,36 @@ void testInWhenPresentEmptyList() { List emptyList = Collections.emptyList(); SelectModel selectModel = select(column1, column3) .from(table, "a") - .where(column3, isInWhenPresent(emptyList) - .withListEmptyCallback(Callback.exceptionThrowingCallback("Fred"))) + .where(column3, isInWhenPresent(emptyList)) .build(); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> selectModel.render(RenderingStrategies.MYBATIS3) - ).withMessage("Fred"); + ); } @Test void testInCaseInsensitiveEmptyList() { SelectModel selectModel = select(column1, column3) .from(table, "a") - .where(column3, isInCaseInsensitive(Collections.emptyList()) - .withListEmptyCallback(Callback.exceptionThrowingCallback("Fred"))) + .where(column3, isInCaseInsensitive(Collections.emptyList())) .build(); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> selectModel.render(RenderingStrategies.MYBATIS3) - ).withMessage("Fred"); + ); } @Test void testInCaseInsensitiveWhenPresentEmptyList() { SelectModel selectModel = select(column1, column3) .from(table, "a") - .where(column3, isInCaseInsensitiveWhenPresent(Collections.emptyList()) - .withListEmptyCallback(Callback.exceptionThrowingCallback("Fred"))) + .where(column3, isInCaseInsensitiveWhenPresent(Collections.emptyList())) .build(); - assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> + assertThatExceptionOfType(NonRenderingWhereClauseException.class).isThrownBy(() -> selectModel.render(RenderingStrategies.MYBATIS3) - ).withMessage("Fred"); + ); } @Test @@ -358,39 +353,36 @@ void testNotInWhenPresentEmptyList() { List emptyList = Collections.emptyList(); SelectModel selectModel = select(column1, column3) .from(table, "a") - .where(column3, isNotInWhenPresent(emptyList) - .withListEmptyCallback(Callback.exceptionThrowingCallback("Fred"))) + .where(column3, isNotInWhenPresent(emptyList)) .build(); - assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> + assertThatExceptionOfType(NonRenderingWhereClauseException.class).isThrownBy(() -> selectModel.render(RenderingStrategies.MYBATIS3) - ).withMessage("Fred"); + ); } @Test void testNotInCaseInsensitiveEmptyList() { SelectModel selectModel = select(column1, column3) .from(table, "a") - .where(column3, isNotInCaseInsensitive(Collections.emptyList()) - .withListEmptyCallback(Callback.exceptionThrowingCallback("Fred"))) + .where(column3, isNotInCaseInsensitive(Collections.emptyList())) .build(); - assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> + assertThatExceptionOfType(NonRenderingWhereClauseException.class).isThrownBy(() -> selectModel.render(RenderingStrategies.MYBATIS3) - ).withMessage("Fred"); + ); } @Test void testNotInCaseInsensitiveWhenPresentEmptyList() { SelectModel selectModel = select(column1, column3) .from(table, "a") - .where(column3, isNotInCaseInsensitiveWhenPresent(Collections.emptyList()) - .withListEmptyCallback(Callback.exceptionThrowingCallback("Fred"))) + .where(column3, isNotInCaseInsensitiveWhenPresent(Collections.emptyList())) .build(); - assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> + assertThatExceptionOfType(NonRenderingWhereClauseException.class).isThrownBy(() -> selectModel.render(RenderingStrategies.MYBATIS3) - ).withMessage("Fred"); + ); } @Test diff --git a/src/test/kotlin/examples/kotlin/mybatis3/canonical/GeneratedAlwaysTest.kt b/src/test/kotlin/examples/kotlin/mybatis3/canonical/GeneratedAlwaysTest.kt index 99af07726..d62a41057 100644 --- a/src/test/kotlin/examples/kotlin/mybatis3/canonical/GeneratedAlwaysTest.kt +++ b/src/test/kotlin/examples/kotlin/mybatis3/canonical/GeneratedAlwaysTest.kt @@ -23,9 +23,7 @@ import org.apache.ibatis.session.ExecutorType import org.apache.ibatis.session.SqlSession import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.mybatis.dynamic.sql.util.kotlin.elements.insertBatch import org.mybatis.dynamic.sql.util.kotlin.mybatis3.insertInto -import org.mybatis.dynamic.sql.util.kotlin.mybatis3.into class GeneratedAlwaysTest { private fun newSession(executorType: ExecutorType = ExecutorType.REUSE): SqlSession { @@ -110,40 +108,6 @@ class GeneratedAlwaysTest { } } - @Test - fun testDeprecatedInsertBatch() { - newSession(ExecutorType.BATCH).use { session -> - val mapper = session.getMapper(GeneratedAlwaysMapper::class.java) - - val record1 = GeneratedAlwaysRecord( - firstName = "Fred", - lastName = "Flintstone" - ) - - val record2 = GeneratedAlwaysRecord( - firstName = "Barney", - lastName = "Rubble" - ) - - insertBatch(record1, record2).into(generatedAlways) { - map(firstName).toProperty("firstName") - map(lastName).toProperty("lastName") - }.insertStatements().map(mapper::insert) - - val batchResults = mapper.flush() - - assertThat(batchResults).hasSize(1) - assertThat(batchResults[0].updateCounts).hasSize(2) - assertThat(batchResults[0].updateCounts[0]).isEqualTo(1) - assertThat(batchResults[0].updateCounts[1]).isEqualTo(1) - - assertThat(record1.id).isEqualTo(22) - assertThat(record1.fullName).isEqualTo("Fred Flintstone") - assertThat(record2.id).isEqualTo(23) - assertThat(record2.fullName).isEqualTo("Barney Rubble") - } - } - @Test fun testGeneralInsert() { newSession().use { session -> diff --git a/src/test/kotlin/examples/kotlin/mybatis3/canonical/PersonMapperTest.kt b/src/test/kotlin/examples/kotlin/mybatis3/canonical/PersonMapperTest.kt index ffe894acb..60ab1c2bf 100644 --- a/src/test/kotlin/examples/kotlin/mybatis3/canonical/PersonMapperTest.kt +++ b/src/test/kotlin/examples/kotlin/mybatis3/canonical/PersonMapperTest.kt @@ -255,7 +255,8 @@ class PersonMapperTest { sqlSessionFactory.openSession().use { session -> val mapper = session.getMapper(PersonMapper::class.java) - val insertStatement = insertSelect(person) { + val insertStatement = insertSelect { + into(person) columns(id, firstName, lastName, employed, occupation, addressId, birthDate) select(add(id, constant("100")), firstName, lastName, employed, occupation, addressId, birthDate) { from(person) diff --git a/src/test/kotlin/examples/kotlin/mybatis3/general/GeneralKotlinTest.kt b/src/test/kotlin/examples/kotlin/mybatis3/general/GeneralKotlinTest.kt index b3da8c6c6..89512cb38 100644 --- a/src/test/kotlin/examples/kotlin/mybatis3/general/GeneralKotlinTest.kt +++ b/src/test/kotlin/examples/kotlin/mybatis3/general/GeneralKotlinTest.kt @@ -17,7 +17,6 @@ package examples.kotlin.mybatis3.general import examples.kotlin.mybatis3.TestUtils import examples.kotlin.mybatis3.canonical.AddressDynamicSqlSupport.address -import examples.kotlin.mybatis3.canonical.LastName import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.person import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.addressId import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.birthDate @@ -27,7 +26,6 @@ import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.id import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.lastName import examples.kotlin.mybatis3.canonical.PersonDynamicSqlSupport.occupation import examples.kotlin.mybatis3.canonical.PersonMapper -import examples.kotlin.mybatis3.canonical.PersonRecord import examples.kotlin.mybatis3.canonical.PersonWithAddressMapper import examples.kotlin.mybatis3.canonical.YesNoTypeHandler import examples.kotlin.mybatis3.canonical.select @@ -41,17 +39,13 @@ import org.mybatis.dynamic.sql.util.Messages import org.mybatis.dynamic.sql.util.kotlin.KInvalidSQLException import org.mybatis.dynamic.sql.util.kotlin.elements.`as` import org.mybatis.dynamic.sql.util.kotlin.elements.count -import org.mybatis.dynamic.sql.util.kotlin.elements.insert -import org.mybatis.dynamic.sql.util.kotlin.elements.insertMultiple import org.mybatis.dynamic.sql.util.kotlin.mybatis3.count import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countDistinct import org.mybatis.dynamic.sql.util.kotlin.mybatis3.countFrom import org.mybatis.dynamic.sql.util.kotlin.mybatis3.deleteFrom -import org.mybatis.dynamic.sql.util.kotlin.mybatis3.into import org.mybatis.dynamic.sql.util.kotlin.mybatis3.select import org.mybatis.dynamic.sql.util.kotlin.mybatis3.selectDistinct import org.mybatis.dynamic.sql.util.kotlin.mybatis3.update -import java.util.Date @Suppress("LargeClass") @TestInstance(TestInstance.Lifecycle.PER_CLASS) @@ -281,90 +275,6 @@ class GeneralKotlinTest { } } - @Test - fun testDeprecatedInsert() { - sqlSessionFactory.openSession().use { session -> - val mapper = session.getMapper(PersonMapper::class.java) - - val record = PersonRecord(100, "Joe", LastName("Jones"), Date(), true, "Developer", 1) - - val insertStatement = insert(record).into(person) { - map(id).toProperty("id") - map(firstName).toProperty("firstName") - map(lastName).toProperty("lastName") - map(birthDate).toProperty("birthDate") - map(employed).toProperty("employed") - map(occupation).toProperty("occupation") - map(addressId).toProperty("addressId") - } - - val expected = - "insert into Person (id, first_name, last_name, birth_date, employed, occupation, address_id) " + - "values " + - "(#{row.id,jdbcType=INTEGER}, #{row.firstName,jdbcType=VARCHAR}, " + - "#{row.lastName,jdbcType=VARCHAR," + - "typeHandler=examples.kotlin.mybatis3.canonical.LastNameTypeHandler}, " + - "#{row.birthDate,jdbcType=DATE}, " + - "#{row.employed,jdbcType=VARCHAR," + - "typeHandler=examples.kotlin.mybatis3.canonical.YesNoTypeHandler}, " + - "#{row.occupation,jdbcType=VARCHAR}, #{row.addressId,jdbcType=INTEGER})" - - assertThat(insertStatement.insertStatement).isEqualTo(expected) - - val rows = mapper.insert(insertStatement) - assertThat(rows).isEqualTo(1) - } - } - - @Test - fun testDeprecatedInsertMultiple() { - sqlSessionFactory.openSession().use { session -> - val mapper = session.getMapper(PersonMapper::class.java) - - val record1 = PersonRecord(100, "Joe", LastName("Jones"), Date(), true, "Developer", 1) - val record2 = PersonRecord(101, "Sarah", LastName("Smith"), Date(), true, "Architect", 2) - - val insertStatement = - insertMultiple(listOf(record1, record2)).into(person) { - map(id).toProperty("id") - map(firstName).toProperty("firstName") - map(lastName).toProperty("lastName") - map(birthDate).toProperty("birthDate") - map(employed).toProperty("employed") - map(occupation).toProperty("occupation") - map(addressId).toProperty("addressId") - } - - val expected = - "insert into Person (id, first_name, last_name, birth_date, employed, occupation, address_id)" + - " values" + - " (#{records[0].id,jdbcType=INTEGER}," + - " #{records[0].firstName,jdbcType=VARCHAR}," + - " #{records[0].lastName,jdbcType=VARCHAR," + - "typeHandler=examples.kotlin.mybatis3.canonical.LastNameTypeHandler}," + - " #{records[0].birthDate,jdbcType=DATE}," + - " #{records[0].employed,jdbcType=VARCHAR," + - "typeHandler=examples.kotlin.mybatis3.canonical.YesNoTypeHandler}," + - " #{records[0].occupation,jdbcType=VARCHAR}," + - " #{records[0].addressId,jdbcType=INTEGER})" + - ", (#{records[1].id,jdbcType=INTEGER}," + - " #{records[1].firstName,jdbcType=VARCHAR}," + - " #{records[1].lastName,jdbcType=VARCHAR," + - "typeHandler=examples.kotlin.mybatis3.canonical.LastNameTypeHandler}," + - " #{records[1].birthDate,jdbcType=DATE}," + - " #{records[1].employed,jdbcType=VARCHAR," + - "typeHandler=examples.kotlin.mybatis3.canonical.YesNoTypeHandler}," + - " #{records[1].occupation,jdbcType=VARCHAR}," + - " #{records[1].addressId,jdbcType=INTEGER})" - - assertThat(insertStatement.insertStatement).isEqualTo(expected) - - val rows = mapper.insertMultiple(insertStatement) - - assertThat(rows).isEqualTo(2) - } - } - @Test fun testRawSelectDistinct() { sqlSessionFactory.openSession().use { session -> diff --git a/src/test/kotlin/examples/kotlin/mybatis3/joins/DeprecatedWhereDSLTest.kt b/src/test/kotlin/examples/kotlin/mybatis3/joins/DeprecatedWhereDSLTest.kt deleted file mode 100644 index 92094b9df..000000000 --- a/src/test/kotlin/examples/kotlin/mybatis3/joins/DeprecatedWhereDSLTest.kt +++ /dev/null @@ -1,666 +0,0 @@ -/* - * Copyright 2016-2022 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * 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.kotlin.mybatis3.joins - -import examples.kotlin.mybatis3.TestUtils -import examples.kotlin.mybatis3.joins.ItemMasterDynamicSQLSupport.itemMaster -import examples.kotlin.mybatis3.joins.OrderLineDynamicSQLSupport.orderLine -import org.apache.ibatis.session.SqlSessionFactory -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.BeforeAll -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.TestInstance -import org.mybatis.dynamic.sql.util.kotlin.elements.exists -import org.mybatis.dynamic.sql.util.kotlin.elements.isEqualTo -import org.mybatis.dynamic.sql.util.kotlin.elements.isGreaterThan -import org.mybatis.dynamic.sql.util.kotlin.elements.notExists -import org.mybatis.dynamic.sql.util.kotlin.mybatis3.select -import org.mybatis.dynamic.sql.util.mybatis3.CommonSelectMapper - -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -class DeprecatedWhereDSLTest { - private lateinit var sqlSessionFactory: SqlSessionFactory - - @BeforeAll - fun setup() { - sqlSessionFactory = TestUtils.buildSqlSessionFactory { - withInitializationScript("/examples/kotlin/mybatis3/joins/CreateJoinDB.sql") - withMapper(CommonSelectMapper::class) - } - } - - @Test - fun testExists() { - sqlSessionFactory.openSession().use { session -> - val mapper = session.getMapper(CommonSelectMapper::class.java) - - val selectStatement = select(itemMaster.allColumns()) { - from(itemMaster, "im") - where( - exists { - select(orderLine.allColumns()) { - from(orderLine, "ol") - where(orderLine.itemId, isEqualTo(itemMaster.itemId.qualifiedWith("im"))) - } - } - ) - orderBy(itemMaster.itemId) - } - - val expectedStatement: String = "select im.* from ItemMaster im" + - " where exists (select ol.* from OrderLine ol where ol.item_id = im.item_id)" + - " order by item_id" - assertThat(selectStatement.selectStatement).isEqualTo(expectedStatement) - - val rows = mapper.selectManyMappedRows(selectStatement) - assertThat(rows).hasSize(3) - - with(rows[0]) { - assertThat(this).containsEntry("ITEM_ID", 22) - assertThat(this).containsEntry("DESCRIPTION", "Helmet") - } - - with(rows[1]) { - assertThat(this).containsEntry("ITEM_ID", 33) - assertThat(this).containsEntry("DESCRIPTION", "First Base Glove") - } - - with(rows[2]) { - assertThat(this).containsEntry("ITEM_ID", 44) - assertThat(this).containsEntry("DESCRIPTION", "Outfield Glove") - } - } - } - - @Test - fun testNotExists() { - sqlSessionFactory.openSession().use { session -> - val mapper = session.getMapper(CommonSelectMapper::class.java) - - val selectStatement = select(itemMaster.allColumns()) { - from(itemMaster, "im") - where( - notExists { - select(orderLine.allColumns()) { - from(orderLine, "ol") - where(orderLine.itemId, isEqualTo(itemMaster.itemId.qualifiedWith("im"))) - } - } - ) - orderBy(itemMaster.itemId) - } - - val expectedStatement: String = "select im.* from ItemMaster im" + - " where not exists (select ol.* from OrderLine ol where ol.item_id = im.item_id)" + - " order by item_id" - assertThat(selectStatement.selectStatement).isEqualTo(expectedStatement) - - val rows = mapper.selectManyMappedRows(selectStatement) - assertThat(rows).hasSize(1) - - with(rows[0]) { - assertThat(this).containsEntry("ITEM_ID", 55) - assertThat(this).containsEntry("DESCRIPTION", "Catcher Glove") - } - } - } - - @Test - fun testAndExists() { - sqlSessionFactory.openSession().use { session -> - val mapper = session.getMapper(CommonSelectMapper::class.java) - - val selectStatement = select(itemMaster.allColumns()) { - from(itemMaster, "im") - where(itemMaster.itemId, isEqualTo(22)) - and( - exists { - select(orderLine.allColumns()) { - from(orderLine, "ol") - where(orderLine.itemId, isEqualTo(itemMaster.itemId.qualifiedWith("im"))) - } - } - ) - orderBy(itemMaster.itemId) - } - - val expectedStatement = "select im.* from ItemMaster im" + - " where im.item_id = #{parameters.p1,jdbcType=INTEGER}" + - " and exists (select ol.* from OrderLine ol where ol.item_id = im.item_id)" + - " order by item_id" - - assertThat(selectStatement.selectStatement).isEqualTo(expectedStatement) - - val rows = mapper.selectManyMappedRows(selectStatement) - assertThat(rows).hasSize(1) - - with(rows[0]) { - assertThat(this).containsEntry("ITEM_ID", 22) - assertThat(this).containsEntry("DESCRIPTION", "Helmet") - } - } - } - - @Test - fun testAndExistsAnd() { - sqlSessionFactory.openSession().use { session -> - val mapper = session.getMapper(CommonSelectMapper::class.java) - - val selectStatement = select(itemMaster.allColumns()) { - from(itemMaster, "im") - where(itemMaster.itemId, isEqualTo(22)) - and( - exists { - select(orderLine.allColumns()) { - from(orderLine, "ol") - where(orderLine.itemId, isEqualTo(itemMaster.itemId.qualifiedWith("im"))) - } - } - ) { - and(itemMaster.itemId, isGreaterThan(2)) - } - orderBy(itemMaster.itemId) - } - - val expectedStatement = "select im.* from ItemMaster im" + - " where im.item_id = #{parameters.p1,jdbcType=INTEGER}" + - " and (exists (select ol.* from OrderLine ol where ol.item_id = im.item_id)" + - " and im.item_id > #{parameters.p2,jdbcType=INTEGER})" + - " order by item_id" - assertThat(selectStatement.selectStatement).isEqualTo(expectedStatement) - - val rows = mapper.selectManyMappedRows(selectStatement) - assertThat(rows).hasSize(1) - - with(rows[0]) { - assertThat(this).containsEntry("ITEM_ID", 22) - assertThat(this).containsEntry("DESCRIPTION", "Helmet") - } - } - } - - @Test - fun testAndExistsAnd2() { - sqlSessionFactory.openSession().use { session -> - val mapper = session.getMapper(CommonSelectMapper::class.java) - - val selectStatement = select(itemMaster.allColumns()) { - from(itemMaster, "im") - where(itemMaster.itemId, isEqualTo(22)) { - and( - exists { - select(orderLine.allColumns()) { - from(orderLine, "ol") - where(orderLine.itemId, isEqualTo(itemMaster.itemId.qualifiedWith("im"))) - } - } - ) - and(itemMaster.itemId, isGreaterThan(2)) - } - orderBy(itemMaster.itemId) - } - - val expectedStatement = "select im.* from ItemMaster im" + - " where (im.item_id = #{parameters.p1,jdbcType=INTEGER}" + - " and exists (select ol.* from OrderLine ol where ol.item_id = im.item_id)" + - " and im.item_id > #{parameters.p2,jdbcType=INTEGER})" + - " order by item_id" - assertThat(selectStatement.selectStatement).isEqualTo(expectedStatement) - - val rows = mapper.selectManyMappedRows(selectStatement) - assertThat(rows).hasSize(1) - - with(rows[0]) { - assertThat(this).containsEntry("ITEM_ID", 22) - assertThat(this).containsEntry("DESCRIPTION", "Helmet") - } - } - } - - @Test - fun testAndExistsAnd3() { - sqlSessionFactory.openSession().use { session -> - val mapper = session.getMapper(CommonSelectMapper::class.java) - - val selectStatement = select(itemMaster.allColumns()) { - from(itemMaster, "im") - where(itemMaster.itemId, isEqualTo(22)) { - and( - exists { - select(orderLine.allColumns()) { - from(orderLine, "ol") - where(orderLine.itemId, isEqualTo(itemMaster.itemId.qualifiedWith("im"))) - } - } - ) { - and(itemMaster.itemId, isGreaterThan(2)) - } - } - orderBy(itemMaster.itemId) - } - - val expectedStatement = "select im.* from ItemMaster im" + - " where (im.item_id = #{parameters.p1,jdbcType=INTEGER}" + - " and (exists (select ol.* from OrderLine ol where ol.item_id = im.item_id)" + - " and im.item_id > #{parameters.p2,jdbcType=INTEGER}))" + - " order by item_id" - assertThat(selectStatement.selectStatement).isEqualTo(expectedStatement) - - val rows = mapper.selectManyMappedRows(selectStatement) - assertThat(rows).hasSize(1) - - with(rows[0]) { - assertThat(this).containsEntry("ITEM_ID", 22) - assertThat(this).containsEntry("DESCRIPTION", "Helmet") - } - } - } - - @Test - fun testOrExists() { - sqlSessionFactory.openSession().use { session -> - val mapper = session.getMapper(CommonSelectMapper::class.java) - - val selectStatement = select(itemMaster.allColumns()) { - from(itemMaster, "im") - where(itemMaster.itemId, isEqualTo(22)) - or( - exists { - select(orderLine.allColumns()) { - from(orderLine, "ol") - where(orderLine.itemId, isEqualTo(itemMaster.itemId.qualifiedWith("im"))) - } - } - ) - orderBy(itemMaster.itemId) - } - - val expectedStatement = "select im.* from ItemMaster im" + - " where im.item_id = #{parameters.p1,jdbcType=INTEGER}" + - " or exists (select ol.* from OrderLine ol where ol.item_id = im.item_id)" + - " order by item_id" - assertThat(selectStatement.selectStatement).isEqualTo(expectedStatement) - - val rows = mapper.selectManyMappedRows(selectStatement) - assertThat(rows).hasSize(3) - - with(rows[0]) { - assertThat(this).containsEntry("ITEM_ID", 22) - assertThat(this).containsEntry("DESCRIPTION", "Helmet") - } - - with(rows[1]) { - assertThat(this).containsEntry("ITEM_ID", 33) - assertThat(this).containsEntry("DESCRIPTION", "First Base Glove") - } - - with(rows[2]) { - assertThat(this).containsEntry("ITEM_ID", 44) - assertThat(this).containsEntry("DESCRIPTION", "Outfield Glove") - } - } - } - - @Test - fun testOrExistsAnd() { - sqlSessionFactory.openSession().use { session -> - val mapper = session.getMapper(CommonSelectMapper::class.java) - - val selectStatement = select(itemMaster.allColumns()) { - from(itemMaster, "im") - where(itemMaster.itemId, isEqualTo(22)) - or( - exists { - select(orderLine.allColumns()) { - from(orderLine, "ol") - where( - orderLine.itemId, - isEqualTo( - itemMaster.itemId.qualifiedWith("im") - ) - ) - } - } - ) { - and(itemMaster.itemId, isGreaterThan(2)) - } - orderBy(itemMaster.itemId) - } - - val expectedStatement = "select im.* from ItemMaster im" + - " where im.item_id = #{parameters.p1,jdbcType=INTEGER}" + - " or (exists (select ol.* from OrderLine ol where ol.item_id = im.item_id)" + - " and im.item_id > #{parameters.p2,jdbcType=INTEGER})" + - " order by item_id" - assertThat(selectStatement.selectStatement).isEqualTo(expectedStatement) - - val rows = mapper.selectManyMappedRows(selectStatement) - assertThat(rows).hasSize(3) - - with(rows[0]) { - assertThat(this).containsEntry("ITEM_ID", 22) - assertThat(this).containsEntry("DESCRIPTION", "Helmet") - } - - with(rows[1]) { - assertThat(this).containsEntry("ITEM_ID", 33) - assertThat(this).containsEntry("DESCRIPTION", "First Base Glove") - } - - with(rows[2]) { - assertThat(this).containsEntry("ITEM_ID", 44) - assertThat(this).containsEntry("DESCRIPTION", "Outfield Glove") - } - } - } - - @Test - fun testOrExistsAnd2() { - sqlSessionFactory.openSession().use { session -> - val mapper = session.getMapper(CommonSelectMapper::class.java) - - val selectStatement = select(itemMaster.allColumns()) { - from(itemMaster, "im") - where(itemMaster.itemId, isEqualTo(22)) { - or( - exists { - select(orderLine.allColumns()) { - from(orderLine, "ol") - where(orderLine.itemId, isEqualTo(itemMaster.itemId.qualifiedWith("im"))) - } - } - ) - and(itemMaster.itemId, isGreaterThan(2)) - } - orderBy(itemMaster.itemId) - } - - val expectedStatement = "select im.* from ItemMaster im" + - " where (im.item_id = #{parameters.p1,jdbcType=INTEGER}" + - " or exists (select ol.* from OrderLine ol where ol.item_id = im.item_id)" + - " and im.item_id > #{parameters.p2,jdbcType=INTEGER})" + - " order by item_id" - assertThat(selectStatement.selectStatement).isEqualTo(expectedStatement) - - val rows = mapper.selectManyMappedRows(selectStatement) - assertThat(rows).hasSize(3) - - with(rows[0]) { - assertThat(this).containsEntry("ITEM_ID", 22) - assertThat(this).containsEntry("DESCRIPTION", "Helmet") - } - - with(rows[1]) { - assertThat(this).containsEntry("ITEM_ID", 33) - assertThat(this).containsEntry("DESCRIPTION", "First Base Glove") - } - - with(rows[2]) { - assertThat(this).containsEntry("ITEM_ID", 44) - assertThat(this).containsEntry("DESCRIPTION", "Outfield Glove") - } - } - } - - @Test - fun testOrExistsAnd3() { - sqlSessionFactory.openSession().use { session -> - val mapper = session.getMapper(CommonSelectMapper::class.java) - - val selectStatement = select(itemMaster.allColumns()) { - from(itemMaster, "im") - where(itemMaster.itemId, isEqualTo(22)) { - or( - exists { - select(orderLine.allColumns()) { - from(orderLine, "ol") - where(orderLine.itemId, isEqualTo(itemMaster.itemId.qualifiedWith("im"))) - } - } - ) { - and(itemMaster.itemId, isGreaterThan(2)) - } - } - orderBy(itemMaster.itemId) - } - - val expectedStatement = "select im.* from ItemMaster im" + - " where (im.item_id = #{parameters.p1,jdbcType=INTEGER}" + - " or (exists (select ol.* from OrderLine ol where ol.item_id = im.item_id)" + - " and im.item_id > #{parameters.p2,jdbcType=INTEGER}))" + - " order by item_id" - assertThat(selectStatement.selectStatement).isEqualTo(expectedStatement) - - val rows = mapper.selectManyMappedRows(selectStatement) - assertThat(rows).hasSize(3) - - with(rows[0]) { - assertThat(this).containsEntry("ITEM_ID", 22) - assertThat(this).containsEntry("DESCRIPTION", "Helmet") - } - - with(rows[1]) { - assertThat(this).containsEntry("ITEM_ID", 33) - assertThat(this).containsEntry("DESCRIPTION", "First Base Glove") - } - - with(rows[2]) { - assertThat(this).containsEntry("ITEM_ID", 44) - assertThat(this).containsEntry("DESCRIPTION", "Outfield Glove") - } - } - } - - @Test - fun testWhereExistsOr() { - sqlSessionFactory.openSession().use { session -> - val mapper = session.getMapper(CommonSelectMapper::class.java) - - val selectStatement = select(itemMaster.allColumns()) { - from(itemMaster, "im") - where( - exists { - select(orderLine.allColumns()) { - from(orderLine, "ol") - where(orderLine.itemId, isEqualTo(itemMaster.itemId.qualifiedWith("im"))) - } - } - ) { - or(itemMaster.itemId, isEqualTo(22)) - } - orderBy(itemMaster.itemId) - } - - val expectedStatement = "select im.* from ItemMaster im" + - " where (exists (select ol.* from OrderLine ol where ol.item_id = im.item_id)" + - " or im.item_id = #{parameters.p1,jdbcType=INTEGER})" + - " order by item_id" - assertThat(selectStatement.selectStatement).isEqualTo(expectedStatement) - - val rows = mapper.selectManyMappedRows(selectStatement) - assertThat(rows).hasSize(3) - - with(rows[0]) { - assertThat(this).containsEntry("ITEM_ID", 22) - assertThat(this).containsEntry("DESCRIPTION", "Helmet") - } - - with(rows[1]) { - assertThat(this).containsEntry("ITEM_ID", 33) - assertThat(this).containsEntry("DESCRIPTION", "First Base Glove") - } - - with(rows[2]) { - assertThat(this).containsEntry("ITEM_ID", 44) - assertThat(this).containsEntry("DESCRIPTION", "Outfield Glove") - } - } - } - - @Test - fun testWhereExistsAnd() { - sqlSessionFactory.openSession().use { session -> - val mapper = session.getMapper(CommonSelectMapper::class.java) - - val selectStatement = select(itemMaster.allColumns()) { - from(itemMaster, "im") - where( - exists { - select(orderLine.allColumns()) { - from(orderLine, "ol") - where(orderLine.itemId, isEqualTo(itemMaster.itemId.qualifiedWith("im"))) - } - } - ) { - and(itemMaster.itemId, isEqualTo(22)) - } - orderBy(itemMaster.itemId) - } - - val expectedStatement = "select im.* from ItemMaster im" + - " where (exists (select ol.* from OrderLine ol where ol.item_id = im.item_id)" + - " and im.item_id = #{parameters.p1,jdbcType=INTEGER})" + - " order by item_id" - assertThat(selectStatement.selectStatement).isEqualTo(expectedStatement) - - val rows = mapper.selectManyMappedRows(selectStatement) - assertThat(rows).hasSize(1) - - with(rows[0]) { - assertThat(this).containsEntry("ITEM_ID", 22) - assertThat(this).containsEntry("DESCRIPTION", "Helmet") - } - } - } - - @Test - fun testWhereAnd() { - sqlSessionFactory.openSession().use { session -> - val mapper = session.getMapper(CommonSelectMapper::class.java) - - val selectStatement = select(itemMaster.allColumns()) { - from(itemMaster) - where(itemMaster.itemId, isGreaterThan(3)) - and(itemMaster.itemId, isGreaterThan(4)) - orderBy(itemMaster.itemId) - } - - val expectedStatement = "select * from ItemMaster" + - " where item_id > #{parameters.p1,jdbcType=INTEGER}" + - " and item_id > #{parameters.p2,jdbcType=INTEGER}" + - " order by item_id" - assertThat(selectStatement.selectStatement).isEqualTo(expectedStatement) - - val rows = mapper.selectManyMappedRows(selectStatement) - assertThat(rows).hasSize(4) - - with(rows[0]) { - assertThat(this).containsEntry("ITEM_ID", 22) - assertThat(this).containsEntry("DESCRIPTION", "Helmet") - } - } - } - - @Test - fun testWhereAndAnd() { - sqlSessionFactory.openSession().use { session -> - val mapper = session.getMapper(CommonSelectMapper::class.java) - - val selectStatement = select(itemMaster.allColumns()) { - from(itemMaster) - where(itemMaster.itemId, isGreaterThan(3)) - and(itemMaster.itemId, isGreaterThan(4)) { - and(itemMaster.itemId, isGreaterThan(5)) - } - orderBy(itemMaster.itemId) - } - - val expectedStatement = "select * from ItemMaster" + - " where item_id > #{parameters.p1,jdbcType=INTEGER}" + - " and (item_id > #{parameters.p2,jdbcType=INTEGER}" + - " and item_id > #{parameters.p3,jdbcType=INTEGER})" + - " order by item_id" - assertThat(selectStatement.selectStatement).isEqualTo(expectedStatement) - - val rows = mapper.selectManyMappedRows(selectStatement) - assertThat(rows).hasSize(4) - - with(rows[0]) { - assertThat(this).containsEntry("ITEM_ID", 22) - assertThat(this).containsEntry("DESCRIPTION", "Helmet") - } - } - } - - @Test - fun testWhereOr() { - sqlSessionFactory.openSession().use { session -> - val mapper = session.getMapper(CommonSelectMapper::class.java) - - val selectStatement = select(itemMaster.allColumns()) { - from(itemMaster) - where(itemMaster.itemId, isEqualTo(22)) - or(itemMaster.itemId, isEqualTo(33)) - orderBy(itemMaster.itemId) - } - - val expectedStatement = "select * from ItemMaster" + - " where item_id = #{parameters.p1,jdbcType=INTEGER}" + - " or item_id = #{parameters.p2,jdbcType=INTEGER}" + - " order by item_id" - assertThat(selectStatement.selectStatement).isEqualTo(expectedStatement) - - val rows = mapper.selectManyMappedRows(selectStatement) - assertThat(rows).hasSize(2) - - with(rows[0]) { - assertThat(this).containsEntry("ITEM_ID", 22) - assertThat(this).containsEntry("DESCRIPTION", "Helmet") - } - } - } - - @Test - fun testWhereOrOr() { - sqlSessionFactory.openSession().use { session -> - val mapper = session.getMapper(CommonSelectMapper::class.java) - - val selectStatement = select(itemMaster.allColumns()) { - from(itemMaster) - where(itemMaster.itemId, isEqualTo(22)) - or(itemMaster.itemId, isEqualTo(33)) { - or(itemMaster.itemId, isEqualTo(44)) - } - orderBy(itemMaster.itemId) - } - - val expectedStatement = "select * from ItemMaster" + - " where item_id = #{parameters.p1,jdbcType=INTEGER}" + - " or (item_id = #{parameters.p2,jdbcType=INTEGER}" + - " or item_id = #{parameters.p3,jdbcType=INTEGER})" + - " order by item_id" - assertThat(selectStatement.selectStatement).isEqualTo(expectedStatement) - - val rows = mapper.selectManyMappedRows(selectStatement) - assertThat(rows).hasSize(3) - - with(rows[0]) { - assertThat(this).containsEntry("ITEM_ID", 22) - assertThat(this).containsEntry("DESCRIPTION", "Helmet") - } - } - } -} diff --git a/src/test/kotlin/examples/kotlin/mybatis3/joins/JoinMapperTest.kt b/src/test/kotlin/examples/kotlin/mybatis3/joins/JoinMapperTest.kt index 887443214..55a2a26bc 100644 --- a/src/test/kotlin/examples/kotlin/mybatis3/joins/JoinMapperTest.kt +++ b/src/test/kotlin/examples/kotlin/mybatis3/joins/JoinMapperTest.kt @@ -30,7 +30,6 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance import org.mybatis.dynamic.sql.util.Messages import org.mybatis.dynamic.sql.util.kotlin.KInvalidSQLException -import org.mybatis.dynamic.sql.util.kotlin.elements.equalTo import org.mybatis.dynamic.sql.util.kotlin.elements.invoke import org.mybatis.dynamic.sql.util.kotlin.elements.max import org.mybatis.dynamic.sql.util.kotlin.mybatis3.select @@ -127,27 +126,6 @@ class JoinMapperTest { assertThat(selectStatement.selectStatement).isEqualTo(expectedStatement) } - @Test - fun testDeprecatedJoin() { - // this is a nonsensical join, but it does test the "and" capability - val selectStatement = select( - orderMaster.orderId, orderMaster.orderDate, orderDetail.lineNumber, - orderDetail.description, orderDetail.quantity - ) { - from(orderMaster, "om") - join(orderDetail, "od") { - on(orderMaster.orderId, equalTo(orderDetail.orderId)) - and(orderMaster.orderId, equalTo(orderDetail.orderId)) - } - where { orderMaster.orderId isEqualTo 1 } - } - - val expectedStatement = "select om.order_id, om.order_date, od.line_number, od.description, od.quantity" + - " from OrderMaster om join OrderDetail od on om.order_id = od.order_id and om.order_id = od.order_id" + - " where om.order_id = #{parameters.p1,jdbcType=INTEGER}" - assertThat(selectStatement.selectStatement).isEqualTo(expectedStatement) - } - @Test fun testMultipleTableJoinWithWhereClause() { sqlSessionFactory.openSession().use { session -> diff --git a/src/test/kotlin/examples/kotlin/spring/canonical/CanonicalSpringKotlinTemplateDirectTest.kt b/src/test/kotlin/examples/kotlin/spring/canonical/CanonicalSpringKotlinTemplateDirectTest.kt index 77f9c26ca..8e202a373 100644 --- a/src/test/kotlin/examples/kotlin/spring/canonical/CanonicalSpringKotlinTemplateDirectTest.kt +++ b/src/test/kotlin/examples/kotlin/spring/canonical/CanonicalSpringKotlinTemplateDirectTest.kt @@ -191,23 +191,6 @@ open class CanonicalSpringKotlinTemplateDirectTest { assertThat(rows).isEqualTo(1) } - @Test - fun testDeprecatedInsert() { - val record = PersonRecord(100, "Joe", LastName("Jones"), Date(), true, "Developer", 1) - - val rows = template.insert(record).into(person) { - map(id).toProperty("id") - map(firstName).toProperty("firstName") - map(lastName).toProperty("lastNameAsString") - map(birthDate).toProperty("birthDate") - map(employed).toProperty("employedAsString") - map(occupation).toPropertyWhenPresent("occupation", record::occupation) - map(addressId).toProperty("addressId") - } - - assertThat(rows).isEqualTo(1) - } - @Test fun testGeneralInsert() { val rows = template.insertInto(person) { @@ -242,24 +225,6 @@ open class CanonicalSpringKotlinTemplateDirectTest { assertThat(rows).isEqualTo(2) } - @Test - fun testDeprecatedMultiRowInsert() { - val record1 = PersonRecord(100, "Joe", LastName("Jones"), Date(), true, "Developer", 1) - val record2 = PersonRecord(101, "Sarah", LastName("Smith"), Date(), true, "Architect", 2) - - val rows = template.insertMultiple(record1, record2).into(person) { - map(id).toProperty("id") - map(firstName).toProperty("firstName") - map(lastName).toProperty("lastNameAsString") - map(birthDate).toProperty("birthDate") - map(employed).toProperty("employedAsString") - map(occupation).toProperty("occupation") - map(addressId).toProperty("addressId") - } - - assertThat(rows).isEqualTo(2) - } - @Test fun testBatchInsert() { val record1 = PersonRecord(100, "Joe", LastName("Jones"), Date(), true, "Developer", 1) @@ -281,26 +246,6 @@ open class CanonicalSpringKotlinTemplateDirectTest { assertThat(rows[1]).isEqualTo(1) } - @Test - fun testDeprecatedBatchInsert() { - val record1 = PersonRecord(100, "Joe", LastName("Jones"), Date(), true, "Developer", 1) - val record2 = PersonRecord(101, "Sarah", LastName("Smith"), Date(), true, "Architect", 2) - - val rows = template.insertBatch(record1, record2).into(person) { - map(id).toProperty("id") - map(firstName).toProperty("firstName") - map(lastName).toProperty("lastNameAsString") - map(birthDate).toProperty("birthDate") - map(employed).toProperty("employedAsString") - map(occupation).toProperty("occupation") - map(addressId).toProperty("addressId") - } - - assertThat(rows).hasSize(2) - assertThat(rows[0]).isEqualTo(1) - assertThat(rows[1]).isEqualTo(1) - } - @Test fun testInsertSelect() { val rows = template.insertSelect { @@ -334,38 +279,6 @@ open class CanonicalSpringKotlinTemplateDirectTest { } } - @Test - fun testDeprecatedInsertSelect() { - val rows = template.insertSelect(person) { - columns(id, firstName, lastName, birthDate, employed, occupation, addressId) - select( - add(id, constant("100")), firstName, lastName, birthDate, employed, occupation, addressId - ) { - from(person) - orderBy(id) - } - } - - assertThat(rows).isEqualTo(6) - - val records = template.select(id, firstName, lastName, birthDate, employed, occupation, addressId) { - from(person) - where { id isGreaterThanOrEqualTo 100 } - orderBy(id) - }.withRowMapper(personRowMapper) - - assertThat(records).hasSize(6) - with(records[1]) { - assertThat(id).isEqualTo(102) - assertThat(firstName).isEqualTo("Wilma") - assertThat(lastName).isEqualTo(LastName("Flintstone")) - assertThat(birthDate).isNotNull - assertThat(employed).isTrue - assertThat(occupation).isEqualTo("Accountant") - assertThat(addressId).isEqualTo(1) - } - } - @Test @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) fun testGeneralInsertWithGeneratedKey() { @@ -403,25 +316,6 @@ open class CanonicalSpringKotlinTemplateDirectTest { assertThat(keyHolder.keys).containsEntry("FULL_NAME", "Fred Flintstone") } - @Test - @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) - fun testDeprecatedInsertWithGeneratedKey() { - val command = GeneratedAlwaysCommand(firstName = "Fred", lastName = "Flintstone") - - val keyHolder = GeneratedKeyHolder() - - val rows = template.withKeyHolder(keyHolder) { - insert(command).into(generatedAlways) { - map(generatedAlways.firstName).toProperty("firstName") - map(generatedAlways.lastName).toProperty("lastName") - } - } - - assertThat(rows).isEqualTo(1) - assertThat(keyHolder.keys).containsEntry("ID", 22) - assertThat(keyHolder.keys).containsEntry("FULL_NAME", "Fred Flintstone") - } - @Test @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) fun testMultiRowInsertWithGeneratedKey() { @@ -445,35 +339,14 @@ open class CanonicalSpringKotlinTemplateDirectTest { assertThat(keyHolder.keyList[1]).containsEntry("FULL_NAME", "Barney Rubble") } - @Test - @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) - fun testDeprecatedMultiRowInsertWithGeneratedKey() { - val command1 = GeneratedAlwaysCommand(firstName = "Fred", lastName = "Flintstone") - val command2 = GeneratedAlwaysCommand(firstName = "Barney", lastName = "Rubble") - - val keyHolder = GeneratedKeyHolder() - - val rows = template.withKeyHolder(keyHolder) { - insertMultiple(command1, command2).into(generatedAlways) { - map(generatedAlways.firstName).toProperty("firstName") - map(generatedAlways.lastName).toProperty("lastName") - } - } - - assertThat(rows).isEqualTo(2) - assertThat(keyHolder.keyList[0]).containsEntry("ID", 22) - assertThat(keyHolder.keyList[0]).containsEntry("FULL_NAME", "Fred Flintstone") - assertThat(keyHolder.keyList[1]).containsEntry("ID", 23) - assertThat(keyHolder.keyList[1]).containsEntry("FULL_NAME", "Barney Rubble") - } - @Test @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) fun testInsertSelectWithGeneratedKey() { val keyHolder = GeneratedKeyHolder() val rows = template.withKeyHolder(keyHolder) { - insertSelect(generatedAlways) { + insertSelect { + into(generatedAlways) columns(generatedAlways.firstName, generatedAlways.lastName) select(person.firstName, person.lastName) { from(person) diff --git a/src/test/kotlin/examples/kotlin/spring/canonical/CanonicalSpringKotlinTest.kt b/src/test/kotlin/examples/kotlin/spring/canonical/CanonicalSpringKotlinTest.kt index 525fd41f7..5351d2dad 100644 --- a/src/test/kotlin/examples/kotlin/spring/canonical/CanonicalSpringKotlinTest.kt +++ b/src/test/kotlin/examples/kotlin/spring/canonical/CanonicalSpringKotlinTest.kt @@ -34,9 +34,6 @@ import org.mybatis.dynamic.sql.util.kotlin.KInvalidSQLException import org.mybatis.dynamic.sql.util.kotlin.elements.`as` import org.mybatis.dynamic.sql.util.kotlin.elements.add import org.mybatis.dynamic.sql.util.kotlin.elements.constant -import org.mybatis.dynamic.sql.util.kotlin.elements.insert -import org.mybatis.dynamic.sql.util.kotlin.elements.insertBatch -import org.mybatis.dynamic.sql.util.kotlin.elements.insertMultiple import org.mybatis.dynamic.sql.util.kotlin.elements.isLikeWhenPresent import org.mybatis.dynamic.sql.util.kotlin.elements.max import org.mybatis.dynamic.sql.util.kotlin.elements.sortColumn @@ -52,7 +49,6 @@ import org.mybatis.dynamic.sql.util.kotlin.spring.insertBatch import org.mybatis.dynamic.sql.util.kotlin.spring.insertInto import org.mybatis.dynamic.sql.util.kotlin.spring.insertMultiple import org.mybatis.dynamic.sql.util.kotlin.spring.insertSelect -import org.mybatis.dynamic.sql.util.kotlin.spring.into import org.mybatis.dynamic.sql.util.kotlin.spring.select import org.mybatis.dynamic.sql.util.kotlin.spring.selectDistinct import org.mybatis.dynamic.sql.util.kotlin.spring.selectList @@ -273,36 +269,6 @@ open class CanonicalSpringKotlinTest { assertThat(rows).isEqualTo(1) } - @Test - fun testDeprecatedInsert() { - - val record = PersonRecord(100, "Joe", LastName("Jones"), Date(), true, "Developer", 1) - - val insertStatement = insert(record).into(person) { - map(id).toProperty("id") - map(firstName).toProperty("firstName") - map(lastName).toProperty("lastNameAsString") - map(birthDate).toProperty("birthDate") - map(employed).toProperty("employedAsString") - map(occupation).toProperty("occupation") - map(addressId).toProperty("addressId") - } - - val expected = - "insert into Person (id, first_name, last_name, birth_date, employed, occupation, address_id)" + - " values" + - " (:id, :firstName," + - " :lastNameAsString," + - " :birthDate, :employedAsString," + - " :occupation, :addressId)" - - assertThat(insertStatement.insertStatement).isEqualTo(expected) - - val rows = template.insert(insertStatement) - - assertThat(rows).isEqualTo(1) - } - @Test fun testGeneralInsert() { @@ -406,35 +372,6 @@ open class CanonicalSpringKotlinTest { assertThat(rows).isEqualTo(2) } - @Test - fun testDeprecatedMultiRowInsert() { - val record1 = PersonRecord(100, "Joe", LastName("Jones"), Date(), true, "Developer", 1) - val record2 = PersonRecord(101, "Sarah", LastName("Smith"), Date(), true, "Architect", 2) - - val insertStatement = insertMultiple(record1, record2).into(person) { - map(id).toProperty("id") - map(firstName).toProperty("firstName") - map(lastName).toProperty("lastNameAsString") - map(birthDate).toProperty("birthDate") - map(employed).toProperty("employedAsString") - map(occupation).toProperty("occupation") - map(addressId).toProperty("addressId") - } - - assertThat(insertStatement.insertStatement).isEqualTo( - "insert into Person (id, first_name, last_name, birth_date, employed, occupation, address_id) " + - "values (:records[0].id, :records[0].firstName, :records[0].lastNameAsString, " + - ":records[0].birthDate, :records[0].employedAsString, " + - ":records[0].occupation, :records[0].addressId), " + - "(:records[1].id, :records[1].firstName, :records[1].lastNameAsString, " + - ":records[1].birthDate, :records[1].employedAsString, :records[1].occupation, " + - ":records[1].addressId)" - ) - - val rows = template.insertMultiple(insertStatement) - assertThat(rows).isEqualTo(2) - } - @Test fun testBatchInsert() { val record1 = PersonRecord( @@ -473,43 +410,6 @@ open class CanonicalSpringKotlinTest { assertThat(rows[1]).isEqualTo(1) } - @Test - fun testDeprecatedBatchInsert() { - val record1 = PersonRecord( - 100, - "Joe", - LastName("Jones"), - Date(), - true, - "Developer", - 1 - ) - val record2 = PersonRecord( - 101, - "Sarah", - LastName("Smith"), - Date(), - true, - "Architect", - 2 - ) - - val insertStatement = insertBatch(record1, record2).into(person) { - map(id).toProperty("id") - map(firstName).toProperty("firstName") - map(lastName).toProperty("lastNameAsString") - map(birthDate).toProperty("birthDate") - map(employed).toProperty("employedAsString") - map(occupation).toProperty("occupation") - map(addressId).toProperty("addressId") - } - - val rows = template.insertBatch(insertStatement) - assertThat(rows).hasSize(2) - assertThat(rows[0]).isEqualTo(1) - assertThat(rows[1]).isEqualTo(1) - } - @Test fun testInsertSelect() { val insertStatement = insertSelect { @@ -561,46 +461,10 @@ open class CanonicalSpringKotlinTest { }.withMessage(Messages.getString("ERROR.29")) } - @Test - fun testDeprecatedInsertSelect() { - val insertStatement = insertSelect(person) { - columns(id, firstName, lastName, birthDate, employed, occupation, addressId) - select(add(id, constant("100")), firstName, lastName, birthDate, employed, occupation, addressId) { - from(person) - orderBy(id) - } - } - - assertThat(insertStatement.insertStatement).isEqualTo( - "insert into Person (id, first_name, last_name, birth_date, employed, occupation, address_id) " + - "select (id + 100), first_name, last_name, birth_date, employed, occupation, address_id " + - "from Person " + - "order by id" - ) - val rows = template.insertSelect(insertStatement) - assertThat(rows).isEqualTo(6) - - val records = template.select(id, firstName, lastName, birthDate, employed, occupation, addressId) { - from(person) - where { id isGreaterThanOrEqualTo 100 } - orderBy(id) - }.withRowMapper(personRowMapper) - - assertThat(records).hasSize(6) - with(records[1]) { - assertThat(id).isEqualTo(102) - assertThat(firstName).isEqualTo("Wilma") - assertThat(lastName).isEqualTo(LastName("Flintstone")) - assertThat(birthDate).isNotNull - assertThat(employed).isTrue - assertThat(occupation).isEqualTo("Accountant") - assertThat(addressId).isEqualTo(1) - } - } - @Test fun testInsertSelectNoColumns() { - val insertStatement = insertSelect(person) { + val insertStatement = insertSelect { + into(person) select(add(id, constant("100")), firstName, lastName, birthDate, employed, occupation, addressId) { from(person) orderBy(id) @@ -620,7 +484,8 @@ open class CanonicalSpringKotlinTest { @Test fun testInsertSelectEmptyColumnList() { assertThatExceptionOfType(InvalidSqlException::class.java).isThrownBy { - insertSelect(person) { + insertSelect { + into(person) columns() select(add(id, constant("100")), firstName, lastName, birthDate, employed, occupation, addressId) { from(person) @@ -633,7 +498,8 @@ open class CanonicalSpringKotlinTest { @Test fun testInsertSelectNoSelectStatement() { assertThatExceptionOfType(KInvalidSQLException::class.java).isThrownBy { - insertSelect(person) { + insertSelect { + into(person) columns(id, firstName, lastName, birthDate, employed, occupation, addressId) } }.withMessage(Messages.getString("ERROR.28")) //$NON-NLS-1$ @@ -734,7 +600,8 @@ open class CanonicalSpringKotlinTest { @Test @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) fun testInsertSelectWithGeneratedKey() { - val insertStatement = insertSelect(generatedAlways) { + val insertStatement = insertSelect { + into(generatedAlways) columns(generatedAlways.firstName, generatedAlways.lastName) select(person.firstName, person.lastName) { from(person)