Skip to content

Better Use of Kotlin Self Type #155

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -24,85 +24,90 @@ import org.mybatis.dynamic.sql.util.Buildable
import org.mybatis.dynamic.sql.where.AbstractWhereDSL

abstract class KotlinBaseBuilder<M, W : AbstractWhereDSL<W>, B : KotlinBaseBuilder<M, W, B>> : Buildable<M> {
fun <T> where(column: BindableColumn<T>, condition: VisitableCondition<T>): B {
getWhere().where(column, condition)
return getThis()
}

fun <T> where(column: BindableColumn<T>, condition: VisitableCondition<T>, collect: CriteriaReceiver): B {
getWhere().where(column, condition, collect)
return getThis()
}

fun applyWhere(whereApplier: WhereApplier): B {
getWhere().applyWhere(whereApplier)
return getThis()
}

fun <T> and(column: BindableColumn<T>, condition: VisitableCondition<T>): B {
getWhere().and(column, condition)
return getThis()
}

fun <T> and(column: BindableColumn<T>, condition: VisitableCondition<T>, collect: CriteriaReceiver): B {
getWhere().and(column, condition, collect)
return getThis()
}

fun <T> or(column: BindableColumn<T>, condition: VisitableCondition<T>): B {
getWhere().or(column, condition)
return getThis()
}

fun <T> or(column: BindableColumn<T>, condition: VisitableCondition<T>, collect: CriteriaReceiver): B {
getWhere().or(column, condition, collect)
return getThis()
}
fun <T> where(column: BindableColumn<T>, condition: VisitableCondition<T>): B =
applySelf {
getWhere().where(column, condition)
}

fun <T> where(column: BindableColumn<T>, condition: VisitableCondition<T>, collect: CriteriaReceiver): B =
applySelf {
getWhere().where(column, condition, collect)
}

fun applyWhere(whereApplier: WhereApplier): B =
applySelf {
getWhere().applyWhere(whereApplier)
}

fun <T> and(column: BindableColumn<T>, condition: VisitableCondition<T>): B =
applySelf {
getWhere().and(column, condition)
}

fun <T> and(column: BindableColumn<T>, condition: VisitableCondition<T>, collect: CriteriaReceiver): B =
applySelf {
getWhere().and(column, condition, collect)
}

fun <T> or(column: BindableColumn<T>, condition: VisitableCondition<T>): B =
applySelf {
getWhere().or(column, condition)
}

fun <T> or(column: BindableColumn<T>, condition: VisitableCondition<T>, 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<T : AbstractQueryExpressionDSL<T, SelectModel>, W: AbstractWhereDSL<W>, B : KotlinBaseJoiningBuilder<T, W, B>>(private val dsl: AbstractQueryExpressionDSL<T, SelectModel>) :
KotlinBaseBuilder<SelectModel, W, B>() {

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<T : AbstractQueryExpressionDSL<T, SelectModel>, W : AbstractWhereDSL<W>, B : KotlinBaseJoiningBuilder<T, W, B>>(
private val dsl: AbstractQueryExpressionDSL<T, SelectModel>
) : KotlinBaseBuilder<SelectModel, W, B>() {

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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ class KotlinCountBuilder(private val dsl: CountDSL<SelectModel>) :

override fun getWhere(): CountDSL<SelectModel>.CountWhereBuilder = dsl.where()

override fun getThis() = this
override fun self() = this
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ class KotlinDeleteBuilder(private val dsl: DeleteDSL<DeleteModel>) :

override fun getWhere(): DeleteDSL<DeleteModel>.DeleteWhereBuilder = dsl.where()

override fun getThis(): KotlinDeleteBuilder = this
override fun self() = this
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ class KotlinQueryBuilder(private val dsl: QueryExpressionDSL<SelectModel>) :

override fun getWhere(): QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder = dsl.where()

override fun getThis() = this
override fun self() = this
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ class KotlinUpdateBuilder(private val dsl: UpdateDSL<UpdateModel>) :

override fun getWhere(): UpdateDSL<UpdateModel>.UpdateWhereBuilder = dsl.where()

override fun getThis(): KotlinUpdateBuilder = this
override fun self() = this
}
2 changes: 2 additions & 0 deletions travis/after_success.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down