Skip to content

Commit ff796c4

Browse files
Improve JDBC Url parsing (#366)
Co-authored-by: Kazuhiro Sera <seratch@gmail.com>
1 parent 2431d53 commit ff796c4

File tree

6 files changed

+48
-19
lines changed

6 files changed

+48
-19
lines changed

core/src/main/scala/scalikejdbc/async/internal/JasyncConfiguration.scala

+20-16
Original file line numberDiff line numberDiff line change
@@ -16,45 +16,49 @@
1616
package scalikejdbc.async.internal
1717

1818
import com.github.jasync.sql.db.Configuration
19-
import scalikejdbc.JDBCUrl
2019
import scalikejdbc.async.AsyncConnectionSettings
2120

2221
/**
2322
* Configuration attribute
2423
*/
2524
private[scalikejdbc] trait JasyncConfiguration {
2625

26+
@deprecated("Will be removed in the future", "0.16.0")
2727
val defaultConfiguration = new Configuration("")
2828

29+
protected def parseUrl(url: String): Configuration
30+
2931
private[scalikejdbc] def configuration(
3032
url: String,
3133
user: String,
3234
password: String,
3335
connectionSettings: AsyncConnectionSettings
3436
) = {
35-
val jdbcUrl = JDBCUrl(url)
36-
new Configuration(
37+
val baseConf = parseUrl(url)
38+
baseConf.copy(
3739
user,
38-
jdbcUrl.host,
39-
jdbcUrl.port,
40+
baseConf.getHost,
41+
baseConf.getPort,
4042
password,
41-
jdbcUrl.database,
42-
connectionSettings.ssl.getOrElse(defaultConfiguration.getSsl),
43-
connectionSettings.charset.getOrElse(defaultConfiguration.getCharset),
43+
baseConf.getDatabase,
44+
connectionSettings.ssl.getOrElse(baseConf.getSsl),
45+
connectionSettings.charset.getOrElse(baseConf.getCharset),
4446
connectionSettings.maximumMessageSize.getOrElse(
45-
defaultConfiguration.getMaximumMessageSize
47+
baseConf.getMaximumMessageSize
4648
),
47-
connectionSettings.allocator.getOrElse(defaultConfiguration.getAllocator),
49+
connectionSettings.allocator.getOrElse(baseConf.getAllocator),
4850
connectionSettings.connectTimeout
4951
.map(_.toMillis.toInt)
50-
.getOrElse(defaultConfiguration.getConnectionTimeout),
52+
.getOrElse(baseConf.getConnectionTimeout),
5153
connectionSettings.queryTimeout
5254
.map(x => java.time.Duration.ofMillis(x.toMillis))
53-
.getOrElse(defaultConfiguration.getQueryTimeout),
54-
defaultConfiguration.getApplicationName,
55-
defaultConfiguration.getInterceptors,
56-
defaultConfiguration.getEventLoopGroup,
57-
defaultConfiguration.getExecutionContext
55+
.getOrElse(baseConf.getQueryTimeout),
56+
baseConf.getApplicationName,
57+
baseConf.getInterceptors,
58+
baseConf.getEventLoopGroup,
59+
baseConf.getExecutionContext,
60+
baseConf.getCurrentSchema,
61+
baseConf.getSocketPath,
5862
)
5963
}
6064

core/src/main/scala/scalikejdbc/async/internal/mysql/MySQLConnectionPoolImpl.scala

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import scalikejdbc._, async._, internal._
1919
import com.github.jasync.sql.db.Configuration
2020
import com.github.jasync.sql.db.mysql.MySQLConnection
2121
import com.github.jasync.sql.db.mysql.pool.MySQLConnectionFactory
22+
import com.github.jasync.sql.db.mysql.util.URLParser
23+
24+
import java.nio.charset.StandardCharsets
2225

2326
/**
2427
* MySQL Connection Pool
@@ -42,6 +45,9 @@ private[scalikejdbc] class MySQLConnectionPoolImpl(
4245
settings
4346
) {
4447

48+
override protected def parseUrl(url: String): Configuration =
49+
URLParser.INSTANCE.parse(url, StandardCharsets.UTF_8)
50+
4551
override def borrow(): AsyncConnection = new PoolableAsyncConnection(pool)
4652
with MySQLConnectionImpl
4753

core/src/main/scala/scalikejdbc/async/internal/mysql/SingleAsyncMySQLConnection.scala

+7
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
*/
1616
package scalikejdbc.async.internal.mysql
1717

18+
import com.github.jasync.sql.db.Configuration
19+
import com.github.jasync.sql.db.mysql.util.URLParser
1820
import scalikejdbc.async._, internal._
1921

22+
import java.nio.charset.StandardCharsets
23+
2024
/**
2125
* MySQL Single Connection
2226
*/
@@ -29,6 +33,9 @@ private[scalikejdbc] case class SingleAsyncMySQLConnection(
2933
with MySQLConnectionImpl
3034
with JasyncConfiguration {
3135

36+
override protected def parseUrl(url: String): Configuration =
37+
URLParser.INSTANCE.parse(url, StandardCharsets.UTF_8)
38+
3239
private[scalikejdbc] val underlying = {
3340
new com.github.jasync.sql.db.mysql.MySQLConnection(
3441
configuration(url, user, password, connectionSettings)

core/src/main/scala/scalikejdbc/async/internal/postgresql/PostgreSQLConnectionPoolImpl.scala

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import scalikejdbc._, async._, internal._
1919
import com.github.jasync.sql.db.Configuration
2020
import com.github.jasync.sql.db.postgresql.PostgreSQLConnection
2121
import com.github.jasync.sql.db.postgresql.pool.PostgreSQLConnectionFactory
22+
import com.github.jasync.sql.db.postgresql.util.URLParser
23+
24+
import java.nio.charset.StandardCharsets
2225

2326
/**
2427
* PostgreSQL Connection Pool
@@ -42,6 +45,9 @@ private[scalikejdbc] class PostgreSQLConnectionPoolImpl(
4245
settings
4346
) {
4447

48+
override protected def parseUrl(url: String): Configuration =
49+
URLParser.INSTANCE.parse(url, StandardCharsets.UTF_8)
50+
4551
override def borrow(): AsyncConnection = new PoolableAsyncConnection(pool)
4652
with PostgreSQLConnectionImpl
4753

core/src/main/scala/scalikejdbc/async/internal/postgresql/SingleAsyncPostgreSQLConnection.scala

+7
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
*/
1616
package scalikejdbc.async.internal.postgresql
1717

18+
import com.github.jasync.sql.db.Configuration
19+
import com.github.jasync.sql.db.postgresql.util.URLParser
1820
import scalikejdbc.async._, internal._
1921

22+
import java.nio.charset.StandardCharsets
23+
2024
/**
2125
* PostgreSQL Single Connection
2226
*/
@@ -29,6 +33,9 @@ private[scalikejdbc] case class SingleAsyncPostgreSQLConnection(
2933
with PostgreSQLConnectionImpl
3034
with JasyncConfiguration {
3135

36+
override protected def parseUrl(url: String): Configuration =
37+
URLParser.INSTANCE.parse(url, StandardCharsets.UTF_8)
38+
3239
private[scalikejdbc] val underlying = {
3340
new com.github.jasync.sql.db.postgresql.PostgreSQLConnection(
3441
configuration(url, user, password, connectionSettings)

core/src/test/scala/unit/DBSettings.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ trait DBSettings extends ForAllTestContainer { self: Suite =>
1919
)
2020
override val container = MultipleContainers(mysql, postgres)
2121

22-
// https://github.com/testcontainers/testcontainers-java/issues/2544
23-
protected[this] final def mysqlJdbcUrl = mysql.jdbcUrl.split('?').head
24-
protected[this] final def postgresJdbcUrl = postgres.jdbcUrl.split('?').head
22+
protected[this] final def mysqlJdbcUrl = mysql.jdbcUrl
23+
protected[this] final def postgresJdbcUrl = postgres.jdbcUrl
2524

2625
protected[this] final val asyncConnectionPoolSettings
2726
: AsyncConnectionPoolSettings = AsyncConnectionPoolSettings()

0 commit comments

Comments
 (0)