Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 25th, 2012  |  syntax: None  |  size: 0.91 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package database
  2.  
  3. import org.orbroker.RowExtractor
  4. import org.orbroker.Row
  5. import models.Movie
  6. import models.Actor
  7. import org.orbroker.Join
  8. import org.orbroker.JoinExtractor
  9.  
  10. /**
  11.  * Allow this extractor to be used both with and without joining to cast.
  12.  */
  13. class MovieExtractor(withCast: Boolean) extends JoinExtractor[Movie] {
  14.   val key = Set("id")
  15.   val actorRenames = Map("id" -> "actor_id")
  16.   def extract(row: Row, join: Join) = {
  17.   val movieID = row.bigInt("id")
  18.   val title = row.string("title").getOrElse("NULL")
  19.   val rated = row.string("rated").getOrElse("NULL")
  20.   val actors = if (withCast) {
  21.      join.extractSeq(ActorExtractor, actorRenames)
  22.      } else {
  23.        Seq.empty
  24.      }
  25.          new Movie(movieID, title, rated, actors)
  26.    }
  27. }
  28.  
  29. object ActorExtractor extends JoinExtractor[Actor] {
  30.   val key = Set("id")
  31.   def extract(row: Row, join: Join) = new Actor( row.bigInt("id"), row.string("name").getOrElse("NULL") )
  32. }