From eb4ab2c07f82c65277ed21fa3860736a3179f3f4 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Sat, 23 Nov 2019 14:13:33 -0500 Subject: [PATCH 1/2] Better usage of Kotlin self type --- .../sql/util/kotlin/KotlinBaseBuilders.kt | 159 +++++++++--------- .../sql/util/kotlin/KotlinCountBuilder.kt | 2 +- .../sql/util/kotlin/KotlinDeleteBuilder.kt | 2 +- .../sql/util/kotlin/KotlinQueryBuilder.kt | 2 +- .../sql/util/kotlin/KotlinUpdateBuilder.kt | 2 +- 5 files changed, 86 insertions(+), 81 deletions(-) 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 c26e96935..77d3135c4 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 @@ -24,85 +24,90 @@ import org.mybatis.dynamic.sql.util.Buildable import org.mybatis.dynamic.sql.where.AbstractWhereDSL abstract class KotlinBaseBuilder, B : KotlinBaseBuilder> : Buildable { - fun where(column: BindableColumn, condition: VisitableCondition): B { - getWhere().where(column, condition) - return getThis() - } - - fun where(column: BindableColumn, condition: VisitableCondition, collect: CriteriaReceiver): B { - getWhere().where(column, condition, collect) - return getThis() - } - - fun applyWhere(whereApplier: WhereApplier): B { - getWhere().applyWhere(whereApplier) - return getThis() - } - - fun and(column: BindableColumn, condition: VisitableCondition): B { - getWhere().and(column, condition) - return getThis() - } - - fun and(column: BindableColumn, condition: VisitableCondition, collect: CriteriaReceiver): B { - getWhere().and(column, condition, collect) - return getThis() - } - - fun or(column: BindableColumn, condition: VisitableCondition): B { - getWhere().or(column, condition) - return getThis() - } - - fun or(column: BindableColumn, condition: VisitableCondition, collect: CriteriaReceiver): B { - getWhere().or(column, condition, collect) - return getThis() - } + fun where(column: BindableColumn, condition: VisitableCondition): B = + applySelf { + getWhere().where(column, condition) + } + + fun where(column: BindableColumn, condition: VisitableCondition, collect: CriteriaReceiver): B = + applySelf { + getWhere().where(column, condition, collect) + } + + fun applyWhere(whereApplier: WhereApplier): B = + applySelf { + getWhere().applyWhere(whereApplier) + } + + fun and(column: BindableColumn, condition: VisitableCondition): B = + applySelf { + getWhere().and(column, condition) + } + + fun and(column: BindableColumn, condition: VisitableCondition, collect: CriteriaReceiver): B = + applySelf { + getWhere().and(column, condition, collect) + } + + fun or(column: BindableColumn, condition: VisitableCondition): B = + applySelf { + getWhere().or(column, condition) + } + + fun or(column: BindableColumn, condition: VisitableCondition, collect: CriteriaReceiver): B = + applySelf { + getWhere().or(column, condition, collect) + } + + protected fun applySelf(block: B.() -> Unit): B = + self().apply { block() } + + protected abstract fun self(): B protected abstract fun getWhere(): W - protected abstract fun getThis(): B } -abstract class KotlinBaseJoiningBuilder, W: AbstractWhereDSL, B : KotlinBaseJoiningBuilder>(private val dsl: AbstractQueryExpressionDSL) : - KotlinBaseBuilder() { - - fun join(table: SqlTable, receiver: JoinReceiver) = - apply { - dsl.join(table, receiver) - } - - fun join(table: SqlTable, alias: String, receiver: JoinReceiver) = - apply { - dsl.join(table, alias, receiver) - } - - fun fullJoin(table: SqlTable, receiver: JoinReceiver) = - apply { - dsl.fullJoin(table, receiver) - } - - fun fullJoin(table: SqlTable, alias: String, receiver: JoinReceiver) = - apply { - dsl.fullJoin(table, alias, receiver) - } - - fun leftJoin(table: SqlTable, receiver: JoinReceiver) = - apply { - dsl.leftJoin(table, receiver) - } - - fun leftJoin(table: SqlTable, alias: String, receiver: JoinReceiver) = - apply { - dsl.leftJoin(table, alias, receiver) - } - - fun rightJoin(table: SqlTable, receiver: JoinReceiver) = - apply { - dsl.rightJoin(table, receiver) - } - - fun rightJoin(table: SqlTable, alias: String, receiver: JoinReceiver) = - apply { - dsl.rightJoin(table, alias, receiver) - } +abstract class KotlinBaseJoiningBuilder, W : AbstractWhereDSL, B : KotlinBaseJoiningBuilder>( + private val dsl: AbstractQueryExpressionDSL +) : KotlinBaseBuilder() { + + fun join(table: SqlTable, receiver: JoinReceiver): B = + applySelf { + dsl.join(table, receiver) + } + + fun join(table: SqlTable, alias: String, receiver: JoinReceiver): B = + applySelf { + dsl.join(table, alias, receiver) + } + + fun fullJoin(table: SqlTable, receiver: JoinReceiver): B = + applySelf { + dsl.fullJoin(table, receiver) + } + + fun fullJoin(table: SqlTable, alias: String, receiver: JoinReceiver): B = + applySelf { + dsl.fullJoin(table, alias, receiver) + } + + fun leftJoin(table: SqlTable, receiver: JoinReceiver): B = + applySelf { + dsl.leftJoin(table, receiver) + } + + fun leftJoin(table: SqlTable, alias: String, receiver: JoinReceiver): B = + applySelf { + dsl.leftJoin(table, alias, receiver) + } + + fun rightJoin(table: SqlTable, receiver: JoinReceiver): B = + applySelf { + dsl.rightJoin(table, receiver) + } + + fun rightJoin(table: SqlTable, alias: String, receiver: JoinReceiver): B = + applySelf { + dsl.rightJoin(table, alias, receiver) + } } diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinCountBuilder.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinCountBuilder.kt index 17149aa7d..eed0caeaa 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinCountBuilder.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinCountBuilder.kt @@ -30,5 +30,5 @@ class KotlinCountBuilder(private val dsl: CountDSL) : override fun getWhere(): CountDSL.CountWhereBuilder = dsl.where() - override fun getThis() = this + override fun self() = this } diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinDeleteBuilder.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinDeleteBuilder.kt index cdf4bd4d7..a986596bb 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinDeleteBuilder.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinDeleteBuilder.kt @@ -30,5 +30,5 @@ class KotlinDeleteBuilder(private val dsl: DeleteDSL) : override fun getWhere(): DeleteDSL.DeleteWhereBuilder = dsl.where() - override fun getThis(): KotlinDeleteBuilder = this + override fun self() = this } diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinQueryBuilder.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinQueryBuilder.kt index 5338eda3a..60976a20d 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinQueryBuilder.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinQueryBuilder.kt @@ -54,5 +54,5 @@ class KotlinQueryBuilder(private val dsl: QueryExpressionDSL) : override fun getWhere(): QueryExpressionDSL.QueryExpressionWhereBuilder = dsl.where() - override fun getThis() = this + override fun self() = this } diff --git a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinUpdateBuilder.kt b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinUpdateBuilder.kt index e7dc3beb8..8a10346d9 100644 --- a/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinUpdateBuilder.kt +++ b/src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinUpdateBuilder.kt @@ -38,5 +38,5 @@ class KotlinUpdateBuilder(private val dsl: UpdateDSL) : override fun getWhere(): UpdateDSL.UpdateWhereBuilder = dsl.where() - override fun getThis(): KotlinUpdateBuilder = this + override fun self() = this } From 1c1f875e699e7231726e1e31566cad14ca201522 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Sat, 23 Nov 2019 14:33:32 -0500 Subject: [PATCH 2/2] Update Travis - do not run sonar for external pull requests --- .travis.yml | 4 ---- travis/after_success.sh | 2 ++ 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index f06d1510c..52567dedb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,3 @@ addons: organization: "mybatis" token: secure: "Hci6OzYOkzcy6CUWlJTe5zLHRFRUO0KVe5o/V3RvtWndz3/4CHmWkP/dZjMxYliUiOZ+UR9uQhVH6dqcKSR94vb++CiDDxorkzqWiWlMEZMaWflvOe/dQsvKwPGZ/QO32RR+Boh0b3VrWZIOsu84wpYAMyZmncXJ0Y2QvmodiqtChYvV+8F6ZimNCfkGZRJhRfKnAbqFsPlB/c9TQc6hW0Dg9rWtjsbQFVtnkIhu48NdVtylPidHUSQWj0JsVQRvWUmBkoMr7lFSImyCW2r7X5vrVIccH6LTPk1Q5V4A8UgCtHhSnQcAFmFi/cxpUqIRgfjvB3azjp/Z9PrzZUFLgRzo3piKZkuQpI5a9xAANH7xcfiZfqztapLx6glW1c5oHRvk771dLcm5+he6JxKIKBBt8BFGOpkXG5NyvDOGHA4bo36oz6VL2L7oVRrS0KdgfFBmQFCuB0cRH3sQGGE4TjyghJUWLnYDRvQGz1IiX94xPUf/+MOHrMeLs/QIROOKJRTMyNC9u+ZQJeQK+i20b4A7euFP8fwzvQRJm3EgEuQf501raPUUDv+Kh4YskDg86fDHxJrmrpM4UsFe6V/WDPFGZc1zRJJRI5yeiaVg5M0KAt5SYfrV1YcjU5ExvKj7x9vyQ3pcfpLlKIKyFKBJMRryMQLNCn+frEJbxlrxJDE=" - -script: -- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package org.jacoco:jacoco-maven-plugin:report -- if [ "$TRAVIS_JDK_VERSION" == "openjdk8" ]; then mvn sonar:sonar -Dsonar.projectKey=mybatis_mybatis-dynamic-sql; fi diff --git a/travis/after_success.sh b/travis/after_success.sh index 20f4572c9..1bf631423 100644 --- a/travis/after_success.sh +++ b/travis/after_success.sh @@ -38,6 +38,8 @@ if [ $TRAVIS_JDK_VERSION == "openjdk8" ] && [ $TRAVIS_REPO_SLUG == "mybatis/myba echo -e "Successfully ran coveralls under Travis job ${TRAVIS_JOB_NUMBER}" if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "master" ] && [[ "$commit_message" != *"[maven-release-plugin]"* ]]; then + # Run Sonar Analysis + ./mvnw sonar:sonar -Dsonar.projectKey=mybatis_mybatis-dynamic-sql # Deploy to Sonatype ./mvnw clean deploy -q --settings ./travis/settings.xml echo -e "Successfully deployed SNAPSHOT artifacts to Sonatype under Travis job ${TRAVIS_JOB_NUMBER}"