Skip to content

Commit

Permalink
Experimental optimization for truncate on Oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
henryju committed Jan 15, 2015
1 parent feaf31f commit 1899835
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public final IDataTypeFactory getDbUnitFactory() {

abstract List<String> resetPrimaryKey(String table, int minSequenceValue);

String getTruncateCommand(String table) {
return "TRUNCATE TABLE " + table;
}

public static DatabaseCommands forDialect(Dialect dialect) {
DatabaseCommands command = ImmutableMap.of(
org.sonar.core.persistence.dialect.H2.ID, H2,
Expand Down Expand Up @@ -96,6 +100,11 @@ List<String> resetPrimaryKey(String table, int minSequenceValue) {
"DROP SEQUENCE " + sequence,
"CREATE SEQUENCE " + sequence + " INCREMENT BY 1 MINVALUE 1 START WITH " + minSequenceValue);
}

@Override
String getTruncateCommand(String table) {
return "TRUNCATE TABLE " + table + " REUSE STORAGE";
}
};

private static final DatabaseCommands MSSQL = new DatabaseCommands(new MsSqlDataTypeFactory()) {
Expand Down Expand Up @@ -128,7 +137,7 @@ public void truncateDatabase(DataSource dataSource) throws SQLException {
statement = connection.createStatement();
for (String table : DatabaseVersion.TABLES) {
try {
statement.executeUpdate("TRUNCATE TABLE " + table);
statement.executeUpdate(getTruncateCommand(table));
connection.commit();
} catch (Exception e) {
// ignore
Expand Down

0 comments on commit 1899835

Please sign in to comment.