use of liquibase.change.core.RawSQLChange in project liquibase by liquibase.
the class SqlChangeLogParser method parse.
@Override
public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor) throws ChangeLogParseException {
DatabaseChangeLog changeLog = new DatabaseChangeLog();
changeLog.setPhysicalFilePath(physicalChangeLogLocation);
RawSQLChange change = new RawSQLChange();
try {
InputStream sqlStream = resourceAccessor.openStream(null, physicalChangeLogLocation);
if (sqlStream != null) {
String sql = StreamUtil.readStreamAsString(sqlStream);
change.setSql(sql);
} else {
throw new ChangeLogParseException(FileUtil.getFileNotFoundMessage(physicalChangeLogLocation));
}
} catch (IOException e) {
throw new ChangeLogParseException(e);
}
change.setSplitStatements(false);
change.setStripComments(false);
ChangeSet changeSet = new ChangeSet("raw", "includeAll", false, false, physicalChangeLogLocation, null, null, true, ObjectQuotingStrategy.LEGACY, changeLog);
changeSet.addChange(change);
changeLog.addChangeSet(changeSet);
return changeLog;
}
use of liquibase.change.core.RawSQLChange in project liquibase by liquibase.
the class Liquibase method executeRollbackScript.
protected void executeRollbackScript(String rollbackScript, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException {
final Executor executor = ExecutorService.getInstance().getExecutor(database);
String rollbackScriptContents;
try {
Set<InputStream> streams = resourceAccessor.getResourcesAsStream(rollbackScript);
if (streams == null || streams.size() == 0) {
throw new LiquibaseException("Cannot find rollbackScript " + rollbackScript);
} else if (streams.size() > 1) {
throw new LiquibaseException("Found multiple rollbackScripts named " + rollbackScript);
}
rollbackScriptContents = StreamUtil.getStreamContents(streams.iterator().next());
} catch (IOException e) {
throw new LiquibaseException("Error reading rollbackScript " + executor + ": " + e.getMessage());
}
RawSQLChange rollbackChange = new RawSQLChange(rollbackScriptContents);
rollbackChange.setSplitStatements(true);
rollbackChange.setStripComments(true);
try {
executor.execute(rollbackChange);
} catch (DatabaseException e) {
e = new DatabaseException("Error executing rollback script. ChangeSets will still be marked as rolled back: " + e.getMessage(), e);
System.err.println(e.getMessage());
log.severe("Error executing rollback script", e);
if (changeExecListener != null) {
changeExecListener.runFailed(null, databaseChangeLog, database, e);
}
}
database.commit();
}
Aggregations