All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sksamuel.cohort.dbcp.manager.kt Maven / Gradle / Ivy

The newest version!
package com.sksamuel.cohort.dbcp

import com.sksamuel.cohort.db.DataSourceInfo
import com.sksamuel.cohort.db.DataSourceManager
import org.apache.commons.dbcp2.BasicDataSource

class ApacheDBCPDataSourceManager(private val ds: BasicDataSource) : DataSourceManager {

  override fun name(): String = ds.jmxName

  override fun evict(): Result = runCatching {
    ds.evict()
    true
  }

  override fun info(): Result {
    return runCatching {
      DataSourceInfo(
        name = ds.jmxName,
        activeConnections = ds.numActive,
        idleConnections = ds.numIdle,
        totalConnections = ds.numActive + ds.numIdle,
        threadsAwaitingConnection = -1,
        connectionTimeoutMs = ds.loginTimeout.toLong(),
        idleTimeoutMs = ds.minEvictableIdleTimeMillis,
        maxLifetimeMs = ds.maxConnLifetimeMillis,
        leakDetectionThreshold = -1,
        minIdle = ds.minIdle,
        maxOpenPreparedStatements = ds.maxOpenPreparedStatements,
        testOnReturn = ds.testOnReturn,
        testOnBorrow = ds.testOnBorrow,
        testOnCreate = ds.testOnCreate,
        maximumPoolSize = ds.maxTotal,
        maximumIdle = ds.maxIdle,
        validationTimeoutMs = ds.validationQueryTimeout.toLong(),
      )
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy