return dbUnitFactory;
}
- abstract List<String> resetPrimaryKey(String table, int minSequenceValue);
+ abstract List<String> resetSequenceSql(String table, int minSequenceValue);
- String getTruncateCommand(String table) {
+ String truncateSql(String table) {
return "TRUNCATE TABLE " + table;
}
+ boolean useLoginAsSchema() {
+ return false;
+ }
+
public static DatabaseCommands forDialect(Dialect dialect) {
DatabaseCommands command = ImmutableMap.of(
org.sonar.core.persistence.dialect.H2.ID, H2,
private static final DatabaseCommands H2 = new DatabaseCommands(new H2DataTypeFactory()) {
@Override
- List<String> resetPrimaryKey(String table, int minSequenceValue) {
+ List<String> resetSequenceSql(String table, int minSequenceValue) {
return Arrays.asList("ALTER TABLE " + table + " ALTER COLUMN ID RESTART WITH " + minSequenceValue);
}
};
private static final DatabaseCommands POSTGRESQL = new DatabaseCommands(new PostgresqlDataTypeFactory()) {
@Override
- List<String> resetPrimaryKey(String table, int minSequenceValue) {
+ List<String> resetSequenceSql(String table, int minSequenceValue) {
return Arrays.asList("ALTER SEQUENCE " + table + "_id_seq RESTART WITH " + minSequenceValue);
}
};
private static final DatabaseCommands ORACLE = new DatabaseCommands(new Oracle10DataTypeFactory()) {
@Override
- List<String> resetPrimaryKey(String table, int minSequenceValue) {
+ List<String> resetSequenceSql(String table, int minSequenceValue) {
String sequence = StringUtils.upperCase(table) + "_SEQ";
return Arrays.asList(
"DROP SEQUENCE " + sequence,
}
@Override
- String getTruncateCommand(String table) {
+ String truncateSql(String table) {
return "TRUNCATE TABLE " + table + " REUSE STORAGE";
}
+
+ @Override
+ boolean useLoginAsSchema() {
+ return true;
+ }
};
private static final DatabaseCommands MSSQL = new DatabaseCommands(new MsSqlDataTypeFactory()) {
}
@Override
- List<String> resetPrimaryKey(String table, int minSequenceValue) {
+ List<String> resetSequenceSql(String table, int minSequenceValue) {
return null;
}
}
@Override
- List<String> resetPrimaryKey(String table, int minSequenceValue) {
+ List<String> resetSequenceSql(String table, int minSequenceValue) {
return null;
}
};
for (String table : DatabaseVersion.TABLES) {
try {
if (shouldTruncate(connection, table)) {
- statement.executeUpdate(getTruncateCommand(table));
+ statement.executeUpdate(truncateSql(table));
connection.commit();
}
} catch (Exception e) {
int maxId = result.getInt(1);
result.close();
- for (String resetCommand : resetPrimaryKey(table, maxId)) {
+ for (String resetCommand : resetSequenceSql(table, maxId)) {
statement.executeUpdate(resetCommand);
}
connection.commit();