World.java 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package models;
  2. import java.util.List;
  3. import javax.persistence.Column;
  4. import javax.persistence.Entity;
  5. import javax.persistence.Id;
  6. import io.ebean.Finder;
  7. import io.ebean.Model;
  8. import io.ebean.Transaction;
  9. @Entity
  10. public class World extends Model {
  11. private static final Finder<Long, World> find = new Finder<>(World.class);
  12. @Id
  13. public Long id;
  14. @Column(name = "randomNumber")
  15. public Long randomNumber;
  16. public static World find(final Long id) {
  17. return find.byId(id);
  18. }
  19. public static List<World> save(final List<World> worlds) {
  20. final int batchSize = 25;
  21. final int batches = ((worlds.size() / batchSize) + 1);
  22. for ( int i = 0 ; i < batches ; ++i ) {
  23. final Transaction transaction = World.db().beginTransaction();
  24. try {
  25. transaction.setBatchMode(true);
  26. transaction.setBatchSize(batchSize);
  27. for(int j = i * batchSize ; j < Math.min((i + 1) * batchSize, worlds.size()); ++j) {
  28. World.db().update(worlds.get(j), transaction);
  29. }
  30. transaction.commit();
  31. } finally {
  32. transaction.end();
  33. }
  34. }
  35. return worlds;
  36. }
  37. }