SetupDao.java 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package hello.controllers;
  2. import hello.model.Fortune;
  3. import java.util.List;
  4. import javax.persistence.EntityManager;
  5. import javax.persistence.Query;
  6. import com.google.inject.Inject;
  7. import com.google.inject.Provider;
  8. import com.google.inject.Singleton;
  9. import com.google.inject.persist.Transactional;
  10. import hello.model.World;
  11. /**
  12. * This class is just for testing.
  13. * Has nothing to do with the TechEmpower test itself...
  14. * @author ra
  15. */
  16. @Singleton
  17. public class SetupDao {
  18. @Inject
  19. Provider<EntityManager> entitiyManagerProvider;
  20. @Transactional
  21. public void generateWorldsForTest() {
  22. for (int i = 0; i < 10000; i++) {
  23. World world = new World();
  24. world.randomNumber = i; // not really a random number. But we can test with that...
  25. entitiyManagerProvider.get().persist(world);
  26. }
  27. }
  28. @Transactional
  29. public void generateFortunesForTest() {
  30. {
  31. Fortune fortune = new Fortune();
  32. // dummy message => just to make sure utf-8 works.
  33. fortune.message = "レームワークのベンチマーク";
  34. entitiyManagerProvider.get().persist(fortune);
  35. }
  36. {
  37. Fortune fortune = new Fortune();
  38. // dummy message => just to make sure utf-8 works.
  39. fortune.message = "<script>I want to be escaped</script>";
  40. entitiyManagerProvider.get().persist(fortune);
  41. }
  42. }
  43. }