use of liquibase.util.csv.CSVReader in project liquibase by liquibase.
the class OfflineChangeLogHistoryService method replaceChangeSet.
protected void replaceChangeSet(ChangeSet changeSet, ReplaceChangeSetLogic replaceLogic) throws DatabaseException {
File oldFile = this.changeLogFile;
File newFile = new File(oldFile.getParentFile(), oldFile.getName() + ".new");
Reader reader = null;
Writer writer = null;
try {
reader = new InputStreamReader(new FileInputStream(oldFile), LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding());
writer = new OutputStreamWriter(new FileOutputStream(newFile), LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding());
CSVReader csvReader = new CSVReader(reader);
CSVWriter csvWriter = new CSVWriter(writer);
String[] line;
while ((line = csvReader.readNext()) != null) {
if (changeSet == null || (line[COLUMN_ID].equals(changeSet.getId()) && line[COLUMN_AUTHOR].equals(changeSet.getAuthor()) && line[COLUMN_FILENAME].equals(changeSet.getFilePath()))) {
line = replaceLogic.execute(line);
}
if (line != null) {
csvWriter.writeNext(line);
}
}
csvWriter.flush();
csvWriter.close();
writer = null;
csvReader.close();
reader = null;
oldFile.delete();
newFile.renameTo(oldFile);
} catch (Exception e) {
throw new DatabaseException(e);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ignore) {
}
}
if (writer != null) {
try {
writer.flush();
writer.close();
} catch (IOException ignore) {
}
}
}
}
Aggregations