Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def writeBuffersToDb(files: Seq[File]) = {
- println(s"Writing buffers $files")
- def diff(ts: Long) = (System.currentTimeMillis() - ts) / 1000
- // parallel works suspiciously slow under windows,
- // however it is expected to be faster
- // http://dba.stackexchange.com/questions/20723/postgresql-two-concurrent-copy-from
- DB localTx { implicit session: DBSession =>
- // dropIndexes()
- files.foreach { case file =>
- val ts = System.currentTimeMillis()
- println(s"Processing $file")
- Using.using(new FileInputStream(file)) { stream ⇒
- val field = session.connection.getClass.getDeclaredField("this$0")
- field.setAccessible(true)
- val ds = field.get(session.connection).asInstanceOf[PoolingDataSource]
- ds.setAccessToUnderlyingConnectionAllowed(true)
- val conn = session.connection.asInstanceOf[DelegatingConnection].getInnermostDelegate
- val copyManager = new CopyManager(conn.asInstanceOf[BaseConnection])
- // val reader = new FileReader(file)
- //"COPY timeseriesentry(ts, val, componentgroup_id) FROM STDIN",
- copyManager.copyIn("COPY observation(ts, vl, parameter_id) FROM STDIN;", stream)
- }
- println(s"Done $file in ${diff(ts)} seconds")
- }
- println(s"Recreating index...")
- val ts = System.currentTimeMillis()
- // createIndexes()
- println(s"Done index in ${diff(ts)} seconds")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement