Skip to content

Commit

Permalink
Eva pimp loosen query executer param types (#132)
Browse files Browse the repository at this point in the history
* EVA-PIMP loosen query executer param types

* gradle

* explain errors clearer
  • Loading branch information
Rattenkrieg committed Jun 5, 2024
1 parent 14c7522 commit 5c759d8
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/CI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import java.lang.Boolean.parseBoolean
object Ci {

private const val SNAPSHOT_BASE = "0.7.0"
private const val RELEASE_VERSION = "0.6.9"
private const val RELEASE_VERSION = "0.6.10"
private val githubSha = System.getenv("GITHUB_SHA") ?: "latest"

val publishRelease = System.getProperty("release", "true").let(::parseBoolean)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import kotlin.coroutines.coroutineContext
class JdbcTransactionManager(
primaryProvider: ConnectionProvider<Connection>,
replicaProvider: ConnectionProvider<Connection>,
private val blockingJdbcContext: CoroutineDispatcher = Dispatchers.IO
private val blockingJdbcContext: CoroutineDispatcher = Dispatchers.IO,
) : TransactionManager<Connection>(primaryProvider, replicaProvider) {

override suspend fun <R> withConnection(block: suspend (Connection) -> R): R {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.razz.eva.persistence.jdbc.executor

import com.razz.eva.persistence.ConnectionMode.REQUIRE_EXISTING
import com.razz.eva.persistence.TransactionManager
import com.razz.eva.persistence.executor.QueryExecutor
import com.razz.eva.persistence.jdbc.JdbcTransactionManager
import org.jooq.DMLQuery
import org.jooq.DSLContext
import org.jooq.Param
Expand All @@ -14,9 +14,10 @@ import org.jooq.Table
import org.jooq.exception.DataAccessException
import org.jooq.impl.DSL
import org.postgresql.util.PSQLException
import java.sql.Connection

class JdbcQueryExecutor(
private val transactionManager: JdbcTransactionManager,
private val transactionManager: TransactionManager<Connection>,
) : QueryExecutor {

override suspend fun <R : Record> executeSelect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class JdbcTransactionManagerSpec : BehaviorSpec({

Then("Exception thrown") {
val ex = shouldThrow<IllegalStateException> { call() }
ex.message shouldBe "Required existing connection"
ex.message shouldBe "Required existing connection but no existing connection was found"
}

And("Pools were not called") {
Expand Down Expand Up @@ -86,7 +86,7 @@ class JdbcTransactionManagerSpec : BehaviorSpec({
connection.autoCommit = true
connection.close()
}
ex.message shouldBe "Required new connection"
ex.message shouldBe "Required new connection but existing connection was found"
}

And("Pool connections was acquired and returned, connection was rolled back") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class JdbcQueryExecutorSpec : BehaviorSpec({

Then("Exception thrown saying there is context missing") {
val ex = shouldThrow<IllegalStateException> { storeRun() }
ex.message shouldBe "Required existing connection"
ex.message shouldBe "Required existing connection but no existing connection was found"
}
And("Connection was not acquired and was not released on delegate provider") {
coVerify(exactly = 0) {
Expand Down Expand Up @@ -98,7 +98,7 @@ class JdbcQueryExecutorSpec : BehaviorSpec({

Then("Exception thrown saying there is context missing") {
val ex = shouldThrow<IllegalStateException> { storeRun() }
ex.message shouldBe "Required existing connection"
ex.message shouldBe "Required existing connection but no existing connection was found"
}
And("Connection was not acquired and was not released on delegate provider") {
coVerify(exactly = 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.razz.eva.persistence.vertx.executor

import com.razz.eva.persistence.ConnectionMode.REQUIRE_EXISTING
import com.razz.eva.persistence.TransactionManager
import com.razz.eva.persistence.executor.QueryExecutor
import com.razz.eva.persistence.vertx.VertxTransactionManager
import io.vertx.core.json.Json
import io.vertx.kotlin.coroutines.coAwait
import io.vertx.pgclient.PgConnection
Expand All @@ -29,7 +29,7 @@ import java.time.LocalDateTime
import java.time.ZoneOffset.UTC

class VertxQueryExecutor(
private val transactionManager: VertxTransactionManager
private val transactionManager: TransactionManager<PgConnection>,
) : QueryExecutor {

override suspend fun <R : Record> executeSelect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class VertxTransactionManagerSpec : BehaviorSpec({

Then("Exception thrown") {
val ex = shouldThrow<IllegalStateException> { call() }
ex.message shouldBe "Required existing connection"
ex.message shouldBe "Required existing connection but no existing connection was found"
}

And("Pools were not called") {
Expand Down Expand Up @@ -84,7 +84,7 @@ class VertxTransactionManagerSpec : BehaviorSpec({
txn.rollback()
connection.close()
}
ex.message shouldBe "Required new connection"
ex.message shouldBe "Required new connection but existing connection was found"
}

And("Pool connections was acquired and returned, txn was rolled back") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class VertxQueryExecutorSpec : BehaviorSpec({

Then("Exception thrown saying there is context missing") {
val ex = shouldThrow<IllegalStateException> { storeRun() }
ex.message shouldBe "Required existing connection"
ex.message shouldBe "Required existing connection but no existing connection was found"
}
And("Connection was not acquired and was not released on delegate provider") {
coVerify(exactly = 0) {
Expand Down Expand Up @@ -136,7 +136,7 @@ class VertxQueryExecutorSpec : BehaviorSpec({

Then("Exception thrown saying there is context missing") {
val ex = shouldThrow<IllegalStateException> { storeRun() }
ex.message shouldBe "Required existing connection"
ex.message shouldBe "Required existing connection but no existing connection was found"
}
And("Connection was not acquired and was not released on delegate provider") {
coVerify(exactly = 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlin.coroutines.coroutineContext

abstract class TransactionManager<C>(
private val primaryProvider: ConnectionProvider<C>,
private val replicaProvider: ConnectionProvider<C>
private val replicaProvider: ConnectionProvider<C>,
) {

open suspend fun <R> withConnection(block: suspend (C) -> R): R {
Expand Down Expand Up @@ -37,9 +37,9 @@ abstract class TransactionManager<C>(
mode: ConnectionMode,
block: suspend (C) -> R
): R {
checkCtxConnectionMode(mode)
return when (val existingConn = ctxConnection()) {
null -> {
check(mode == REQUIRE_NEW) { "Required existing connection but no existing connection was found" }
var newConn: C? = null
try {
newConn = primaryProvider.acquire()
Expand All @@ -63,7 +63,10 @@ abstract class TransactionManager<C>(
// because we are in recursive call to inTransaction
// and this connection was created upwards the callstack during first call to inTransaction
// and will be handled there
else -> block(existingConn)
else -> {
check(mode == REQUIRE_EXISTING) { "Required new connection but existing connection was found" }
block(existingConn)
}
}
}

Expand All @@ -74,13 +77,6 @@ abstract class TransactionManager<C>(
replicaProvider
}

private suspend fun checkCtxConnectionMode(mode: ConnectionMode) {
when (mode) {
REQUIRE_NEW -> check(ctxConnection() == null) { "Required new connection" }
REQUIRE_EXISTING -> check(ctxConnection() != null) { "Required existing connection" }
}
}

abstract fun supportsPipelining(): Boolean

protected abstract fun wrapConnection(newConn: C): ConnectionWrapper<C>
Expand Down

0 comments on commit 5c759d8

Please sign in to comment.