<commit_before>package com.novocode.squery.session

import java.sql.{Blob, Clob, Date, Time, Timestamp}

sealed trait TypeMapper[T] {
  def zero: T
  def sqlType: Int
  def setValue(v: T, p: PositionedParameters): Unit
  def setOption(v: Option[T], p: PositionedParameters): Unit
  def nextValue(r: PositionedResult): T
  final def nextValueOrElse(d: =>T, r: PositionedResult) = { val v = nextValue(r); if(r.rs wasNull) d else v }
  final def nextOption(r: PositionedResult): Option[T] = { val v = nextValue(r); if(r.rs wasNull) None else Some(v) }
  def valueToSQLLiteral(value: T): String = value.toString
}

trait BaseTypeMapper[T] extends TypeMapper[T]

trait OptionTypeMapper[T] extends TypeMapper[Option[T]]

object TypeMapper {
  implicit object BooleanTypeMapper extends BaseTypeMapper[Boolean] {
    def zero = false
    def sqlType = java.sql.Types.BOOLEAN
    def setValue(v: Boolean, p: PositionedParameters) = p.setBoolean(v)
    def setOption(v: Option[Boolean], p: PositionedParameters) = p.setBooleanOption(v)
    def nextValue(r: PositionedResult) = r.nextBoolean
  }

  implicit object BlobTypeMapper extends BaseTypeMapper[Blob] {
    def zero = null
    def sqlType = java.sql.Types.BLOB
    def setValue(v: Blob, p: PositionedParameters) = p.setBlob(v)
    def setOption(v: Option[Blob], p: PositionedParameters) = p.setBlobOption(v)
    def nextValue(r: PositionedResult) = r.nextBlob
  }

  implicit object ByteTypeMapper extends BaseTypeMapper[Byte] {
    def zero = 0
    def sqlType = java.sql.Types.TINYINT
    def setValue(v: Byte, p: PositionedParameters) = p.setByte(v)
    def setOption(v: Option[Byte], p: PositionedParameters) = p.setByteOption(v)
    def nextValue(r: PositionedResult) = r.nextByte
  }

  implicit object ClobTypeMapper extends BaseTypeMapper[Clob] {
    def zero = null
    def sqlType = java.sql.Types.CLOB
    def setValue(v: Clob, p: PositionedParameters) = p.setClob(v)
    def setOption(v: Option[Clob], p: PositionedParameters) = p.setClobOption(v)
    def nextValue(r: PositionedResult) = r.nextClob
  }

  implicit object DateTypeMapper extends BaseTypeMapper[Date] {
    def zero = new Date(70, 0, 1)
    def sqlType = java.sql.Types.DATE
    def setValue(v: Date, p: PositionedParameters) = p.setDate(v)
    def setOption(v: Option[Date], p: PositionedParameters) = p.setDateOption(v)
    def nextValue(r: PositionedResult) = r.nextDate
  }

  implicit object DoubleTypeMapper extends BaseTypeMapper[Double] {
    def zero = 0
    def sqlType = java.sql.Types.DOUBLE
    def setValue(v: Double, p: PositionedParameters) = p.setDouble(v)
    def setOption(v: Option[Double], p: PositionedParameters) = p.setDoubleOption(v)
    def nextValue(r: PositionedResult) = r.nextDouble
  }

  implicit object FloatTypeMapper extends BaseTypeMapper[Float] {
    def zero = 0
    def sqlType = java.sql.Types.FLOAT
    def setValue(v: Float, p: PositionedParameters) = p.setFloat(v)
    def setOption(v: Option[Float], p: PositionedParameters) = p.setFloatOption(v)
    def nextValue(r: PositionedResult) = r.nextFloat
  }

  implicit object IntTypeMapper extends BaseTypeMapper[Int] {
    def zero = 0
    def sqlType = java.sql.Types.INTEGER
    def setValue(v: Int, p: PositionedParameters) = p.setInt(v)
    def setOption(v: Option[Int], p: PositionedParameters) = p.setIntOption(v)
    def nextValue(r: PositionedResult) = r.nextInt
  }

  implicit object LongTypeMapper extends BaseTypeMapper[Long] {
    def zero = 0
    def sqlType = java.sql.Types.INTEGER
    def setValue(v: Long, p: PositionedParameters) = p.setLong(v)
    def setOption(v: Option[Long], p: PositionedParameters) = p.setLongOption(v)
    def nextValue(r: PositionedResult) = r.nextLong
  }

  implicit object StringTypeMapper extends BaseTypeMapper[String] {
    def zero = ""
    def sqlType = java.sql.Types.VARCHAR
    def setValue(v: String, p: PositionedParameters) = p.setString(v)
    def setOption(v: Option[String], p: PositionedParameters) = p.setStringOption(v)<commit_msg>Changed mapping for Scala type Long from SQL type INTEGER to BIGINT<commit_after>package com.novocode.squery.session

import java.sql.{Blob, Clob, Date, Time, Timestamp}

sealed trait TypeMapper[T] {
  def zero: T
  def sqlType: Int
  def setValue(v: T, p: PositionedParameters): Unit
  def setOption(v: Option[T], p: PositionedParameters): Unit
  def nextValue(r: PositionedResult): T
  final def nextValueOrElse(d: =>T, r: PositionedResult) = { val v = nextValue(r); if(r.rs wasNull) d else v }
  final def nextOption(r: PositionedResult): Option[T] = { val v = nextValue(r); if(r.rs wasNull) None else Some(v) }
  def valueToSQLLiteral(value: T): String = value.toString
}

trait BaseTypeMapper[T] extends TypeMapper[T]

trait OptionTypeMapper[T] extends TypeMapper[Option[T]]

object TypeMapper {
  implicit object BooleanTypeMapper extends BaseTypeMapper[Boolean] {
    def zero = false
    def sqlType = java.sql.Types.BOOLEAN
    def setValue(v: Boolean, p: PositionedParameters) = p.setBoolean(v)
    def setOption(v: Option[Boolean], p: PositionedParameters) = p.setBooleanOption(v)
    def nextValue(r: PositionedResult) = r.nextBoolean
  }

  implicit object BlobTypeMapper extends BaseTypeMapper[Blob] {
    def zero = null
    def sqlType = java.sql.Types.BLOB
    def setValue(v: Blob, p: PositionedParameters) = p.setBlob(v)
    def setOption(v: Option[Blob], p: PositionedParameters) = p.setBlobOption(v)
    def nextValue(r: PositionedResult) = r.nextBlob
  }

  implicit object ByteTypeMapper extends BaseTypeMapper[Byte] {
    def zero = 0
    def sqlType = java.sql.Types.TINYINT
    def setValue(v: Byte, p: PositionedParameters) = p.setByte(v)
    def setOption(v: Option[Byte], p: PositionedParameters) = p.setByteOption(v)
    def nextValue(r: PositionedResult) = r.nextByte
  }

  implicit object ClobTypeMapper extends BaseTypeMapper[Clob] {
    def zero = null
    def sqlType = java.sql.Types.CLOB
    def setValue(v: Clob, p: PositionedParameters) = p.setClob(v)
    def setOption(v: Option[Clob], p: PositionedParameters) = p.setClobOption(v)
    def nextValue(r: PositionedResult) = r.nextClob
  }

  implicit object DateTypeMapper extends BaseTypeMapper[Date] {
    def zero = new Date(70, 0, 1)
    def sqlType = java.sql.Types.DATE
    def setValue(v: Date, p: PositionedParameters) = p.setDate(v)
    def setOption(v: Option[Date], p: PositionedParameters) = p.setDateOption(v)
    def nextValue(r: PositionedResult) = r.nextDate
  }

  implicit object DoubleTypeMapper extends BaseTypeMapper[Double] {
    def zero = 0
    def sqlType = java.sql.Types.DOUBLE
    def setValue(v: Double, p: PositionedParameters) = p.setDouble(v)
    def setOption(v: Option[Double], p: PositionedParameters) = p.setDoubleOption(v)
    def nextValue(r: PositionedResult) = r.nextDouble
  }

  implicit object FloatTypeMapper extends BaseTypeMapper[Float] {
    def zero = 0
    def sqlType = java.sql.Types.FLOAT
    def setValue(v: Float, p: PositionedParameters) = p.setFloat(v)
    def setOption(v: Option[Float], p: PositionedParameters) = p.setFloatOption(v)
    def nextValue(r: PositionedResult) = r.nextFloat
  }

  implicit object IntTypeMapper extends BaseTypeMapper[Int] {
    def zero = 0
    def sqlType = java.sql.Types.INTEGER
    def setValue(v: Int, p: PositionedParameters) = p.setInt(v)
    def setOption(v: Option[Int], p: PositionedParameters) = p.setIntOption(v)
    def nextValue(r: PositionedResult) = r.nextInt
  }

  implicit object LongTypeMapper extends BaseTypeMapper[Long] {
    def zero = 0
    def sqlType = java.sql.Types.BIGINT
    def setValue(v: Long, p: PositionedParameters) = p.setLong(v)
    def setOption(v: Option[Long], p: PositionedParameters) = p.setLongOption(v)
    def nextValue(r: PositionedResult) = r.nextLong
  }

  implicit object StringTypeMapper extends BaseTypeMapper[String] {
    def zero = ""
    def sqlType = java.sql.Types.VARCHAR
    def setValue(v: String, p: PositionedParameters) = p.setString(v)
    def setOption(v: Option[String], p: PositionedParameters) = p.setStringOption(v)
{'fraction_non_alphanumeric': 0.10647517642689117, 'fraction_numerical': 0.002228550204283769, 'mean_word_length': 4.314473684210526, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5105439', 'n_tokens_mistral': 2678, 'n_tokens_neox': 2665, 'n_words': 696}