当前位置: 首页>>代码示例>>Scala>>正文


Scala HikariConfig类代码示例

本文整理汇总了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()
} 
开发者ID:andrewobukhov,项目名称:smart-house,代码行数:18,代码来源:DatabaseService.scala

示例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()
} 
开发者ID:hwshim0810,项目名称:scalable-board,代码行数:18,代码来源:DatabaseService.scala

示例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()
} 
开发者ID:poguez,项目名称:class_orchestration_api,代码行数:36,代码来源:DatabaseService.scala

示例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)
  }
} 
开发者ID:mkorman9,项目名称:districron,代码行数:47,代码来源:SystemConfiguration.scala

示例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
} 
开发者ID:citrum,项目名称:webby,代码行数:40,代码来源:HikariCPPlugin.scala


注:本文中的com.zaxxer.hikari.HikariConfig类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。