Skip to content

Commit

Permalink
Merge pull request #11601 from benwaffle/hikari-sql-exception-override
Browse files Browse the repository at this point in the history
Add exceptionOverrideClassName Hikari config setting
  • Loading branch information
mkurz committed Jan 11, 2023
2 parents b2e6e66 + a215073 commit 71f6975
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions persistence/play-jdbc/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ play {
# If non null, sets the transaction isolation level
transactionIsolation = null

# The user-supplied SQLExceptionOverride class name.
exceptionOverrideClassName = null

# The validation timeout to use
validationTimeout = 5 seconds

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ private[db] class HikariCPConfig private (
config.get[Option[String]]("connectionInitSql").foreach(hikariConfig.setConnectionInitSql)
config.get[Option[String]]("catalog").foreach(hikariConfig.setCatalog)
config.get[Option[String]]("transactionIsolation").foreach(hikariConfig.setTransactionIsolation)
config.get[Option[String]]("exceptionOverrideClassName").foreach(hikariConfig.setExceptionOverrideClassName)
hikariConfig.setValidationTimeout(config.get[FiniteDuration]("validationTimeout").toMillis)
hikariConfig.setLeakDetectionThreshold(toMillis(config.get[Duration]("leakDetectionThreshold")))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,21 @@ class HikariCPConfigSpec extends Specification {
val config = from("hikaricp.leakDetectionThreshold" -> "3 seconds")
new HikariCPConfig("foo", dbConfig, config).toHikariConfig.getLeakDetectionThreshold must beEqualTo(3000L)
}

"exceptionOverrideClassName" in new Configs {
val className = classOf[MyTestExceptionOverride].getName

val config = from("hikaricp.exceptionOverrideClassName" -> className)
new HikariCPConfig("foo", dbConfig, config).toHikariConfig.getExceptionOverrideClassName must beEqualTo(
className
)
}
}
}
}

class MyTestExceptionOverride extends com.zaxxer.hikari.SQLExceptionOverride {}

trait Configs extends Scope {
val dbConfig: DatabaseConfig = DatabaseConfig(Some("org.h2.Driver"), Some("jdbc:h2:mem:"), None, None, None)
val reference: Configuration = Configuration.reference.get[Configuration]("play.db.prototype")
Expand Down

0 comments on commit 71f6975

Please sign in to comment.