Browse Source

Merge pull request #1829 from jochenberger/add-fortune-test-2

add support for Test type 4: Fortunes
Nate 9 years ago
parent
commit
fe696b28cf

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

@@ -6,6 +6,7 @@
       "json_url": "/tapestry/hellojson",
       "db_url": "/tapestry/hellodb",
       "query_url": "/tapestry/hellodbs?queries=",
+      "fortune_url": "/tapestry/hellofortune",
       "port": 8080,
       "approach": "Realistic",
       "classification": "Fullstack",

+ 22 - 0
frameworks/Java/tapestry/hello/src/main/java/hello/entities/Fortune.java

@@ -0,0 +1,22 @@
+package hello.entities;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+/**
+ * Database Mapping Test entity
+ */
+@Entity
+public class Fortune implements Comparable<Fortune> {
+  @Id
+  @GeneratedValue(strategy = GenerationType.IDENTITY)
+  public int id;
+  public String message;
+
+  @Override
+  public int compareTo(final Fortune o) {
+    return message.compareTo(o.message);
+  }
+}

+ 37 - 0
frameworks/Java/tapestry/hello/src/main/java/hello/pages/HelloFortune.java

@@ -0,0 +1,37 @@
+package hello.pages;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.tapestry5.annotations.Property;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.services.Request;
+
+import hello.entities.Fortune;
+
+/**
+ * Test type 4: Fortunes
+ */
+public class HelloFortune {
+  @Inject
+  private org.hibernate.Session session;
+
+  @Inject
+  private Request request;
+
+  @Property
+  private Fortune currentFortune;
+
+  public List getFortunes() {
+    final List<Fortune> fortunesFromDB = session.createCriteria(Fortune.class).list();
+    final List<Fortune> fortunes = new ArrayList<>(fortunesFromDB.size() + 1);
+    fortunes.addAll(fortunesFromDB);
+    Fortune additionalFortune = new Fortune();
+    additionalFortune.message = "Additional fortune added at request time.";
+    fortunes.add(additionalFortune);
+    Collections.sort(fortunes);
+    return fortunes;
+  }
+
+}

+ 17 - 0
frameworks/Java/tapestry/hello/src/main/java/hello/services/AppModule.java

@@ -1,8 +1,12 @@
 package hello.services;
 
+import org.apache.tapestry5.MarkupWriter;
 import org.apache.tapestry5.SymbolConstants;
 import org.apache.tapestry5.ioc.MappedConfiguration;
+import org.apache.tapestry5.ioc.OrderedConfiguration;
 import org.apache.tapestry5.ioc.ServiceBinder;
+import org.apache.tapestry5.services.MarkupRenderer;
+import org.apache.tapestry5.services.MarkupRendererFilter;
 
 /**
  * This module is automatically included as part of the Tapestry IoC Registry, it's a good place to
@@ -41,5 +45,18 @@ public class AppModule
         // you can extend this list of locales (it's a comma separated series of locale names;
         // the first locale name is the default when there's no reasonable match).
         configuration.add(SymbolConstants.SUPPORTED_LOCALES, "en");
+        configuration.add(SymbolConstants.OMIT_GENERATOR_META, true);
+        
+    }
+    
+    public void contributeMarkupRenderer(OrderedConfiguration<MarkupRendererFilter> configuration){
+      // prevent addition of the default stylesheet. There will be a symbol to toggle this behavior in Tapestry 5.4.
+      configuration.override("InjectDefaultStylesheet", new MarkupRendererFilter() {
+        
+        @Override
+        public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
+          renderer.renderMarkup(writer);
+        }
+      });
     }
 }

+ 18 - 0
frameworks/Java/tapestry/hello/src/main/resources/hello/pages/HelloFortune.tml

@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd">
+	<head>
+		<title>Fortunes</title>
+	</head>
+	<body>
+		<table>
+			<tr>
+				<th>id</th>
+				<th>message</th>
+			</tr>
+			<t:loop  source="fortunes" value="currentFortune" element="tr">
+				<td>${currentFortune.id}</td>
+				<td>${currentFortune.message}</td>
+			</t:loop>
+		</table>
+	</body>
+</html>