Skip to content

Commit 0dd4087

Browse files
committed
Refactor ConnectionPoolImpl to enhance atomicity and thread safety. Replace manual mutex locks with atomic utilities (AtomicInt, AtomicBoolean) for core state management.
1 parent 2c96c17 commit 0dd4087

File tree

11 files changed

+1145
-589
lines changed

11 files changed

+1145
-589
lines changed

sqlx4k/src/commonMain/kotlin/io/github/smyrgeorge/sqlx4k/ConnectionPool.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ interface ConnectionPool {
6464
// Set the maximum lifetime of individual connections.
6565
val maxLifetime: Duration? = null,
6666
) {
67+
init {
68+
require(minConnections == null || minConnections > 0) { "minConnections must be greater than 0" }
69+
require(maxConnections > 0) { "maxConnections must be greater than 0" }
70+
require(idleTimeout == null || idleTimeout.isPositive()) { "idleTimeout must be greater than 0" }
71+
require(maxLifetime == null || maxLifetime.isPositive()) { "maxLifetime must be greater than 0" }
72+
require(acquireTimeout == null || acquireTimeout.isPositive()) { "acquireTimeout must be greater than 0" }
73+
require(minConnections == null || maxConnections >= minConnections) { "maxConnections must be greater than or equal to minConnections" }
74+
require(idleTimeout == null || maxLifetime == null || idleTimeout <= maxLifetime) { "idleTimeout must be less than or equal to maxLifetime" }
75+
}
76+
6777
@Suppress("unused")
6878
class Builder {
6979
private var minConnections: Int? = null

0 commit comments

Comments
 (0)