本文整理汇总了Scala中com.zaxxer.hikari.HikariConfig类的典型用法代码示例。如果您正苦于以下问题:Scala HikariConfig类的具体用法?Scala HikariConfig怎么用?Scala HikariConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HikariConfig类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: DatabaseService
//设置package包名称以及导入依赖的类
package smarthouse.restapi.utils
import com.zaxxer.hikari.{HikariConfig, HikariDataSource}
class DatabaseService(jdbcUrl: String, dbUser: String, dbPassword: String) {
private val hikariConfig = new HikariConfig()
hikariConfig.setJdbcUrl(jdbcUrl)
hikariConfig.setUsername(dbUser)
hikariConfig.setPassword(dbPassword)
private val dataSource = new HikariDataSource(hikariConfig)
val driver = slick.driver.PostgresDriver
import driver.api._
val db = Database.forDataSource(dataSource)
db.createSession()
}
示例2: DatabaseService
//设置package包名称以及导入依赖的类
package app.board.utils
import com.zaxxer.hikari.{HikariConfig, HikariDataSource}
class DatabaseService(jdbcUrl: String, dbUser: String, dbPassword: String) {
private val hikariConfig = new HikariConfig()
hikariConfig.setJdbcUrl(jdbcUrl)
hikariConfig.setUsername(dbUser)
hikariConfig.setPassword(dbPassword)
private val dataSource = new HikariDataSource(hikariConfig)
val driver = slick.driver.PostgresDriver
import driver.api._
val db = Database.forDataSource(dataSource)
db.createSession()
}
示例3: pgjson
//设置package包名称以及导入依赖的类
package com.noedominguez.class_orchestration.restapi.utils
import com.github.tminglei.slickpg._
import com.github.tminglei.slickpg.PgDateSupportJoda
import com.github.tminglei.slickpg.PgJsonSupport
import com.github.tminglei.slickpg.json.PgJsonExtensions
import com.zaxxer.hikari.{HikariConfig, HikariDataSource}
trait MyPostgresDriver extends ExPostgresProfile
with PgDateSupportJoda
with PgJsonSupport
with PgJsonExtensions{
def pgjson = "jsonb"
override val api = MyAPI
object MyAPI extends API with DateTimeImplicits with JsonImplicits
}
object MyPostgresDriver extends MyPostgresDriver
class DatabaseService(jdbcUrl: String, dbUser: String, dbPassword: String) {
private val hikariConfig = new HikariConfig()
hikariConfig.setJdbcUrl(jdbcUrl)
hikariConfig.setUsername(dbUser)
hikariConfig.setPassword(dbPassword)
private val dataSource = new HikariDataSource(hikariConfig)
val driver = MyPostgresDriver
import driver.api._
val db = Database.forDataSource(dataSource, Some(10))
db.createSession()
}
示例4: SystemConfiguration
//设置package包名称以及导入依赖的类
package com.github.mkorman9.districron
import javax.sql.DataSource
import akka.actor.ActorSystem
import com.typesafe.config.{Config, ConfigFactory}
import com.zaxxer.hikari.{HikariConfig, HikariDataSource}
import org.springframework.context.annotation.{Bean, ComponentScan, Configuration}
import org.springframework.scheduling.annotation.EnableScheduling
import scala.slick.driver.MySQLDriver.simple._
@Configuration
@ComponentScan
@EnableScheduling
class SystemConfiguration {
final val ActorSystemName = "DistricronSystem"
@Bean
def config: Config = {
ConfigFactory.load()
}
@Bean
def actorSystem(config: Config): ActorSystem = {
ActorSystem(ActorSystemName, config)
}
@Bean
def dataSource(config: Config): DataSource = {
val hikariConfig = new HikariConfig()
hikariConfig.setDriverClassName(config.getString("datasource.jdbc-driver-class"))
hikariConfig.setJdbcUrl(config.getString("datasource.jdbc-url"))
hikariConfig.setUsername(config.getString("datasource.jdbc-username"))
hikariConfig.setPassword(config.getString("datasource.jdbc-password"))
hikariConfig.setMaxLifetime(config.getInt("datasource.poll-max-lifetime"))
hikariConfig.setLeakDetectionThreshold(config.getInt("datasource.poll-leak-detection-threshold"))
new HikariDataSource(hikariConfig)
}
@Bean
def databaseConnection(dataSource: DataSource): Database = {
Database.forDataSource(dataSource)
}
}
示例5: HikariCPPlugin
//设置package包名称以及导入依赖的类
package webby.api.db
import java.sql.{Connection, SQLException}
import com.zaxxer.hikari.{HikariConfig, HikariDataSource}
import webby.api.App
import scala.util.Try
abstract class HikariCPPlugin extends DbPlugin {
private var ds: HikariDataSource = _
override def onStart() {
val config = getConfig
ds = new HikariDataSource(config)
if (isTestConnection) {
try {
ds.getConnection.close()
} catch {
case e: SQLException =>
throw new RuntimeException("Plugin: " + getClass.getSimpleName + ", unable to connect to DB", e)
}
}
}
override def onStop() {
Try(ds.close()).get
}
override def getConnection: Connection = ds.getConnection
override def shutdownPool() = ds.close()
def isTestConnection = App.profile.isJenkinsOrProd
// ------------------------------- Abstract methods -------------------------------
def getConfig: HikariConfig
}