Search in sources :

Example 6 with RawSQLChange

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;
}
Also used : RawSQLChange(liquibase.change.core.RawSQLChange) InputStream(java.io.InputStream) ChangeLogParseException(liquibase.exception.ChangeLogParseException) IOException(java.io.IOException) ChangeSet(liquibase.changelog.ChangeSet) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog)

Example 7 with RawSQLChange

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();
}
Also used : RawSQLChange(liquibase.change.core.RawSQLChange) Executor(liquibase.executor.Executor) LoggingExecutor(liquibase.executor.LoggingExecutor) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) LiquibaseException(liquibase.exception.LiquibaseException) DatabaseException(liquibase.exception.DatabaseException)

Aggregations

RawSQLChange (liquibase.change.core.RawSQLChange)7 IOException (java.io.IOException)3 EmptyChange (liquibase.change.core.EmptyChange)2 ChangeSet (liquibase.changelog.ChangeSet)2 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)2 ChangeLogParseException (liquibase.exception.ChangeLogParseException)2 DatabaseException (liquibase.exception.DatabaseException)2 Executor (liquibase.executor.Executor)2 LoggingExecutor (liquibase.executor.LoggingExecutor)2 BufferedReader (java.io.BufferedReader)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Labels (liquibase.Labels)1 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)1 LiquibaseException (liquibase.exception.LiquibaseException)1 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)1 ExecutorService (liquibase.executor.ExecutorService)1 HubChangeExecListener (liquibase.hub.listener.HubChangeExecListener)1