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

scalikejdbc.SettingsProvider.scala Maven / Gradle / Ivy

The newest version!
package scalikejdbc

import scalikejdbc.SettingsProvider._

/**
 * @note does not use case class for binary-compatibility keepability
 */
final class SettingsProvider private (
  private[scalikejdbc] val loggingSQLErrors: Endo[Boolean],
  private[scalikejdbc] val loggingConnections: Endo[Boolean],
  private[scalikejdbc] val sqlFormatter: Endo[SQLFormatterSettings],
  private[scalikejdbc] val driverNamesToChooseColumnNameForAutoGeneratedKeyRetrieval: Endo[
    collection.Seq[String]
  ],
  private[scalikejdbc] val queryCompletionListener: Endo[
    GlobalSettings.QueryCompletionListener
  ],
  private[scalikejdbc] val queryFailureListener: Endo[
    GlobalSettings.QueryFailureListener
  ],
  private[scalikejdbc] val taggedQueryCompletionListener: Endo[
    GlobalSettings.TaggedQueryCompletionListener
  ],
  private[scalikejdbc] val taggedQueryFailureListener: Endo[
    GlobalSettings.TaggedQueryFailureListener
  ],
  private[scalikejdbc] val jtaDataSourceCompatible: Endo[Boolean],
  private[scalikejdbc] val loggingSQLAndTime: Endo[LoggingSQLAndTimeSettings],
  private[scalikejdbc] val nameBindingSQLValidator: Endo[
    NameBindingSQLValidatorSettings
  ]
) {

  def copy(
    loggingSQLErrors: Endo[Boolean] = this.loggingSQLErrors,
    loggingConnections: Endo[Boolean] = this.loggingConnections,
    sqlFormatter: Endo[SQLFormatterSettings] = this.sqlFormatter,
    driverNamesToChooseColumnNameForAutoGeneratedKeyRetrieval: Endo[
      collection.Seq[String]
    ] = this.driverNamesToChooseColumnNameForAutoGeneratedKeyRetrieval,
    queryCompletionListener: Endo[GlobalSettings.QueryCompletionListener] =
      this.queryCompletionListener,
    queryFailureListener: Endo[GlobalSettings.QueryFailureListener] =
      this.queryFailureListener,
    taggedQueryCompletionListener: Endo[
      GlobalSettings.TaggedQueryCompletionListener
    ] = this.taggedQueryCompletionListener,
    taggedQueryFailureListener: Endo[
      GlobalSettings.TaggedQueryFailureListener
    ] = this.taggedQueryFailureListener,
    jtaDataSourceCompatible: Endo[Boolean] = this.jtaDataSourceCompatible,
    loggingSQLAndTime: Endo[LoggingSQLAndTimeSettings] = this.loggingSQLAndTime,
    nameBindingSQLValidator: Endo[NameBindingSQLValidatorSettings] =
      this.nameBindingSQLValidator
  ): SettingsProvider =
    new SettingsProvider(
      loggingSQLErrors = loggingSQLErrors,
      loggingConnections = loggingConnections,
      sqlFormatter = sqlFormatter,
      driverNamesToChooseColumnNameForAutoGeneratedKeyRetrieval =
        driverNamesToChooseColumnNameForAutoGeneratedKeyRetrieval,
      queryCompletionListener = queryCompletionListener,
      queryFailureListener = queryFailureListener,
      taggedQueryCompletionListener = taggedQueryCompletionListener,
      taggedQueryFailureListener = taggedQueryFailureListener,
      jtaDataSourceCompatible = jtaDataSourceCompatible,
      loggingSQLAndTime = loggingSQLAndTime,
      nameBindingSQLValidator = nameBindingSQLValidator
    )

  def merge(other: SettingsProvider): SettingsProvider = {
    // avoid create new instance if default instance
    if (this eq SettingsProvider.default) {
      other
    } else if (other eq SettingsProvider.default) {
      this
    } else {
      new SettingsProvider(
        loggingSQLErrors = this.loggingSQLErrors andThen other.loggingSQLErrors,
        loggingConnections =
          this.loggingConnections andThen other.loggingConnections,
        sqlFormatter = this.sqlFormatter andThen other.sqlFormatter,
        driverNamesToChooseColumnNameForAutoGeneratedKeyRetrieval =
          this.driverNamesToChooseColumnNameForAutoGeneratedKeyRetrieval andThen other.driverNamesToChooseColumnNameForAutoGeneratedKeyRetrieval,
        queryCompletionListener =
          this.queryCompletionListener andThen other.queryCompletionListener,
        queryFailureListener =
          this.queryFailureListener andThen other.queryFailureListener,
        taggedQueryCompletionListener =
          this.taggedQueryCompletionListener andThen other.taggedQueryCompletionListener,
        taggedQueryFailureListener =
          this.taggedQueryFailureListener andThen other.taggedQueryFailureListener,
        jtaDataSourceCompatible =
          this.jtaDataSourceCompatible andThen other.jtaDataSourceCompatible,
        loggingSQLAndTime =
          this.loggingSQLAndTime andThen other.loggingSQLAndTime,
        nameBindingSQLValidator =
          this.nameBindingSQLValidator andThen other.nameBindingSQLValidator
      )
    }
  }
}

object SettingsProvider {
  type Endo[A] = A => A

  private[this] val _endoId: Endo[Any] = a => a
  private[this] def endoId[A]: Endo[A] = _endoId.asInstanceOf[Endo[A]]

  val default: SettingsProvider = new SettingsProvider(
    loggingSQLErrors = endoId,
    loggingConnections = endoId,
    sqlFormatter = endoId,
    driverNamesToChooseColumnNameForAutoGeneratedKeyRetrieval = endoId,
    queryCompletionListener = endoId,
    queryFailureListener = endoId,
    taggedQueryCompletionListener = endoId,
    taggedQueryFailureListener = endoId,
    jtaDataSourceCompatible = endoId,
    loggingSQLAndTime = endoId,
    nameBindingSQLValidator = endoId
  )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy