Browse Source

Updated play-java-jpa to 2.2.0-RC2

Christopher Hunt 12 years ago
parent
commit
19717b05ff

+ 11 - 29
play-java-jpa/app/controllers/Application.java

@@ -1,18 +1,14 @@
 package controllers;
 
 import akka.dispatch.ExecutionContexts;
-import akka.dispatch.Futures;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
 import models.World;
 import play.Play;
 import play.core.NamedThreadFactory;
-import play.libs.Akka;
 import play.libs.F;
 import play.libs.Json;
 
-import static play.libs.Akka.future;
-
-import org.codehaus.jackson.node.ObjectNode;
-import org.codehaus.jackson.map.ObjectMapper;
 import play.mvc.Controller;
 import play.mvc.Result;
 import scala.concurrent.ExecutionContext;
@@ -28,7 +24,6 @@ public class Application extends Controller {
 
     private static final int MAX_QUERIES_PER_REQUEST = 20;
     private static final int TEST_DATABASE_ROWS = 10000;
-    //http://stackoverflow.com/questions/3907929/should-i-make-jacksons-objectmapper-as-static-final
     private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
 
     private static final int partitionCount = Play.application().configuration().getInt("db.default.partitionCount");
@@ -63,37 +58,24 @@ public class Application extends Controller {
 
 
     @Predicated(predicate = IsDbAvailable.class, failed = SERVICE_UNAVAILABLE)
-    public static Result db(final Integer queries) {
+    public static F.Promise<Result> db(final Integer queries) {
         final Random random = ThreadLocalRandom.current();
         final List<F.Promise<? extends World>> promises = new ArrayList<F.Promise<? extends World>>(queries);
         for (int i = 0; i < queries; ++i) {
-            // There's no convenience method for submitting a future on an EC in Java. There is
-            // an issue that will address this though: https://github.com/playframework/Play20/issues/972
-            // Meanwhile we call the Akka future directly and wrap its result in a promise.
-            final F.Promise p = Akka.asPromise(Futures.future(
-                    findWorld(Long.valueOf(random.nextInt(TEST_DATABASE_ROWS) + 1)), dbEc));
+            final F.Promise<World> p = F.Promise.promise(new F.Function0<World>() {
+                @Override
+                public World apply() throws Throwable {
+                    return World.findById(Long.valueOf(random.nextInt(TEST_DATABASE_ROWS) + 1));
+                }
+            }, dbEc);
             promises.add(p);
         }
-        return async(F.Promise.sequence(promises).map(new F.Function<List<World>, Result>() {
-
+        return F.Promise.sequence(promises).map(new F.Function<List<World>, Result>() {
             @Override
             public Result apply(List<World> worlds) {
                 return ok(Json.toJson(worlds));
             }
-
-        }));
-
-    }
-
-    private static Callable<World> findWorld(final Long id) {
-        return new Callable<World>() {
-            @Override
-            public World call() {
-                try {
-                    return World.findById(id);
-                } catch(Throwable t) { throw new RuntimeException(t); }
-            }
-        };
+        });
     }
 
 }

+ 0 - 1
play-java-jpa/app/models/World.java

@@ -3,7 +3,6 @@ package models;
 import javax.persistence.*;
 
 import play.db.jpa.JPA;
-import play.db.jpa.Transactional;
 
 @Entity
 public class World {

+ 4 - 3
play-java-jpa/app/utils/PredicatedAction.java

@@ -5,18 +5,19 @@ package utils;
  * condition is not satisfied then a supplied status result is yielded.
  */
 
+import play.libs.F;
 import play.mvc.Action;
 import play.mvc.Http;
-import play.mvc.Result;
+import play.mvc.SimpleResult;
 
 public class PredicatedAction extends Action<Predicated> {
     @Override
-    public Result call(final Http.Context ctx) throws Throwable {
+    public F.Promise<SimpleResult> call(final Http.Context ctx) throws Throwable {
         final Predicate p = configuration.predicate().newInstance();
         if (p.condition()) {
             return delegate.call(ctx);
         } else {
-            return status(configuration.failed());
+            return F.Promise.<SimpleResult>pure(status(configuration.failed()));
         }
     }
 }

+ 12 - 0
play-java-jpa/build.sbt

@@ -0,0 +1,12 @@
+name := "play-java-jpa"
+
+version := "1.0-SNAPSHOT"
+
+libraryDependencies ++= Seq(
+  javaJdbc,
+  javaJpa,
+  "mysql" % "mysql-connector-java" % "5.1.22",
+  "org.hibernate" % "hibernate-entitymanager" % "4.2.1.Final"
+  )
+
+playJavaSettings

+ 0 - 19
play-java-jpa/conf/application.conf

@@ -72,22 +72,3 @@ logger.play=ERROR
 
 # Logger provided to your application:
 logger.application=ERROR
-play {
-  akka {
-    event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]
-    loglevel = WARNING
-    actor {
-      default-dispatcher = {
-        fork-join-executor {
-          parallelism-factor = 1.0
-          parallelism-max = 50
-        }
-      }
-      application = {
-        fork-join-executor {
-          parallelism-max = 300
-        }
-      }	
-    }
-  }
-}

+ 0 - 23
play-java-jpa/project/Build.scala

@@ -1,23 +0,0 @@
-import sbt._
-import Keys._
-import play.Project._
-
-object ApplicationBuild extends Build {
-
-    val appName         = "play-java-jpa"
-    val appVersion      = "1.0-SNAPSHOT"
-
-    val appDependencies = Seq(
-      // Add your project dependencies here,
-      javaCore,
-      javaJdbc,
-      javaJpa,
-      "mysql" % "mysql-connector-java" % "5.1.22",
-      "org.hibernate" % "hibernate-entitymanager" % "4.2.1.Final"
-    )
-
-    val main = play.Project(appName, appVersion, appDependencies).settings(
-      // Add your own project settings here 
-    )
-
-}

+ 1 - 1
play-java-jpa/project/build.properties

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

+ 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("play" % "sbt-plugin" % "2.1.2-RC1")
+addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0-RC2")