Skip to content

Commit

Permalink
Merge pull request #9 from huanshankeji/dev-dependent-on-snapshots
Browse files Browse the repository at this point in the history
Develop dependent on snapshots
  • Loading branch information
ShreckYe authored Oct 19, 2024
2 parents 3528563 + 33abe19 commit 82c5077
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 15 deletions.
7 changes: 4 additions & 3 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ repositories {
}

dependencies {
implementation(kotlin("gradle-plugin", "2.0.0"))
implementation("com.huanshankeji:common-gradle-dependencies:0.7.1-20240516")
implementation("com.huanshankeji.team:gradle-plugins:0.5.1")
// With Kotlin 2.0.20, a "Could not parse POM" build error occurs in the JVM projects of some dependent projects.
implementation(kotlin("gradle-plugin", "2.0.10"))
implementation("com.huanshankeji:common-gradle-dependencies:0.8.0-20241016") // don't use a snapshot version in a main branch
implementation("com.huanshankeji.team:gradle-plugins:0.6.0") // don't use a snapshot version in a main branch
}
5 changes: 3 additions & 2 deletions buildSrc/src/main/kotlin/VersionsAndDependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import com.huanshankeji.CommonVersions

val projectVersion = "0.4.0-SNAPSHOT"

val commonVersions = CommonVersions()
// TODO don't use a snapshot version in a main branch
val commonVersions = CommonVersions(kotlinCommon = "0.5.1")
val commonDependencies = CommonDependencies(commonVersions)
val commonGradleClasspathDependencies = CommonGradleClasspathDependencies(commonVersions)

object DependencyVersions {
val exposedAdtMapping = "0.1.0"
val exposedAdtMapping = "0.2.0"
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.huanshankeji.exposedvertxsqlclient

import arrow.core.*
import com.huanshankeji.collections.singleOrNullIfEmpty
import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig.Socket
import com.huanshankeji.exposedvertxsqlclient.ConnectionConfig.UnixDomainSocketWithPeerAuthentication
import com.huanshankeji.exposedvertxsqlclient.sql.selectExpression
Expand Down Expand Up @@ -171,10 +172,24 @@ class DatabaseClient<out VertxSqlClient : SqlClient>(
suspend fun <U> executeWithMapping(statement: Statement<*>, RowMapper: Function<Row, U>): RowSet<U> =
execute(statement) { mapping(RowMapper) }

// TODO call `getFieldExpressionSet` inside existing transactions (the ones used to prepare the query) to further optimize the performance
@ExperimentalEvscApi
fun FieldSet.getFieldExpressionSetWithTransaction() =
exposedTransaction { getFieldExpressionSet() }

@Deprecated("This function is called nowhere except `Row.toExposedResultRowWithTransaction`. Consider inlining and removing it.")
@ExperimentalEvscApi
fun Query.getFieldExpressionSetWithTransaction() =
set.getFieldExpressionSetWithTransaction()

@ExperimentalEvscApi
fun Row.toExposedResultRowWithTransaction(query: Query) =
toExposedResultRow(query.getFieldExpressionSetWithTransaction())

suspend inline fun <Data> executeQuery(
query: Query, crossinline resultRowMapper: ResultRow.() -> Data
): RowSet<Data> =
executeWithMapping(query) { row -> row.toExposedResultRow(query).resultRowMapper() }
executeWithMapping(query) { row -> row.toExposedResultRowWithTransaction(query).resultRowMapper() }

suspend fun executeQuery(query: Query): RowSet<ResultRow> =
executeQuery(query) { this }
Expand Down Expand Up @@ -279,7 +294,7 @@ class DatabaseClient<out VertxSqlClient : SqlClient>(
suspend inline fun <Data> executeBatchQuery(
fieldSet: FieldSet, queries: Iterable<Query>, crossinline resultRowMapper: ResultRow.() -> Data
): Sequence<RowSet<Data>> {
val fieldExpressionSet = fieldSet.getFieldExpressionSet()
val fieldExpressionSet = fieldSet.getFieldExpressionSetWithTransaction()
return executeBatch(queries) {
mapping { row -> row.toExposedResultRow(fieldExpressionSet).resultRowMapper() }
}
Expand All @@ -288,6 +303,11 @@ class DatabaseClient<out VertxSqlClient : SqlClient>(
suspend fun executeBatchQuery(fieldSet: FieldSet, queries: Iterable<Query>): Sequence<RowSet<ResultRow>> =
executeBatchQuery(fieldSet, queries) { this }

/*
TODO Consider basing it on `Sequence` instead of `Iterable` so there is less wrapping and conversion
when mapping as sequences, such as `asSequence` and `toIterable`.
Also consider adding both versions.
*/
/**
* Executes a batch of update statements, including [InsertStatement] and [UpdateStatement].
* @see org.jetbrains.exposed.sql.batchInsert
Expand All @@ -303,10 +323,13 @@ class DatabaseClient<out VertxSqlClient : SqlClient>(
fun <R> RowSet<R>.singleResult(): R =
single()

// TODO consider moving into "kotlin-common" and renaming to "singleOrZero"
/** "single or no" means differently here from [Iterable.singleOrNull]. */
@Deprecated(
"Just use `singleOrNullIfEmpty` from \"kotlin-common\".",
ReplaceWith("this.singleOrNullIfEmpty()", "com.huanshankeji.collections.singleOrNullIfEmpty")
)
fun <R> RowSet<R>.singleOrNoResult(): R? =
if (none()) null else single()
singleOrNullIfEmpty()

fun Row.toExposedResultRow(fieldExpressionSet: Set<Expression<*>>) =
ResultRow.createAndFillValues(
Expand All @@ -320,13 +343,29 @@ fun Row.toExposedResultRow(fieldExpressionSet: Set<Expression<*>>) =
}.toMap()
)

private const val USE_THE_ONE_IN_DATABASE_CLIENT_BECAUSE_TRANSACTION_REQUIRED_MESSAGE =
"Use the one in `DatabaseClient` because a transaction may be required."

/**
* An Exposed transaction is required if the [FieldSet] contains custom functions that depend on dialects.
*/
//@Deprecated(USE_THE_ONE_IN_DATABASE_CLIENT_BECAUSE_TRANSACTION_REQUIRED_MESSAGE)
fun FieldSet.getFieldExpressionSet() =
/** [org.jetbrains.exposed.sql.AbstractQuery.ResultIterator.fieldsIndex] */
realFields.toSet()

/**
* @see FieldSet.getFieldExpressionSet
*/
@Deprecated("This function is called nowhere except `Row.toExposedResultRow`. Consider inlining and removing it.")
//@Deprecated(USE_THE_ONE_IN_DATABASE_CLIENT_BECAUSE_TRANSACTION_REQUIRED_MESSAGE)
fun Query.getFieldExpressionSet() =
set.getFieldExpressionSet()

/**
* @see FieldSet.getFieldExpressionSet
*/
//@Deprecated(USE_THE_ONE_IN_DATABASE_CLIENT_BECAUSE_TRANSACTION_REQUIRED_MESSAGE)
fun Row.toExposedResultRow(query: Query) =
toExposedResultRow(query.getFieldExpressionSet())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ suspend inline fun <Data> DatabaseClient<*>.select(
): RowSet<Data> =
executeQuery(columnSet.buildQuery(), resultRowMapper)

// TODO adapt to the new SELECT DSL or deprecate
suspend inline fun DatabaseClient<*>.select(
columnSet: ColumnSet, buildQuery: ColumnSet.() -> Query
): RowSet<ResultRow> =
@Suppress("MoveLambdaOutsideParentheses")
select(columnSet, buildQuery, { this })


// TODO adapt to the new SELECT DSL or deprecate
/**
* SQL: `SELECT <expression> FROM <table>;`.
* Examples: `SELECT COUNT(*) FROM <table>;`, `SELECT COUNT(*) FROM <table>;`.
* Examples: `SELECT COUNT(*) FROM <table>;`, `SELECT SUM(<column>) FROM <table>;`.
*/
@ExperimentalEvscApi
suspend fun <T> DatabaseClient<*>.selectTableExpression(
Expand All @@ -59,6 +62,7 @@ suspend inline fun <T, R> DatabaseClient<*>.executeSingleColumnSelectQuery(
): RowSet<R> =
selectSingleColumn(columnSet, column, buildQuery, mapper)

// TODO adapt to the new SELECT DSL or deprecate
suspend fun <T> DatabaseClient<*>.selectSingleColumn(
columnSet: ColumnSet, column: Column<T>, buildQuery: FieldSet.() -> Query
): RowSet<T> =
Expand All @@ -70,6 +74,7 @@ suspend fun <T> DatabaseClient<*>.executeSingleColumnSelectQuery(
): RowSet<T> =
selectSingleColumn(columnSet, column, buildQuery)

// TODO adapt to the new SELECT DSL or deprecate
suspend fun <T : Comparable<T>> DatabaseClient<*>.selectSingleEntityIdColumn(
columnSet: ColumnSet, column: Column<EntityID<T>>, buildQuery: FieldSet.() -> Query
): RowSet<T> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.huanshankeji.exposed.deleteWhereStatement
import com.huanshankeji.exposedvertxsqlclient.DatabaseClient
import com.huanshankeji.exposedvertxsqlclient.ExperimentalEvscApi
import com.huanshankeji.exposedvertxsqlclient.sql.*
import com.huanshankeji.exposedvertxsqlclient.toExposedResultRow
import com.huanshankeji.vertx.sqlclient.datamapping.RowDataQueryMapper
import io.vertx.sqlclient.RowSet
import org.jetbrains.exposed.sql.*
Expand All @@ -23,7 +22,7 @@ suspend fun <Data : Any> DatabaseClient<*>.executeQuery(
query: Query,
dataQueryMapper: DataQueryMapper<Data>
): RowSet<Data> =
executeWithMapping(query) { row -> dataQueryMapper.resultRowToData(row.toExposedResultRow(query)) }
executeWithMapping(query) { row -> dataQueryMapper.resultRowToData(row.toExposedResultRowWithTransaction(query)) }

@ExperimentalEvscApi
suspend fun <Data : Any> DatabaseClient<*>.executeVertxSqlClientRowQuery(
Expand Down

0 comments on commit 82c5077

Please sign in to comment.