Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.39"
- libraryDependencies += "com.typesafe.scala-logging" % "scala-logging_2.11" % "3.5.0"
- libraryDependencies += "joda-time" % "joda-time" % "2.3"
- package com.dealer.rtb.util
- import com.typesafe.scalalogging.LazyLogging
- import org.joda.time.DateTime
- import org.joda.time.format.DateTimeFormat
- object Db2Helper extends LazyLogging {
- Class.forName("com.mysql.jdbc.Driver").newInstance
- def getDb2UsersForDay(numDbps : Int, dbp : Int, date : DateTime, numUsers: Int = 1000) = {
- import java.sql.DriverManager
- def db2Conns = (1 to 19)
- .map( x => if (x < 10) s"0$x" else s"$x")
- .map { x => DriverManager.getConnection(s"jdbc:mysql://HOST:PORT/DB", "USER", "PASS") }
- val begin = DateTimeFormat.forPattern("YYYY-MM-dd HH:mm:ss").print( date )
- val end = DateTimeFormat.forPattern("YYYY-MM-dd HH:mm:ss").print( date.plusDays(1) )
- db2Conns.par.flatMap( conn => {
- logger.debug(s"Getting users for $begin -> $end on ${conn.getMetaData.getURL}")
- new Iterator[String]{
- val rs = conn.createStatement().executeQuery(
- s"""SELECT bla
- |FROM bla
- |WHERE datetime BETWEEN '$begin' AND '$end'
- |LIMIT $numUsers;""".stripMargin)
- override def hasNext = rs.next()
- override def next = rs.getString("bla")
- }
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement