From 1425fc40f5b077dc623c4f870bfd2200fbdd2741 Mon Sep 17 00:00:00 2001 From: cchantep Date: Sun, 21 Feb 2016 16:46:43 +0100 Subject: [PATCH] Update to 0.11.10 --- app/controllers/Application.scala | 45 ++++++++++++++++++------------- build.sbt | 16 +++++++---- project/plugins.sbt | 2 +- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/app/controllers/Application.scala b/app/controllers/Application.scala index 42a6ef7..a8760b3 100644 --- a/app/controllers/Application.scala +++ b/app/controllers/Application.scala @@ -18,31 +18,38 @@ import reactivemongo.api.{ Cursor, QueryOpts } import play.modules.reactivemongo.{ MongoController, ReactiveMongoApi, ReactiveMongoComponents } -import play.modules.reactivemongo.json.collection.JSONCollection +import reactivemongo.play.json.collection.JSONCollection class Application @Inject() (val reactiveMongoApi: ReactiveMongoApi) extends Controller with MongoController with ReactiveMongoComponents { // BSON-JSON conversions - import play.modules.reactivemongo.json._, ImplicitBSONHandlers._ + import reactivemongo.play.json._ + + // Iteratees cursor + import reactivemongo.play.iteratees.cursorProducer // let's be sure that the collections exists and is capped val futureCollection: Future[JSONCollection] = { - val db = reactiveMongoApi.db - val collection = db.collection[JSONCollection]("acappedcollection") + val db = reactiveMongoApi.database + val coll = db.map(_.collection[JSONCollection]("acappedcollection")) - collection.stats().flatMap { - case stats if !stats.capped => - // the collection is not capped, so we convert it - println("converting to capped") - collection.convertToCapped(1024 * 1024, None) - case _ => Future(collection) - }.recover { - // the collection does not exist, so we create it - case _ => - println("creating capped collection...") - collection.createCapped(1024 * 1024, None) - }.map { _ => + for { + collection <- coll + stats <- collection.stats() + _ <- { + if (!stats.capped) { + // the collection is not capped, so we convert it + println("converting to capped") + collection.convertToCapped(1024 * 1024, None) + } else Future.successful(collection) + } recover { + // the collection does not exist, so we create it + case _ => + println("creating capped collection...") + collection.createCapped(1024 * 1024, None) + } + } yield { println("the capped collection is available") collection } @@ -73,15 +80,15 @@ class Application @Inject() (val reactiveMongoApi: ReactiveMongoApi) .find(Json.obj()) // the cursor must be tailable and await data .options(QueryOpts().tailable.awaitData) - .cursor[JsObject] + .cursor[JsObject]() // ok, let's enumerate it - cursor.enumerate() + cursorProducer.produce(cursor).enumerator() } Enumerator.flatten(futureEnumerator) } // We're done! - (in, out) + in -> out } } diff --git a/build.sbt b/build.sbt index 36bce5e..ec5d4f8 100644 --- a/build.sbt +++ b/build.sbt @@ -2,14 +2,20 @@ import play.PlayImport.PlayKeys._ name := "reactivemongo-tailablecursors-demo" -version := "0.11.0" +val reactiveMongoVer = "0.11.10" -scalaVersion := "2.11.6" +version := reactiveMongoVer + +scalaVersion := "2.11.7" + +libraryDependencies ++= Seq( + "org.reactivemongo" %% "play2-reactivemongo" % reactiveMongoVer, + "org.reactivemongo" %% "reactivemongo-iteratees" % reactiveMongoVer +) libraryDependencies ++= Seq( - "org.reactivemongo" %% "play2-reactivemongo" % "0.11.0.play24", - "org.specs2" %% "specs2-core" % "2.4.9" % "test", - "org.specs2" %% "specs2-junit" % "2.4.9" % "test" + "org.specs2" %% "specs2-core" % "2.4.9" % Test, + "org.specs2" %% "specs2-junit" % "2.4.9" % Test ) routesGenerator := InjectedRoutesGenerator diff --git a/project/plugins.sbt b/project/plugins.sbt index fd33e89..ac7576e 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -2,4 +2,4 @@ resolvers ++= Seq( "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" ) -addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.0") +addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.6")