Browse Source

Merge pull request #1449 from TechEmpower/tapestry-1137

Fixed validation warnings for tapestry. Resolves #1137
Brittany Mazza 10 years ago
parent
commit
a36184e537

+ 2 - 2
frameworks/Java/tapestry/benchmark_config

@@ -5,7 +5,7 @@
       "setup_file": "setup",
       "setup_file": "setup",
       "json_url": "/tapestry/hellojson",
       "json_url": "/tapestry/hellojson",
       "db_url": "/tapestry/hellodb",
       "db_url": "/tapestry/hellodb",
-      "query_url": "/tapestry/hellodb?queries=",
+      "query_url": "/tapestry/hellodbs?queries=",
       "port": 8080,
       "port": 8080,
       "approach": "Realistic",
       "approach": "Realistic",
       "classification": "Fullstack",
       "classification": "Fullstack",
@@ -22,4 +22,4 @@
       "versus": "servlet"
       "versus": "servlet"
     }
     }
   }]
   }]
-}
+}

+ 2 - 23
frameworks/Java/tapestry/hello/src/main/java/hello/pages/HelloDB.java

@@ -32,37 +32,16 @@ public class HelloDB
 
 
   StreamResponse onActivate() {
   StreamResponse onActivate() {
 
 
-    // Read queries from URL, but don't bother validating
-    int queries = 1;
-    String qString = this.request.getParameter("queries");
-    if (qString != null) {
-      queries = Integer.parseInt(qString);
-    }
-    if (queries <= 0) {
-      queries = 1;
-    }
-    final World[] worlds = new World[queries];
-
     // For generating a random row ID
     // For generating a random row ID
     final Random rand = ThreadLocalRandom.current();
     final Random rand = ThreadLocalRandom.current();
 
 
-    for (int i = 0; i < queries; i++) {
-      // Read object from database
-      worlds[i] = (World)session.get(World.class, new Integer(rand.nextInt(DB_ROWS) + 1));
-    }
+    final World world = (World)session.get(World.class, new Integer(rand.nextInt(DB_ROWS) + 1));
 
 
     // Send reponse
     // Send reponse
     String response = "";
     String response = "";
     try
     try
     {
     {
-      if (queries == 1)
-      {
-        response = HelloDB.mapper.writeValueAsString(worlds[0]); 
-      }
-      else
-      {
-        response = HelloDB.mapper.writeValueAsString(worlds);
-      }
+      response = HelloDB.mapper.writeValueAsString(world);
     }
     }
     catch (IOException ex)
     catch (IOException ex)
     {
     {

+ 74 - 0
frameworks/Java/tapestry/hello/src/main/java/hello/pages/HelloDBs.java

@@ -0,0 +1,74 @@
+package hello.pages;
+
+import hello.entities.*;
+
+import java.util.*;
+import java.util.concurrent.*;
+import java.io.IOException;
+
+import org.apache.tapestry5.*;
+import org.apache.tapestry5.annotations.*;
+import org.apache.tapestry5.ioc.annotations.*;
+import org.apache.tapestry5.json.*;
+import org.apache.tapestry5.util.*;
+import org.apache.tapestry5.services.*;
+import org.hibernate.*;
+import com.fasterxml.jackson.databind.*;
+
+/**
+ * Database Mapping Test
+ */
+public class HelloDBs
+{
+  @Inject
+  private org.hibernate.Session session;
+
+  @Inject
+  private Request request;
+
+  private static final int DB_ROWS = 10000;
+
+  private static final ObjectMapper mapper = new ObjectMapper();
+
+  StreamResponse onActivate() {
+
+    // Read queries from URL, but don't bother validating
+    int queries = 1;
+    String qString = this.request.getParameter("queries");
+    if (qString != null) {
+      try {
+        queries = Integer.parseInt(qString);
+      }
+      catch (Exception e) {
+        queries = 1;
+      }
+    }
+    if (queries <= 0) {
+      queries = 1;
+    }
+    else if (queries > 500) {
+      queries = 500;
+    }
+    final World[] worlds = new World[queries];
+
+    // For generating a random row ID
+    final Random rand = ThreadLocalRandom.current();
+
+    for (int i = 0; i < queries; i++) {
+      // Read object from database
+      worlds[i] = (World)session.get(World.class, new Integer(rand.nextInt(DB_ROWS) + 1));
+    }
+
+    // Send reponse
+    String response = "";
+    try
+    {
+      response = HelloDBs.mapper.writeValueAsString(worlds);
+    }
+    catch (IOException ex)
+    {
+      // do nothing
+    }
+    return new TextStreamResponse("application/json", response);
+  }
+}