Ejemplo n.º 1
0
 @Override
 public void deleteHomeInvite(HomeInvite homeInvite) throws StorageException {
   Transaction tx = ebean.beginTransaction();
   tx.setPersistCascade(false);
   ebean.delete(homeInvite, tx);
   tx.commit();
 }
  public void convertNewDatabaseSystem() {
    if (existTable("playerstats")) {
      databaseServer.beginTransaction();
      try {
        final SqlUpdate convert =
            databaseServer.createSqlUpdate(
                "INSERT INTO player_stats "
                    + "(playername, kills, deaths, mobkills, killstreak, last_online) "
                    + "SELECT playername, kills, deaths, mobkills, killstreak, ? "
                    + "FROM playerstats");

        // sql parameters begins with one
        convert.setParameter(1, System.currentTimeMillis());
        final int affectedRows = convert.execute();
        final SqlUpdate dropTable = databaseServer.createSqlUpdate("DROP TABLE playerstats");
        dropTable.execute();
        // a drop have to commited and should be rollbackable if process wasn't complete
        databaseServer.commitTransaction();

        Logger.getLogger("ScoreboardStats")
            .log(Level.INFO, "Successfully converted {0} into new table structure", affectedRows);
      } finally {
        databaseServer.endTransaction();
      }
    }
  }
Ejemplo n.º 3
0
  @Test
  public void testBatch() {
    int rowsNumber = 100;

    EbeanServer server = Ebean.getServer(null);
    Transaction transaction = server.beginTransaction();
    transaction.setBatchMode(true);
    transaction.setBatchSize(30);
    try {
      for (int i = 0; i < rowsNumber; i++) {
        server.save(buildAccount(i));
      }
      server.commitTransaction();
    } finally {
      server.endTransaction();
    }
    List<Account> all = server.find(Account.class).select("name").findList();
    Assert.assertEquals("Batch update", rowsNumber, all.size());
  }
Ejemplo n.º 4
0
 public void createTables() {
   EbeanServer srv = EbeanServerManager.getManager().getServer(databaseName(), CLASSES, true);
   srv.beginTransaction().end();
 }
Ejemplo n.º 5
0
 @Override
 public void saveHomeInvite(HomeInvite homeInvite) {
   Transaction tx = ebean.beginTransaction();
   ebean.save(homeInvite, tx);
   tx.commit();
 }