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

scalikejdbc.orm.basic.AutoSessionFeature.scala Maven / Gradle / Ivy

The newest version!
package scalikejdbc.orm.basic

// Don't change this import
import scalikejdbc._

/**
 * Provides AutoSession for this mapper.
 */
trait AutoSessionFeature {
  self: SQLSyntaxSupport[?] with ConnectionPoolFeature =>

  /**
   * AutoSession definition.
   */
  override def autoSession: DBSession = {
    connectionPoolName match {
      case ConnectionPool.DEFAULT_NAME =>
        Option(ThreadLocalDB.load()).map { threadLocalDB =>
          if (threadLocalDB.isTxNotActive) AutoSession
          else if (threadLocalDB.isTxAlreadyStarted)
            threadLocalDB.withinTxSession()
          else threadLocalDB.autoCommitSession()
        } getOrElse AutoSession
      case _ => NamedAutoSession(connectionPoolName)
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy