scalikejdbc-async icon indicating copy to clipboard operation
scalikejdbc-async copied to clipboard

Support additional jasync configuration parameters

Open sbmpost opened this issue 3 years ago • 1 comments

First of all, thank you for this library. I have a suggestion for supporting additional jasync config parameters.

Maybe AsyncConnectionSettings.scala can be updated like so:

case class AsyncConnectionPoolSettings(
    maxPoolSize: Int = 8,
    maxQueueSize: Int = 8,
    maxIdleMillis: Long = 1000L,

    // these 5 parameters are new
    validationInterval: Long = 5000L,
    createTimeout: Long = 5000L,
    testTimeout: Long = 5000L,
    queryTimeout: Option[Long] = None,
    maxObjectTtl: Option[Long] = None,

    connectionSettings: AsyncConnectionSettings = AsyncConnectionSettings()
)

 case class AsyncConnectionSettings(
    ssl: Option[SSLConfiguration] = None,
    charset: Option[Charset] = None,
    maximumMessageSize: Option[Int] = None,
    allocator: Option[ByteBufAllocator] = None,
    connectTimeout: Option[Duration] = None,

    // testTimeout seems out of place and
    // probably belongs in the poolsettings
    testTimeout: Option[Duration] = None,

    queryTimeout: Option[Duration] = None
)

And the following lines can be added to AsyncConnectionPoolCommonImpl.scala like so:

  builder.setConnectionValidationInterval(settings.validationInterval)
  builder.setConnectionCreateTimeout(settings.createTimeout)
  builder.setConnectionTestTimeout(settings.testTimeout)
  settings.queryTimeout match {
    case Some(timeout) =>
      builder.setQueryTimeout(timeout)
    case None =>
      builder.setQueryTimeout(null)
  }
  settings.maxObjectTtl match {
    case Some(ttl) =>
      builder.setMaxConnectionTtl(ttl)
    case None =>
      builder.setMaxConnectionTtl(null)
  }

sbmpost avatar Apr 04 '22 19:04 sbmpost

I figured that I might as well create a PR for this. See #281

sbmpost avatar Apr 05 '22 10:04 sbmpost