本文整理汇总了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)
}
示例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)})")
}
示例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))
}
示例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)
}
示例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))
}
示例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)
}
}
}