• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Types类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中java.sql.Types的典型用法代码示例。如果您正苦于以下问题:Scala Types类的具体用法?Scala Types怎么用?Scala Types使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Types类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: genericEncoder

//设置package包名称以及导入依赖的类
package io.gustavoamigo.quill.pgsql.encoding.range.numeric

import java.sql.{Types, PreparedStatement}

import io.getquill.source.jdbc.JdbcSource

import scala.collection.immutable.NumericRange

trait Encoders {
  this: JdbcSource[_, _] =>

  private def genericEncoder[T](valueToString: (T => String)): Encoder[T] = {
    new Encoder[T] {
      override def apply(index: Int, value: T, row: PreparedStatement) = {
        val sqlLiteral = valueToString(value)
        row.setObject(index + 1, sqlLiteral, Types.OTHER)
        row
      }
    }
  }

  private def tuple[T](t: (T, T)) = s"[${t._1}, ${t._2}]"

  private def range[T](r: NumericRange[T]) = s"[${r.head}, ${r.last}]"

  implicit val intTupleEncoder: Encoder[(Int, Int)] = genericEncoder(tuple)
  implicit val intRangeEncoder: Encoder[NumericRange[Int]] = genericEncoder(range)
  implicit val bigIntTupleEncoder: Encoder[(BigInt, BigInt)] = genericEncoder(tuple)
  implicit val bigIntRangeEncoder: Encoder[NumericRange[BigInt]] = genericEncoder(range)
  implicit val longTupleEncoder: Encoder[(Long, Long)] = genericEncoder(tuple)
  implicit val longRangeEncoder: Encoder[NumericRange[Long]] = genericEncoder(range)
  implicit val doubleTupleEncoder: Encoder[(Double, Double)] = genericEncoder(tuple)
  implicit val bigDecimalTupleEncoder: Encoder[(BigDecimal, BigDecimal)] = genericEncoder(tuple)
  implicit val bigDecimalRangeEncoder: Encoder[NumericRange[BigDecimal]] = genericEncoder(range)
} 
开发者ID:gustavoamigo,项目名称:quill-pgsql,代码行数:36,代码来源:Encoders.scala


示例2: genericEncoder

//设置package包名称以及导入依赖的类
package io.gustavoamigo.quill.pgsql.encoding.range.datetime

import java.sql.{PreparedStatement, Types}
import java.time.{LocalDate, ZonedDateTime, LocalDateTime}
import java.util.Date

import io.getquill.source.jdbc.JdbcSource

trait Encoders {
  this: JdbcSource[_, _] =>

  import Formatters._

  private def genericEncoder[T](valueToString: (T => String)): Encoder[T] = {
    new Encoder[T] {
      override def apply(index: Int, value: T, row: PreparedStatement) = {
        val sqlLiteral = valueToString(value)
        row.setObject(index + 1, sqlLiteral, Types.OTHER)
        row
      }
    }
  }

  private def tuple[T](t: (T, T))(valToStr: T => String) = s"[${valToStr(t._1)}, ${valToStr(t._2)}]"

  implicit val dateTupleEncoder: Encoder[(Date, Date)] = genericEncoder(tuple(_)(formatDate))
  implicit val localDateTimeTupleEncoder: Encoder[(LocalDateTime, LocalDateTime)] =
    genericEncoder(tuple(_)(formatLocalDateTime))
  implicit val zonedDateTimeTupleEncoder: Encoder[(ZonedDateTime, ZonedDateTime)] =
    genericEncoder(tuple(_)(formatZonedDateTime))
  implicit val dateTimeTupleEncoder: Encoder[(LocalDate, LocalDate)] =
    genericEncoder(t => s"[${formatLocalDate(t._1)}, ${formatLocalDate(t._2)})")
} 
开发者ID:gustavoamigo,项目名称:quill-pgsql,代码行数:34,代码来源:Encoders.scala


示例3: genericEncoder

//设置package包名称以及导入依赖的类
package io.gustavoamigo.quill.pgsql.encoding.jodatime

import java.sql.{Types, PreparedStatement}

import io.getquill.source.jdbc.JdbcSource
import org.joda.time._

trait Encoders {
  this: JdbcSource[_, _] =>

  import Formatters._

  private def genericEncoder[T](valueToString: (T => String) = (r: T) => r.toString): Encoder[T] =
    new Encoder[T] {
      override def apply(index: Int, value: T, row: PreparedStatement) = {
        val sqlLiteral = s"'${valueToString(value)}'"
        row.setObject(index + 1, sqlLiteral, Types.OTHER)
        row
      }
    }

  implicit val jodaDateTimeEncoder: Encoder[DateTime] = genericEncoder(_.toString(jodaTzDateTimeFormatter))
  implicit val jodaLocalDateEncoder: Encoder[LocalDate] = genericEncoder(_.toString(jodaDateFormatter))
  implicit val jodaLocalTimeEncoder: Encoder[LocalTime] = genericEncoder(_.toString(jodaTimeFormatter))
} 
开发者ID:gustavoamigo,项目名称:quill-pgsql,代码行数:26,代码来源:Encoders.scala


示例4: genericEncoder

//设置package包名称以及导入依赖的类
package io.gustavoamigo.quill.pgsql.encoding.json.play

import java.sql.{Types, PreparedStatement}
import io.getquill.source.jdbc.JdbcSource

trait JsonEncoder {
  this: JdbcSource[_, _] =>

  import play.api.libs.json._

  private def genericEncoder[T](valueToString: (T => String) = (r: T) => r.toString): Encoder[T] =
    new Encoder[T] {
      override def apply(index: Int, value: T, row: PreparedStatement) = {
        row.setObject(index + 1, valueToString(value), Types.OTHER)
        row
      }
    }

  implicit val jsonEncoder: Encoder[JsValue] = genericEncoder(Json.stringify)
} 
开发者ID:gustavoamigo,项目名称:quill-pgsql,代码行数:21,代码来源:JsonEncoder.scala


示例5: genericEncoder

//设置package包名称以及导入依赖的类
package io.gustavoamigo.quill.pgsql.encoding.datetime

import java.sql.{PreparedStatement, Timestamp, Types}
import java.time._
import io.getquill.source.jdbc.JdbcSource

trait Encoders {
  this: JdbcSource[_, _] =>

  import Formatters._

  private def genericEncoder[T](valueToString: (T => String) = (r: T) => r.toString): Encoder[T] =
    new Encoder[T] {
      override def apply(index: Int, value: T, row: PreparedStatement) = {
        val sqlLiteral = s"'${valueToString(value)}'"
        row.setObject(index + 1, sqlLiteral, Types.OTHER)
        row
      }
    }

  private def encoder[T](f: PreparedStatement => (Int, T) => Unit): Encoder[T] =
    new Encoder[T] {
      override def apply(index: Int, value: T, row: PreparedStatement) = {
        f(row)(index + 1, value)
        row
      }
    }

  implicit val localDateTimeEncoder: Encoder[LocalDateTime] = encoder { (row: PreparedStatement) =>
    (index: Int, d: LocalDateTime) => row.setObject(index, Timestamp.valueOf(d), Types.TIMESTAMP)
  }
  implicit val zonedDateTimeEncoder: Encoder[ZonedDateTime] = genericEncoder(_.format(bpTzDateTimeFormatter))
  implicit val localDateEncoder: Encoder[LocalDate] = genericEncoder(_.format(bpDateFormatter))
  implicit val localTimeEncoder: Encoder[LocalTime] = genericEncoder(_.format(bpTimeFormatter))
  implicit val offsetTimeEncoder: Encoder[OffsetTime] = genericEncoder(_.format(bpTzTimeFormatter))

} 
开发者ID:gustavoamigo,项目名称:quill-pgsql,代码行数:38,代码来源:Encoders.scala


示例6: OracleJdbcDialect

//设置package包名称以及导入依赖的类
package io.eels.component.jdbc.dialect

import java.sql.{ResultSetMetaData, Types}

import com.sksamuel.exts.Logging
import io.eels.component.jdbc.JdbcReaderConfig
import io.eels.schema.{BooleanType, ByteType, DataType, DecimalType, DoubleType, Field, FloatType, IntType, LongType, Precision, Scale, ShortType}

class OracleJdbcDialect extends GenericJdbcDialect with Logging {

  private val config = JdbcReaderConfig()

  // oracle uses its own timestamp types
  override def sanitize(value: Any): Any = {
    if (value == null) null
    else value match {
      case other if other.getClass.getName == "oracle.sql.TIMESTAMP" =>
        value.getClass.getDeclaredMethod("timestampValue").invoke(value)
      case other => super.sanitize(other)
    }
  }

  override def toJdbcType(field: Field): String = field.dataType match {
    // https://docs.oracle.com/cd/E19501-01/819-3659/gcmaz/
    case BooleanType => "NUMBER(1)"
    case IntType(_) => "NUMBER(10)"
    case LongType(_) => "NUMBER(19)"
    case FloatType => "NUMBER(19, 4)"
    case DoubleType => "NUMBER(19, 4)"
    case ByteType(_) => "NUMBER(3)"
    case ShortType(_) => "NUMBER(5)"
    case _ => super.toJdbcType(field)
  }

  private def decimalType(column: Int, metadata: ResultSetMetaData): DataType = {
    val precision = metadata.getPrecision(column)
    val scale = metadata.getScale(column)
    require(scale <= precision, "Scale must be less than precision")

    (precision, scale) match {
      // Jdbc returns precision == 0 and scale == -127 for NUMBER fields which have no precision/scale
      // http://stackoverflow.com/questions/593197/what-is-the-default-precision-and-scale-for-a-number-in-oracle
      case (0, _) => DecimalType(config.defaultPrecision, config.defaultScale)
      case (_, -127L) => DecimalType(config.defaultPrecision, config.defaultScale)
      case (x, 0) if x > 9 => LongType.Signed
      case (_, 0) => IntType.Signed
      case (_, _) => DecimalType(Precision(precision), Scale(scale))
    }
  }

  override def fromJdbcType(column: Int, metadata: ResultSetMetaData): DataType = {
    metadata.getColumnType(column) match {
      case Types.DECIMAL | Types.NUMERIC => decimalType(column, metadata)
      case _ => super.fromJdbcType(column, metadata)
    }
  }
} 
开发者ID:51zero,项目名称:eel-sdk,代码行数:58,代码来源:OracleJdbcDialect.scala



注:本文中的java.sql.Types类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala CSRFFilter类代码示例发布时间:2022-05-23
下一篇:
Scala NioServerSocketChannel类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap