本文整理汇总了Scala中java.sql.Timestamp类的典型用法代码示例。如果您正苦于以下问题:Scala Timestamp类的具体用法?Scala Timestamp怎么用?Scala Timestamp使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Timestamp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: User
//设置package包名称以及导入依赖的类
package services.users
import java.io.File
import java.nio.charset.Charset
import java.sql.Timestamp
import org.apache.commons.io.FileUtils
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.types.{StringType, StructField, StructType}
import org.apache.spark.streaming.StreamingContext
import services.events.EventStream
import services.Util
case class User(userId: String, testFinishTime: Timestamp, nickname: String, gender: String)
object User {
val DELIMITER = ','
val USER_FEED = "/Users/mahesh/data/affinitas/feeds/users/"
val USER_DATA = "/Users/mahesh/data/affinitas/tables/users/"
var ssc: StreamingContext = null
var sql: SparkSession = null
lazy val usersFeedDF = sql.read
.format("com.databricks.spark.csv")
.option("header", false)
.schema(StructType(Array(
StructField("userId", StringType, true),
StructField("nickname", StringType, true),
StructField("gender", StringType, true)
)
)).load(User.USER_FEED)
//EventStream.testFinishStream.print()
lazy val usersMap = usersFeedDF.rdd.map(record => (record.getString(0), (record.getString(1), record.getString(2))))
def initialize(sscO: StreamingContext, sqlO: SparkSession) = {
ssc = sscO
sql = sqlO
new File(USER_FEED).mkdirs()
new File(USER_DATA).mkdirs()
EventStream.testFinishStream.foreachRDD( {
rdd => {
val testFinishMap = rdd.map(record => (record.userId, record.timestamp))
val userData = testFinishMap.join(usersMap)
.map(record => Array(record._1, record._2._1, record._2._2._1, record._2._2._2))
.collect()
Util.writeCsvToDir(userData, DELIMITER.toString, USER_DATA)
}
})
}
}
示例2: Person
//设置package包名称以及导入依赖的类
package onextent.oemap.server.entities
import java.sql.Timestamp
import java.util.UUID
trait IdAble { val id: UUID; val created: Timestamp }
case class Person(id: UUID,
name: String,
description: String,
created: Timestamp)
extends IdAble
case class OeMap(id: UUID,
ownerId: UUID,
title: String,
created: Timestamp,
description: String)
extends IdAble
case class Membership(id: UUID,
personId: UUID,
mapId: UUID,
description: String,
created: Timestamp,
role: String)
extends IdAble
case class Location(id: UUID,
personId: UUID,
mapId: UUID,
description: String,
created: Timestamp,
lat: Double,
lon: Double)
extends IdAble
示例3: 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))
}
示例4: DriverStorage
//设置package包名称以及导入依赖的类
package storages
import models.DriverModel
import java.sql.Timestamp
import slick.lifted.TableQuery
import database.MyPostgresDriver.api._
class DriverStorage(tag: Tag) extends Table[DriverModel](tag, "drivers") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name")
def vehicle = column[String]("vehicle")
def createdAt = column[Timestamp]("created_at")
def updatedAt = column[Timestamp]("updated_at")
override def * =
(id, name, vehicle, createdAt, updatedAt) <> (DriverModel.tupled, DriverModel.unapply)
}
object DriverStorage {
val tableQuery = TableQuery[DriverStorage]
}
示例5: DriverLocationStorage
//设置package包名称以及导入依赖的类
package storages
import models.DriverLocationModel
import java.sql.Timestamp
import com.vividsolutions.jts.geom.Geometry
import slick.lifted.{ProvenShape, TableQuery}
import database.MyPostgresDriver.api._
import database.MyPostgresDriver.api.PgArrayPositionedResult
class DriverLocationStorage(tag: Tag) extends Table[DriverLocationModel](tag, "drivers_location") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def driverId = column[Long]("driver_id")
def location = column[Geometry]("location")
def createdAt = column[Timestamp]("created_at")
def updatedAt = column[Timestamp]("updated_at")
override def * =
(id, driverId, location, createdAt, updatedAt) <> (DriverLocationModel.tupled, DriverLocationModel.unapply)
}
object DriverLocationStorage {
val tableQuery = TableQuery[DriverLocationStorage]
}
示例6: timestampToDateTime
//设置package包名称以及导入依赖的类
package converters
import play.api.libs.json.Json._
import play.api.libs.json._
import org.joda.time.DateTime
import java.sql.Timestamp
import countries.Country
import users.User
import users.{Role => UserRole}
trait JsonFormatters {
def timestampToDateTime(t: Timestamp): DateTime = new DateTime(t.getTime)
def dateTimeToTimestamp(dt: DateTime): Timestamp = new Timestamp(dt.getMillis)
implicit val timestampFormat = new Format[Timestamp] {
def writes(t: Timestamp): JsValue = toJson(timestampToDateTime(t))
def reads(json: JsValue): JsResult[Timestamp] = fromJson[DateTime](json).map(dateTimeToTimestamp)
}
implicit val enumFormat = new Format[UserRole.Value] {
def writes(enum: UserRole.Value): JsValue = toJson(enum.toString)
def reads(json: JsValue): JsResult[UserRole.Value] = fromJson[String](json).map(json => UserRole.withName(json.toString))
}
implicit val jsonCountryFormat = Json.format[Country]
implicit val jsonUserWriter = new Writes[User] {
def writes(user: User) = {
defaultObjectCreator(user)
}
def writesForCreate(user: User) = {
defaultObjectCreator(user) + ("authToken" -> Json.toJson(user.authToken))
}
def writesForAuth(user: User) = {
Json.obj("authToken" -> Json.toJson(user.authToken))
}
def defaultObjectCreator(user: User) = {
Json.obj("id" -> user.id,
"email" -> user.email,
"firstName" -> user.firstName,
"lastName" -> user.lastName,
"role" -> user.role,
"cityId" -> user.cityId,
"phone" -> user.phone,
"createdAt" -> user.createdAt)
}
}
}
示例7: User
//设置package包名称以及导入依赖的类
package users
import slick.driver.MySQLDriver.api._
import utils.TimeUtil
import java.sql.Timestamp
import users.{Role => UserRole}
import converters.JsonFormatters
import models.{Errorable, QueryCommands, Defaultable, RichTable}
case class User(id: Long = 0, email: String, firstName: String, lastName: String,
role: UserRole.Value, password: String, authToken: String,
authTokenCreatedAt: Timestamp, cityId: Long, phone: String,
createdAt: Timestamp = TimeUtil.now) extends Errorable with Defaultable
object User extends JsonFormatters
class UsersTable(tag: Tag) extends RichTable[User](tag, "Users") {
def email = column[String]("email")
def firstName = column[String]("firstName")
def lastName = column[String]("lastName")
def role = column[UserRole.Value]("role")
def password = column[String]("password")
def authToken = column[String]("authToken")
def authTokenCreatedAt = column[Timestamp]("authTokenCreatedAt")
def cityId = column[Long]("cityId")
def phone = column[String]("phone")
def createdAt = column[Timestamp]("createdAt")
def * =
(id, email, firstName, lastName, role, password, authToken, authTokenCreatedAt, cityId, phone, createdAt) <> ((User.apply _).tupled, User.unapply)
implicit val userEnumMapper = MappedColumnType.base[UserRole.Value, String](
enum => enum.toString,
string => UserRole.withName(string)
)
}
object Users extends QueryCommands[UsersTable, User] {
override val tableName = "Users"
override val records = TableQuery[UsersTable]
override def create(record: User) = {
import com.github.t3hnar.bcrypt._
super.create(record.copy(password = record.password.bcrypt))
}
def findByEmail(email: String) = dbConfig.db.run(records.filter(_.email === email).result.headOption)
def findByAuthToken(token: String) = dbConfig.db.run(records.filter(_.authToken === token).result.headOption)
}
示例8: BroadcastRow
//设置package包名称以及导入依赖的类
package com.esri
import java.sql.Timestamp
case class BroadcastRow(
objectID: Long,
heading: Int,
baseDateTime: Timestamp,
status: Int,
voyageID: String,
MMSI: String,
lon: Double,
lat: Double
)
object BroadcastRow {
def apply(
broadcast: Broadcast,
lon: Double,
lat: Double
): BroadcastRow = new BroadcastRow(
broadcast.objectID,
broadcast.heading,
broadcast.baseDateTime,
broadcast.status,
broadcast.voyageID,
broadcast.MMSI,
lon, lat)
}
示例9: Broadcast
//设置package包名称以及导入依赖的类
package com.esri
import java.sql.Timestamp
case class Broadcast(
objectID: Long,
SOG: Int,
COG: Int,
heading: Int,
ROT: Int,
baseDateTime: Timestamp,
status: Int,
voyageID: String,
MMSI: String,
receiverType: String,
receiverID: String,
wkt: String
)
示例10: PhraseDao
//设置package包名称以及导入依赖的类
package daos
import java.sql.Timestamp
import java.util.Date
import javax.inject.Inject
import models.Phrase
import org.joda.time.DateTime
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.HasDatabaseConfigProvider
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import slick.driver.JdbcProfile
import scala.concurrent.Future
class PhraseDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) extends HasDatabaseConfigProvider[JdbcProfile] {
import driver.api._
private val Phrases = TableQuery[PhrasesTable]
def all(): Future[Seq[Phrase]] = db.run(Phrases.result)
def insert(phrase: Phrase): Future[Unit] = db.run(Phrases += phrase).map { _ => () }
def insert(phrases: Seq[Phrase]): Future[Unit] = db.run(this.Phrases ++= phrases).map(_ => ())
def findById(id: Long): Future[Option[Phrase]] = db.run(Phrases.filter(_.id === id).result.headOption)
def update(id: Long, phrase: Phrase): Future[Unit] = {
val phraseToUpdate: Phrase = phrase.copy(Some(id))
db.run(Phrases.filter(_.id === id).update(phraseToUpdate)).map(_ => ())
}
def delete(id: Long): Future[Unit] =
db.run(Phrases.filter(_.id === id).delete).map(_ => ())
def count(): Future[Int] = {
// this should be changed to db.run(Phrases.length.result) when https://github.com/slick/slick/issues/1237 is fixed
db.run(Phrases.map(_.id).length.result)
}
private class PhrasesTable(tag: Tag) extends Table[Phrase](tag, "PHRASE") {
//implicit val dateColumnType = MappedColumnType.base[Date, Long](d => d.getTime, d => new Date(d))
implicit def dateTime = MappedColumnType.base[DateTime, Timestamp] (
dt => new Timestamp(dt.getMillis), ts => new DateTime(ts.getTime)
)
def id = column[Long]("ID", O.PrimaryKey, O.AutoInc)
def spanish = column[String]("SPANISH")
def english = column[String]("ENGLISH")
def createdAt = column[DateTime]("CREATED_AT")
def * = (id.?, spanish, english, createdAt) <> (Phrase.tupled, Phrase.unapply _)
}
}
示例11: GroupedRow
//设置package包名称以及导入依赖的类
package unus.blocking
import java.sql.Timestamp
import java.time.{LocalDate, LocalDateTime}
import unus.db.{BlockedRow, Patient}
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.Dataset
case class GroupedRow(
key: String,
id: String,
patient: Patient
)
trait BlockerBase extends Serializable {
val name: String
def filterPair(p1: Patient, p2: Patient): Boolean = true
def filter(r: Patient): Boolean
def group(r: Patient): String = {""}
def groupSplit(r: Patient): Seq[String] = {
group(r) :: Nil
}
def anon1(r: Patient) = {
groupSplit(r).map(rr => (rr, r))
}
def anon2(kv: (String , Iterable[Patient])) = {
kv._2.map(r => GroupedRow(kv._1, r.enterpriseId, r))
}
def apply(rdd: RDD[Patient]): RDD[BlockedRow] = {
val now = Timestamp.valueOf(LocalDateTime.now())
val grouped = rdd.filter(r => filter(r))
.flatMap(anon1)
.groupByKey()
.flatMap(anon2).keyBy(_.key).cache()
grouped.join(grouped)
.filter(r => r._2._1.id < r._2._2.id)
.filter(r => filterPair(r._2._1.patient, r._2._2.patient))
.map(r=> BlockedRow(name, r._2._1.id,r._2._2.id, now))
.distinct()
}
}
示例12: BlockerCacher
//设置package包名称以及导入依赖的类
package unus.stage
import java.sql.Timestamp
import java.time.LocalDateTime
import unus.blocking.BlockerBase
import unus.db.{BlockedRow, Patient, Repository}
import unus.helpers.Cacher
import org.apache.spark.rdd.RDD
class BlockerCacher(repo: Repository, patients: RDD[Patient], val blocker: BlockerBase) extends Cacher[BlockedRow] {
override protected val name: String = "blocker/" + blocker.name
override protected def build(): RDD[BlockedRow] = {
blocker(patients).cache()
}
override protected def save(data: RDD[BlockedRow]): Unit = {
super.save(data)
repo.createBlocker(
unus.db.Blocker(
blocker.name,
data.count(),
Timestamp.valueOf(LocalDateTime.now())
)
)
}
}
示例13: Model
//设置package包名称以及导入依赖的类
package unus.db
import java.sql.Timestamp
case class Model(
model: String,
ts: Timestamp,
features: String,
blockers: List[String],
batches: List[String],
trees: Int,
depth: Int,
f1: Double,
precision: Double,
recall: Double
)
示例14: Repository
//设置package包名称以及导入依赖的类
package unus.db
import java.sql.Timestamp
import java.time.LocalDateTime
class Repository(private val db: DbContext) {
import db._
private implicit val timestampEncoder = MappedEncoding[LocalDateTime, Timestamp](Timestamp.valueOf)
private implicit val timestampDecoder = MappedEncoding[Timestamp, LocalDateTime](_.toLocalDateTime)
def patientsExist(): Boolean = {
run(
quote {
query[Patient].size
}
) > 0
}
def getModel(model: String): Model = {
run(
quote {
query[Model].filter(_.model == lift(model)).take(1)
}
).head
}
def createBlocker(blocker: Blocker): Long = {
run(
quote {
query[Blocker].insert(lift(blocker))
}
)
}
}
示例15: Episodio
//设置package包名称以及导入依赖的类
package migrana.modelo
import org.joda.time.DateTime
import java.sql.Timestamp
import slick.driver.MySQLDriver.api._
case class Episodio(
Id: Long,
IdPaciente:Long,
FechayHoraEpisodio: DateTime,
NivelDolor: String,
LocalizacionDolor:String,
PromedioHorasSuenoSemanal:Long,
MedicamentoTomaActualmente: String,
BebidasqueCausaronMigrana: String,
AlimentosqueCausaronMigrana: String,
ActividadFisicaqueCausaronMigrana: String)
class EpisodioTable(tag: Tag) extends Table[Episodio](tag, "episodio") {
implicit val jdateColumnType = MappedColumnType.base[ DateTime, Timestamp ]( dt => new Timestamp( dt.getMillis ), ts => new DateTime( ts.getTime ) )
def Id = column[Long]("id", O.PrimaryKey,O.AutoInc)
def IdPaciente = column[Long]("IdPaciente")
def FechayHoraEpisodio = column[ DateTime ]( "FechayHoraEpisodio")
def NivelDolor = column[String]("NivelDolor")
def LocalizacionDolor = column[String]("LocalizacionDolor")
def PromedioHorasSuenoSemanal = column[Long]("PromedioHorasSuenoSemanal")
def MedicamentoTomaActualmente = column[String]("MedicamentoTomaActualmente")
def BebidasqueCausaronMigrana = column[String]("BebidasqueCausaronMigrana")
def AlimentosqueCausaronMigrana = column[String]("AlimentosqueCausaronMigrana")
def ActividadFisicaqueCausaronMigrana = column[String]("ActividadFisicaqueCausaronMigrana")
override def * = (Id, IdPaciente, FechayHoraEpisodio, NivelDolor, LocalizacionDolor,PromedioHorasSuenoSemanal,
MedicamentoTomaActualmente,BebidasqueCausaronMigrana,AlimentosqueCausaronMigrana,ActividadFisicaqueCausaronMigrana ) <>(Episodio.tupled, Episodio.unapply _)
}