Browse Source

Merge branch 'slick2-upgrade' of https://github.com/cvogt/FrameworkBenchmarks into 824

James Yen 11 years ago
parent
commit
a6801becb6

+ 3 - 3
play-slick/app/controllers/Application.scala

@@ -5,7 +5,7 @@ import play.api.mvc._
 import play.api.libs.json.Json
 import play.api.libs.json.Json
 import java.util.concurrent._
 import java.util.concurrent._
 import scala.concurrent._
 import scala.concurrent._
-import models.{Worlds, World, Fortunes, Fortune}
+import models.{Worlds, World, Fortunes, Fortune, WorldsTableQuery, FortunesTableQuery}
 import utils._
 import utils._
 import scala.concurrent.Future
 import scala.concurrent.Future
 
 
@@ -29,8 +29,8 @@ object Application extends Controller {
     new NamedThreadFactory("dbEc"))
     new NamedThreadFactory("dbEc"))
   private val dbEc = ExecutionContext.fromExecutorService(tpe)
   private val dbEc = ExecutionContext.fromExecutorService(tpe)
 
 
-  private val worldsTable = new Worlds
-  private val fortunesTable = new Fortunes
+  private val worldsTable = new WorldsTableQuery
+  private val fortunesTable = new FortunesTableQuery
 
 
   // A predicate for checking our ability to service database requests is determined by ensuring that the request
   // A predicate for checking our ability to service database requests is determined by ensuring that the request
   // queue doesn't fill up beyond a certain threshold. For convenience we use the max number of connections * the max
   // queue doesn't fill up beyond a certain threshold. For convenience we use the max number of connections * the max

+ 7 - 6
play-slick/app/models/Fortune.scala

@@ -5,15 +5,16 @@ import play.api.db.slick.Config.driver.simple._
 import play.api.db.slick.DB
 import play.api.db.slick.DB
 
 
 
 
-class Fortunes extends Table[Fortune]("Fortune") {
+class Fortunes(tag: Tag) extends Table[Fortune](tag, "Fortune") {
   def id = column[Long]("id", O.PrimaryKey)
   def id = column[Long]("id", O.PrimaryKey)
   def message = column[String]("message")
   def message = column[String]("message")
-  def * = id ~ message <> (Fortune.apply _, Fortune.unapply _)
-
-  val byId = createFinderBy(_.id)
-
+  def * = (id, message) <> (Fortune.tupled, Fortune.unapply _)
+}
+class FortunesTableQuery extends TableQuery(new Fortunes(_)){
+  val byId = this.findBy(_.id)
+  val all = Compiled{this:Query[Fortunes,Fortune]}
   def getAll(): List[Fortune] = DB.withSession { implicit session =>
   def getAll(): List[Fortune] = DB.withSession { implicit session =>
-    Query(this).list
+    all.list
   }
   }
 }
 }
 
 

+ 8 - 7
play-slick/app/models/World.scala

@@ -6,23 +6,24 @@ import play.api.db.slick.DB
 import play.api.libs.json._
 import play.api.libs.json._
 import play.api.libs.functional.syntax._
 import play.api.libs.functional.syntax._
 
 
-class Worlds extends Table[World]("World") {
+class Worlds(tag: Tag) extends Table[World](tag, "World") {
   def id = column[Int]("id", O.PrimaryKey)
   def id = column[Int]("id", O.PrimaryKey)
   def randomNumber = column[Long]("randomNumber")
   def randomNumber = column[Long]("randomNumber")
-  def * = id ~ randomNumber <> (World.apply _, World.unapply _)
-
-  val byId = createFinderBy(_.id)
+  def * = (id, randomNumber) <> ((World.apply _).tupled, World.unapply _)
+}
+class WorldsTableQuery extends TableQuery(new Worlds(_)){
+  val byId = this.findBy(_.id)
 
 
   def findById(id: Int): Option[World] = DB.withSession { implicit session =>
   def findById(id: Int): Option[World] = DB.withSession { implicit session =>
       byId(id).firstOption
       byId(id).firstOption
   }
   }
 
 
+  val updateQuery = Compiled{ (id: Column[Int]) => this.where(_.id === id) }
   def updateRandom(world: World) {
   def updateRandom(world: World) {
     DB.withSession { implicit session: Session =>
     DB.withSession { implicit session: Session =>
-      this.where(_.id === world.id.bind).update(world)
+      updateQuery(world.id).update(world)
     }
     }
-  }
-
+  }  
 }
 }
 
 
 case class World(id: Int, randomNumber: Long)
 case class World(id: Int, randomNumber: Long)

+ 1 - 1
play-slick/project/Build.scala

@@ -11,7 +11,7 @@ object ApplicationBuild extends Build {
     jdbc,
     jdbc,
     anorm,
     anorm,
     "mysql" % "mysql-connector-java" % "5.1.22",
     "mysql" % "mysql-connector-java" % "5.1.22",
-    "com.typesafe.play" %% "play-slick" % "0.5.0.8" 
+    "com.typesafe.play" %% "play-slick" % "0.6.0.1"
   )
   )
 
 
   val main = play.Project(appName, appVersion, appDependencies).settings(
   val main = play.Project(appName, appVersion, appDependencies).settings(