Advertisement
Guest User

Untitled

a guest
Feb 8th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.39"
  2. libraryDependencies += "com.typesafe.scala-logging" % "scala-logging_2.11" % "3.5.0"
  3. libraryDependencies += "joda-time" % "joda-time" % "2.3"
  4.  
  5. package com.dealer.rtb.util
  6.  
  7. import com.typesafe.scalalogging.LazyLogging
  8. import org.joda.time.DateTime
  9. import org.joda.time.format.DateTimeFormat
  10.  
  11. object Db2Helper extends LazyLogging {
  12. Class.forName("com.mysql.jdbc.Driver").newInstance
  13. def getDb2UsersForDay(numDbps : Int, dbp : Int, date : DateTime, numUsers: Int = 1000) = {
  14. import java.sql.DriverManager
  15. def db2Conns = (1 to 19)
  16. .map( x => if (x < 10) s"0$x" else s"$x")
  17. .map { x => DriverManager.getConnection(s"jdbc:mysql://HOST:PORT/DB", "USER", "PASS") }
  18.  
  19. val begin = DateTimeFormat.forPattern("YYYY-MM-dd HH:mm:ss").print( date )
  20. val end = DateTimeFormat.forPattern("YYYY-MM-dd HH:mm:ss").print( date.plusDays(1) )
  21.  
  22. db2Conns.par.flatMap( conn => {
  23. logger.debug(s"Getting users for $begin -> $end on ${conn.getMetaData.getURL}")
  24. new Iterator[String]{
  25. val rs = conn.createStatement().executeQuery(
  26. s"""SELECT bla
  27. |FROM bla
  28. |WHERE datetime BETWEEN '$begin' AND '$end'
  29. |LIMIT $numUsers;""".stripMargin)
  30. override def hasNext = rs.next()
  31. override def next = rs.getString("bla")
  32. }
  33. })
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement