Browse Source

Merge pull request #551 from huntc/play-2-2-0

Play 2 2 0 updates
Brian Hauer 11 years ago
parent
commit
3bdad28869

+ 1 - 1
play-java-jpa/project/plugins.sbt

@@ -5,4 +5,4 @@ logLevel := Level.Warn
 resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
 
 // Use the Play sbt plugin for Play projects
-addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0-RC2")
+addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")

+ 1 - 1
play-java/project/plugins.sbt

@@ -5,4 +5,4 @@ logLevel := Level.Warn
 resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
 
 // Use the Play sbt plugin for Play projects
-addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0-RC2")
+addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")

+ 11 - 13
play-scala-mongodb/app/controllers/Application.scala

@@ -33,21 +33,19 @@ object Application extends Controller {
   private def collection: JSONCollection = database.collection[JSONCollection]("world")
   private val projection = Json.obj("_id" -> 0)
 
-  def db(queries: Int) = Action {
+  def db(queries: Int) = Action.async {
     import scala.concurrent.ExecutionContext.Implicits.global
 
-    Async {
-      val random = ThreadLocalRandom.current()
-      val futureWorlds = Future.sequence((for {
-        _ <- 1 to queries
-      } yield { collection
-        .find(Json.obj("id" -> (random.nextInt(TestDatabaseRows) + 1)), projection)
-        .one[JsValue]
-      }))
-
-      futureWorlds.map { worlds =>
-        Ok(Json.toJson(worlds))
-      }
+    val random = ThreadLocalRandom.current()
+    val futureWorlds = Future.sequence((for {
+      _ <- 1 to queries
+    } yield { collection
+      .find(Json.obj("id" -> (random.nextInt(TestDatabaseRows) + 1)), projection)
+      .one[JsValue]
+    }))
+
+    futureWorlds.map { worlds =>
+      Ok(Json.toJson(worlds))
     }
   }
 

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

@@ -7,7 +7,7 @@ object ApplicationBuild extends Build {
   val appVersion      = "1.0-SNAPSHOT"
 
   val appDependencies = Seq(
-    "org.reactivemongo" %% "play2-reactivemongo" % "0.9"
+    "org.reactivemongo" %% "play2-reactivemongo" % "0.9" exclude("org.scala-stm", "scala-stm_2.10.0")
   )
 
   val main = play.Project(appName, appVersion, appDependencies).settings(

+ 1 - 1
play-scala-mongodb/project/build.properties

@@ -1 +1 @@
-sbt.version=0.12.3
+sbt.version=0.13.0

+ 1 - 1
play-scala-mongodb/project/plugins.sbt

@@ -5,4 +5,4 @@ logLevel := Level.Warn
 resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
 
 // Use the Play sbt plugin for Play projects
-addSbtPlugin("play" % "sbt-plugin" % "2.1.2-RC1")
+addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")

+ 1 - 1
play-scala/project/plugins.sbt

@@ -5,4 +5,4 @@ logLevel := Level.Warn
 resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
 
 // Use the Play sbt plugin for Play projects
-addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0-RC2")
+addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")

+ 37 - 43
play-slick/app/controllers/Application.scala

@@ -40,60 +40,54 @@ object Application extends Controller {
   def isDbAvailable: Boolean = (tpe.getQueue.size() < maxConnections * MaxQueriesPerRequest)
 
   def db(queries: Int) = PredicatedAction(isDbAvailable, ServiceUnavailable) {
-    Action {
-      Async {
-        val random = ThreadLocalRandom.current()
-
-        val _worlds = Future.sequence((for {
-          _ <- 1 to queries
-        } yield Future(worldsTable.findById(random.nextInt(TestDatabaseRows) + 1))(dbEc)
-          ).toList)
-
-        _worlds map {
-          w => Ok(Json.toJson(w))
-        }
+    Action.async {
+      val random = ThreadLocalRandom.current()
+
+      val _worlds = Future.sequence((for {
+        _ <- 1 to queries
+      } yield Future(worldsTable.findById(random.nextInt(TestDatabaseRows) + 1))(dbEc)
+        ).toList)
+
+      _worlds map {
+        w => Ok(Json.toJson(w))
       }
     }
   }
 
   def fortunes() = PredicatedAction(isDbAvailable, ServiceUnavailable) {
-    Action {
-      Async {
-        Future(fortunesTable.getAll())(dbEc).map { fs =>
-          val fortunes =  Fortune(-1, "Additional fortune added at request time.") +: fs
-          Ok(views.html.fortune(fortunes))
-        }
+    Action.async {
+      Future(fortunesTable.getAll())(dbEc).map { fs =>
+        val fortunes =  Fortune(-1, "Additional fortune added at request time.") +: fs
+        Ok(views.html.fortune(fortunes))
       }
     }
   }
 
   def update(queries: Int) = PredicatedAction(isDbAvailable, ServiceUnavailable) {
-    Action {
-      Async {
-        val random = ThreadLocalRandom.current()
-
-        val boundsCheckedQueries = queries match {
-          case q if q > 500 => 500
-          case q if q <   1 => 1
-          case _ => queries
-        }
-
-        val worlds = Future.sequence((for {
-          _ <- 1 to boundsCheckedQueries
-        } yield Future {
-            for {
-              world <- worldsTable.findById(random.nextInt(TestDatabaseRows) + 1) 
-            } yield {
-              val updatedWorld = world.copy(randomNumber = random.nextInt(TestDatabaseRows) + 1)
-              worldsTable.updateRandom(updatedWorld)
-              updatedWorld
-            }
-          }(dbEc)
-        ).toList)
+    Action.async {
+      val random = ThreadLocalRandom.current()
+
+      val boundsCheckedQueries = queries match {
+        case q if q > 500 => 500
+        case q if q <   1 => 1
+        case _ => queries
+      }
 
-        worlds.map {
-          w => Ok(Json.toJson(w)).withHeaders("Server" -> "Netty")
-        }
+      val worlds = Future.sequence((for {
+        _ <- 1 to boundsCheckedQueries
+      } yield Future {
+          for {
+            world <- worldsTable.findById(random.nextInt(TestDatabaseRows) + 1) 
+          } yield {
+            val updatedWorld = world.copy(randomNumber = random.nextInt(TestDatabaseRows) + 1)
+            worldsTable.updateRandom(updatedWorld)
+            updatedWorld
+          }
+        }(dbEc)
+      ).toList)
+
+      worlds.map {
+        w => Ok(Json.toJson(w)).withHeaders("Server" -> "Netty")
       }
     }
   }

+ 1 - 1
play-slick/app/models/World.scala

@@ -18,7 +18,7 @@ class Worlds extends Table[World]("World") {
   }
 
   def updateRandom(world: World) {
-    DB.withSession { implicit session =>
+    DB.withSession { implicit session: Session =>
       this.where(_.id === world.id.bind).update(world)
     }
   }

+ 4 - 3
play-slick/app/utils/PredicatedAction.scala

@@ -1,15 +1,16 @@
 package utils
 
 import play.api.mvc._
+import scala.concurrent.{Promise, Future}
 
 /**
  * A predicated action is one where a condition must be satisfied in order to proceed with the request. If the
  * condition is not satisfied then a supplied status result is yielded.
  */
 class PredicatedActionBuilder {
-  def apply[A](p: => Boolean, failed: => Result)(action: Action[A]): Action[A] = new Action[A] {
-    def apply(request: Request[A]): Result = {
-      if (p) action(request) else failed
+  def apply[A](p: => Boolean, failed: => SimpleResult)(action: Action[A]): Action[A] = new Action[A] {
+    def apply(request: Request[A]): Future[SimpleResult] = {
+      if (p) action(request) else Promise.successful(failed).future
     }
 
     lazy val parser = action.parser

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

@@ -1,6 +1,6 @@
 import sbt._
 import Keys._
-import PlayProject._
+import play.Project._
 
 object ApplicationBuild extends Build {
 
@@ -11,7 +11,7 @@ object ApplicationBuild extends Build {
     jdbc,
     anorm,
     "mysql" % "mysql-connector-java" % "5.1.22",
-    "com.typesafe.play" %% "play-slick" % "0.3.2" 
+    "com.typesafe.play" %% "play-slick" % "0.5.0.8" 
   )
 
   val main = play.Project(appName, appVersion, appDependencies).settings(

+ 1 - 1
play-slick/project/build.properties

@@ -1 +1 @@
-sbt.version=0.12.3
+sbt.version=0.13.0

+ 1 - 1
play-slick/project/plugins.sbt

@@ -5,4 +5,4 @@ logLevel := Level.Warn
 resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
 
 // Use the Play sbt plugin for Play projects
-addSbtPlugin("play" % "sbt-plugin" % "2.1.2-RC1")
+addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")