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(); } } }
@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()); }