Guest User

Untitled

a guest
May 1st, 2012
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.12 KB | None | 0 0
  1. class Task extends Record[Long, Task] with IdentityGenerator[Long, Task] {
  2.   def this(name: String, description: String, done: Boolean, dueTo: Option[Date], id: Long) = {
  3.     this()
  4.     this.name := name.trim()
  5.     this.description := description.trim()
  6.     this.dueTo := dueTo
  7.     this.done := done
  8.     if (id == 0) this.id.setNull else this.id := id
  9.   }
  10.  
  11.   def PRIMARY_KEY = id
  12.   def relation = Task
  13.  
  14.   val id = "id".BIGINT.NOT_NULL.AUTO_INCREMENT
  15.   val name = "name".VARCHAR(255)
  16.   val description = "description".TEXT
  17.   val createdAt = "created_at".TIMESTAMP.DEFAULT("current_timestamp")
  18.   val dueTo = "due_to".DATE
  19.   val done = "done".BOOLEAN.NOT_NULL(false)
  20.  
  21. }
  22.  
  23. def apply(name: String, description: String, done: String, dueTo: Option[Date], id: Long) = {
  24.     var task: Task = null;
  25.     if (id > 0) {
  26.       task = Task.get(id).get
  27.       task.name := name
  28.       task.description := description
  29.       task.done := (done == "on")
  30.       task.dueTo := dueTo getOrElse (null)
  31.       task.id := id
  32.     }
  33.     else {
  34.       task = new Task(name, description, done == "on", dueTo getOrElse null, id)
  35.     }
  36.     task
  37.   }
Advertisement
Add Comment
Please, Sign In to add comment