• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala HikariDataSource类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中com.zaxxer.hikari.HikariDataSource的典型用法代码示例。如果您正苦于以下问题:Scala HikariDataSource类的具体用法?Scala HikariDataSource怎么用?Scala HikariDataSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了HikariDataSource类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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


示例4: 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


示例5: DB

//设置package包名称以及导入依赖的类
package com.onur.moviedb.db

import javax.sql.DataSource

import com.onur.moviedb.conf.SiteConfig
import com.onur.moviedb.metric.Metrics
import com.zaxxer.hikari.HikariDataSource
import doobie.imports._

import scalaz.concurrent.Task

object DB {
  lazy val dataSource: DataSource = {
    val ds = new HikariDataSource
    val dbConf = SiteConfig.dbConf
    val urlBuilder = new StringBuilder("jdbc:postgresql://")
    urlBuilder.append(dbConf.host)
      .append(":")
      .append(dbConf.port).append("/")
      .append(dbConf.name)
      .append(dbConf.urlOptions)
      .append("&prepStmtCacheSize=250")
      .append("&prepStmtCacheSqlLimit=2048")

    ds.setJdbcUrl(urlBuilder.toString)
    ds.setUsername(dbConf.username)
    ds.setPassword(dbConf.password)
    ds.setConnectionTimeout(dbConf.connectionTimeout)
    ds.setIdleTimeout(dbConf.idleTimeout)
    ds.setMaximumPoolSize(dbConf.connectionCount)
    ds.setMaxLifetime(dbConf.maxLifetime)
    ds.setPoolName(dbConf.poolName)
    ds.setRegisterMbeans(true)
    ds.setValidationTimeout(dbConf.validationTimeout)
    ds.setMetricRegistry(Metrics.metricRegistry)
    ds.setHealthCheckRegistry(Metrics.healthCheckRegistry)
    ds.addHealthCheckProperty("expected99thPercentileMs", "100")
    sys.addShutdownHook(ds.close())
    ds
  }

  lazy val xa = DataSourceTransactor[Task].apply(DB.dataSource)
} 
开发者ID:onurzdg,项目名称:movie-db,代码行数:44,代码来源:DB.scala


示例6: 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.HikariDataSource类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Observable类代码示例发布时间:2022-05-23
下一篇:
Scala Merge类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap