World.java 939 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package models;
  2. import play.db.jpa.JPA;
  3. import javax.persistence.Column;
  4. import javax.persistence.Entity;
  5. import javax.persistence.Id;
  6. import java.util.List;
  7. @Entity
  8. public class World {
  9. @Id
  10. public Long id;
  11. @Column(name = "randomNumber")
  12. public Long randomNumber;
  13. public static World findById(final Long id) throws Throwable {
  14. return JPA.withTransaction("default", true, new play.libs.F.Function0<World>() {
  15. public World apply() {
  16. return JPA.em().find(World.class, id);
  17. }
  18. });
  19. }
  20. public static List<World> save(final List<World> worlds) throws Throwable {
  21. for (final World world : worlds) {
  22. JPA.withTransaction("default", false, new play.libs.F.Function0<World>() {
  23. public World apply() {
  24. return JPA.em().merge(world);
  25. }
  26. });
  27. }
  28. return worlds;
  29. }
  30. }