Advertisement
NLinker

selectByWithDeps

Nov 21st, 2013
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.99 KB | None | 0 0
  1.   /**
  2.    * Select only job without dependent tables
  3.    */
  4.   def selectByWithDeps(jobId: Int): Option[JobDeps] = {
  5.     execute {
  6.       DbSchema.db.withSession {
  7.         implicit session: Session =>
  8.           session.withTransaction {
  9.             // fill the dependent instances with empty data
  10.             val query = for {
  11.               job <- schema.Jobs if job.jobId === jobId && job.isDeleted === Active.value
  12.               jty <- schema.JobTypes if jty.jtyId === job.jtyId && jty.isDeleted === Active.value
  13.               jtm <- schema.JobTemplates if jtm.jtmId === jty.jtmId && jtm.isDeleted === Active.value
  14.               src <- schema.DataSources if src.srcId === jtm.srcId && src.isDeleted === Active.value
  15.               dst <- schema.DataDestinations if dst.destId === jty.destId && dst.isDeleted === Active.value
  16.             } yield (job, jty, jtm, src, dst)
  17.             val f = (JobDeps.apply _).tupled
  18.             query.firstOption.map(t => f(t))
  19.           }
  20.       }
  21.     }
  22.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement