mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 05:25:50 +01:00
(refs #1297)Allow to configure HikariCP in database.conf
This commit is contained in:
@@ -52,6 +52,13 @@ object Database {
|
|||||||
config.setJdbcUrl(DatabaseConfig.url)
|
config.setJdbcUrl(DatabaseConfig.url)
|
||||||
config.setUsername(DatabaseConfig.user)
|
config.setUsername(DatabaseConfig.user)
|
||||||
config.setPassword(DatabaseConfig.password)
|
config.setPassword(DatabaseConfig.password)
|
||||||
|
config.setAutoCommit(false)
|
||||||
|
DatabaseConfig.connectionTimeout.foreach(config.setConnectionTimeout)
|
||||||
|
DatabaseConfig.idleTimeout.foreach(config.setIdleTimeout)
|
||||||
|
DatabaseConfig.maxLifetime.foreach(config.setMaxLifetime)
|
||||||
|
DatabaseConfig.minimumIdle.foreach(config.setMinimumIdle)
|
||||||
|
DatabaseConfig.maximumPoolSize.foreach(config.setMaximumPoolSize)
|
||||||
|
|
||||||
logger.debug("load database connection pool")
|
logger.debug("load database connection pool")
|
||||||
new HikariDataSource(config)
|
new HikariDataSource(config)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ object DatabaseConfig {
|
|||||||
| url = "jdbc:h2:${DatabaseHome};MVCC=true"
|
| url = "jdbc:h2:${DatabaseHome};MVCC=true"
|
||||||
| user = "sa"
|
| user = "sa"
|
||||||
| password = "sa"
|
| password = "sa"
|
||||||
|
|# connectionTimeout = 30000
|
||||||
|
|# idleTimeout = 600000
|
||||||
|
|# maxLifetime = 1800000
|
||||||
|
|# minimumIdle = 10
|
||||||
|
|# maximumPoolSize = 10
|
||||||
|}
|
|}
|
||||||
|""".stripMargin, "UTF-8")
|
|""".stripMargin, "UTF-8")
|
||||||
}
|
}
|
||||||
@@ -34,6 +39,15 @@ object DatabaseConfig {
|
|||||||
lazy val jdbcDriver : String = DatabaseType(url).jdbcDriver
|
lazy val jdbcDriver : String = DatabaseType(url).jdbcDriver
|
||||||
lazy val slickDriver : slick.driver.JdbcProfile = DatabaseType(url).slickDriver
|
lazy val slickDriver : slick.driver.JdbcProfile = DatabaseType(url).slickDriver
|
||||||
lazy val liquiDriver : AbstractJdbcDatabase = DatabaseType(url).liquiDriver
|
lazy val liquiDriver : AbstractJdbcDatabase = DatabaseType(url).liquiDriver
|
||||||
|
lazy val connectionTimeout : Option[Long] = getOptionValue("db.connectionTimeout", config.getLong)
|
||||||
|
lazy val idleTimeout : Option[Long] = getOptionValue("db.idleTimeout" , config.getLong)
|
||||||
|
lazy val maxLifetime : Option[Long] = getOptionValue("db.maxLifetime" , config.getLong)
|
||||||
|
lazy val minimumIdle : Option[Int] = getOptionValue("db.minimumIdle" , config.getInt)
|
||||||
|
lazy val maximumPoolSize : Option[Int] = getOptionValue("db.maximumPoolSize" , config.getInt)
|
||||||
|
|
||||||
|
private def getOptionValue[T](path: String, f: String => T): Option[T] = {
|
||||||
|
if(config.hasPath(path)) None else Some(f(path))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user