|
@@ -1,4 +1,4 @@
|
|
-package hello.dao;
|
|
|
|
|
|
+package hello.controllers;
|
|
|
|
|
|
import hello.model.Fortune;
|
|
import hello.model.Fortune;
|
|
|
|
|
|
@@ -9,21 +9,59 @@ import javax.persistence.Query;
|
|
|
|
|
|
import com.google.inject.Inject;
|
|
import com.google.inject.Inject;
|
|
import com.google.inject.Provider;
|
|
import com.google.inject.Provider;
|
|
|
|
+import com.google.inject.Singleton;
|
|
import com.google.inject.persist.Transactional;
|
|
import com.google.inject.persist.Transactional;
|
|
|
|
+import hello.model.World;
|
|
|
|
|
|
-public class FortuneDao {
|
|
|
|
|
|
+/**
|
|
|
|
+ * This class is just for testing.
|
|
|
|
+ * Has nothing to do with the TechEmpower test itself...
|
|
|
|
+ * @author ra
|
|
|
|
+ */
|
|
|
|
+@Singleton
|
|
|
|
+public class SetupDao {
|
|
|
|
|
|
@Inject
|
|
@Inject
|
|
Provider<EntityManager> entitiyManagerProvider;
|
|
Provider<EntityManager> entitiyManagerProvider;
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
- public List<Fortune> getAll() {
|
|
|
|
- EntityManager entityManager = entitiyManagerProvider.get();
|
|
|
|
-
|
|
|
|
- Query q = entityManager.createQuery("SELECT x FROM Fortune x");
|
|
|
|
- List<Fortune> fortunes = q.getResultList();
|
|
|
|
|
|
+ public void generateWorldsForTest() {
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < 10000; i++) {
|
|
|
|
+
|
|
|
|
+ World world = new World();
|
|
|
|
+ world.randomNumber = i; // not really a random number. But we can test with that...
|
|
|
|
+ entitiyManagerProvider.get().persist(world);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ public void generateFortunesForTest() {
|
|
|
|
+
|
|
|
|
|
|
- return fortunes;
|
|
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ Fortune fortune = new Fortune();
|
|
|
|
+ // dummy message => just to make sure utf-8 works.
|
|
|
|
+ fortune.message = "レームワークのベンチマーク";
|
|
|
|
+ entitiyManagerProvider.get().persist(fortune);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ Fortune fortune = new Fortune();
|
|
|
|
+ // dummy message => just to make sure utf-8 works.
|
|
|
|
+ fortune.message = "<script>I want to be escaped</script>";
|
|
|
|
+ entitiyManagerProvider.get().persist(fortune);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|