Browse Source

Updating Jooby Framework from 0.16.0 to 1.0.3 (#2572)

* Updating Jooby Framework from 0.16.0 to 1.0.3

* Update Jooby jdbc configuration with useServerPrepStmts=true

* Adding fortunes test to Jooby

* add fortunes test to benchmark configuration for Jooby
Max De Marzi 8 years ago
parent
commit
fff744dc6f

+ 1 - 0
frameworks/Java/jooby/benchmark_config.json

@@ -6,6 +6,7 @@
       "db_url": "/db",
       "json_url": "/json",
       "plaintext_url": "/plaintext",
+      "fortune_url": "/fortunes",
       "port": 8080,
       "approach": "Realistic",
       "classification": "Fullstack",

+ 1 - 1
frameworks/Java/jooby/conf/application.conf

@@ -11,7 +11,7 @@ server.threads.Max = ${runtime.processors-x2}
 DBHOST = localhost
 
 ## database
-db.url = "jdbc:mysql://"${DBHOST}":3306/hello_world?jdbcCompliantTruncation=false&elideSetAutoCommits=true&useLocalSessionState=true&cachePrepStmts=true&cacheCallableStmts=true&alwaysSendSetIsolation=false&prepStmtCacheSize=4096&cacheServerConfiguration=true&prepStmtCacheSqlLimit=2048&zeroDateTimeBehavior=convertToNull&traceProtocol=false&useUnbufferedInput=false&useReadAheadInput=false&maintainTimeStats=false&useServerPrepStmts&cacheRSMetadata=true"
+db.url = "jdbc:mysql://"${DBHOST}":3306/hello_world?jdbcCompliantTruncation=false&elideSetAutoCommits=true&useLocalSessionState=true&cachePrepStmts=true&cacheCallableStmts=true&alwaysSendSetIsolation=false&prepStmtCacheSize=4096&cacheServerConfiguration=true&prepStmtCacheSqlLimit=2048&zeroDateTimeBehavior=convertToNull&traceProtocol=false&useUnbufferedInput=false&useReadAheadInput=false&maintainTimeStats=false&useServerPrepStmts=true&cacheRSMetadata=true"
 db.user = benchmarkdbuser
 db.password = benchmarkdbpass
 hikari.maximumPoolSize = ${server.threads.Max}

+ 8 - 2
frameworks/Java/jooby/pom.xml

@@ -7,7 +7,7 @@
   <parent>
     <groupId>org.jooby</groupId>
     <artifactId>jooby-project</artifactId>
-    <version>0.16.0</version>
+    <version>1.0.3</version>
   </parent>
 
   <artifactId>jooby</artifactId>
@@ -17,7 +17,7 @@
   <name>jooby</name>
 
   <properties>
-    <jooby.version>0.16.0</jooby.version>
+    <jooby.version>1.0.3</jooby.version>
 
     <!-- Startup class -->
     <application.class>com.techempower.App</application.class>
@@ -48,6 +48,12 @@
       <artifactId>mysql-connector-java</artifactId>
     </dependency>
 
+    <!-- handlebars -->
+    <dependency>
+      <groupId>org.jooby</groupId>
+      <artifactId>jooby-hbs</artifactId>
+    </dependency>
+
     <!-- Server -->
     <dependency>
       <groupId>org.jooby</groupId>

+ 12 - 0
frameworks/Java/jooby/public/fortunes.html

@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head><title>Fortunes</title></head>
+<body>
+<table>
+    <tr><th>id</th><th>message</th></tr>
+    {{#each fortunes}}
+    <tr><td>{{id}}</td><td>{{message}}</td></tr>
+    {{/each}}
+</table>
+</body>
+</html>

+ 23 - 8
frameworks/Java/jooby/src/main/java/com/techempower/App.java

@@ -1,20 +1,22 @@
 package com.techempower;
 
-import java.time.Instant;
-import java.time.ZoneId;
-import java.time.format.DateTimeFormatter;
-import java.util.Locale;
-import java.util.concurrent.ThreadLocalRandom;
-
+import com.fasterxml.jackson.databind.ObjectMapper;
 import org.jooby.Jooby;
 import org.jooby.MediaType;
 import org.jooby.Result;
 import org.jooby.Results;
+import org.jooby.hbs.Hbs;
 import org.jooby.jdbi.Jdbi;
 import org.jooby.json.Jackson;
 import org.skife.jdbi.v2.Handle;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+import java.util.concurrent.ThreadLocalRandom;
 
 /**
  * @author jooby generator
@@ -42,6 +44,9 @@ public class App extends Jooby {
     /** database via jdbi .*/
     use(new Jdbi());
 
+    /** templates via handlebars .*/
+    use(new Hbs());
+
     get("/plaintext", () -> result(HELLO_WORLD, MediaType.text))
         .renderer("text");
 
@@ -60,6 +65,16 @@ public class App extends Jooby {
       }
     }).renderer("json");
 
+    get("/fortunes", req -> {
+      try (Handle handle = req.require(Handle.class)) {
+        List<Fortune> fortunes = handle.createQuery("select * from fortune")
+                .map((idx,rs,ctx) -> new Fortune(rs.getInt("id"), rs.getString("message")))
+                .list();
+        fortunes.add(new Fortune(0, "Additional fortune added at request time."));
+        Collections.sort(fortunes);
+        return result(Results.html("fortunes").put("fortunes", fortunes), MediaType.html);
+      }
+    }).renderer("html");
   }
 
   private Result result(final Object value, final MediaType type) {
@@ -69,7 +84,7 @@ public class App extends Jooby {
   }
 
   public static void main(final String[] args) throws Exception {
-    new App().start(args);
+    run(App::new, args);
   }
 
 }

+ 25 - 0
frameworks/Java/jooby/src/main/java/com/techempower/Fortune.java

@@ -0,0 +1,25 @@
+package com.techempower;
+
+/**
+ * The model for the "fortune" database table.
+ */
+public final class Fortune implements Comparable<Fortune> {
+    public int id;
+    public String message;
+
+    /**
+     * Constructs a new fortune object with the given parameters.
+     *
+     * @param id the ID of the fortune
+     * @param message the message of the fortune
+     */
+    public Fortune(int id, String message) {
+        this.id = id;
+        this.message = message;
+    }
+
+    @Override
+    public int compareTo(Fortune other) {
+        return message.compareTo(other.message);
+    }
+}