import org.dbunit.ext.postgresql.PostgresqlDataTypeFactory;
import org.sonar.jpa.dialect.*;
+import java.util.Arrays;
+import java.util.List;
+
abstract class DatabaseCommands {
private IDataTypeFactory dbUnitFactory;
abstract String truncate(String table);
- abstract String resetPrimaryKey(String table);
+ abstract List<String> resetPrimaryKey(String table);
final IDataTypeFactory dbUnitFactory() {
return dbUnitFactory;
}
@Override
- String resetPrimaryKey(String table) {
- return "ALTER TABLE " + table + " ALTER COLUMN ID RESTART WITH 1";
+ List<String> resetPrimaryKey(String table) {
+ return Arrays.asList("ALTER TABLE " + table + " ALTER COLUMN ID RESTART WITH 1");
}
};
}
@Override
- String resetPrimaryKey(String table) {
- return "DBCC CHECKIDENT('" + table + "', RESEED, 1)";
+ List<String> resetPrimaryKey(String table) {
+ return Arrays.asList("DBCC CHECKIDENT('" + table + "', RESEED, 1)");
}
};
}
@Override
- String resetPrimaryKey(String table) {
- return "ALTER TABLE " + table + " AUTO_INCREMENT = 1";
+ List<String> resetPrimaryKey(String table) {
+ return Arrays.asList("ALTER TABLE " + table + " AUTO_INCREMENT = 1");
}
};
}
@Override
- String resetPrimaryKey(String table) {
- return "ALTER SEQUENCE " + table + "_SEQ INCREMENT BY 1 MINVALUE 1";
+ List<String> resetPrimaryKey(String table) {
+ return Arrays.asList(
+ "DROP SEQUENCE " + table + "_SEQ",
+ "CREATE SEQUENCE " + table + "_SEQ INCREMENT BY 1 MINVALUE 1 START WITH 1 NOORDER CACHE"
+ );
}
};
}
@Override
- String resetPrimaryKey(String table) {
- return "ALTER SEQUENCE " + table + "_id_seq RESTART WITH 1";
+ List<String> resetPrimaryKey(String table) {
+ return Arrays.asList("ALTER SEQUENCE " + table + "_id_seq RESTART WITH 1");
}
};