Search in sources :

Example 6 with Contexts

use of liquibase.Contexts in project liquibase by liquibase.

the class ChangeLogSyncToTagTask method executeWithLiquibaseClassloader.

@Override
public void executeWithLiquibaseClassloader() throws BuildException {
    Liquibase liquibase = getLiquibase();
    OutputStreamWriter writer = null;
    try {
        FileResource outputFile = getOutputFile();
        if (outputFile != null) {
            writer = new OutputStreamWriter(outputFile.getOutputStream(), getOutputEncoding());
            liquibase.changeLogSync(toTag, new Contexts(getContexts()), getLabels(), writer);
        } else {
            liquibase.changeLogSync(toTag, new Contexts(getContexts()), getLabels());
        }
    } catch (UnsupportedEncodingException e) {
        throw new BuildException("Unable to generate sync SQL. Encoding [" + getOutputEncoding() + "] is not supported.", e);
    } catch (IOException e) {
        throw new BuildException("Unable to generate sync SQL. Error creating output writer.", e);
    } catch (LiquibaseException e) {
        throw new BuildException("Unable to sync change log: " + e.getMessage(), e);
    } finally {
        FileUtils.close(writer);
    }
}
Also used : Liquibase(liquibase.Liquibase) FileResource(org.apache.tools.ant.types.resources.FileResource) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OutputStreamWriter(java.io.OutputStreamWriter) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) LiquibaseException(liquibase.exception.LiquibaseException) Contexts(liquibase.Contexts)

Example 7 with Contexts

use of liquibase.Contexts in project liquibase by liquibase.

the class DatabaseRollbackTask method executeWithLiquibaseClassloader.

@Override
public void executeWithLiquibaseClassloader() throws BuildException {
    Writer writer = null;
    Liquibase liquibase = getLiquibase();
    try {
        FileResource outputFile = getOutputFile();
        if (rollbackCount != null) {
            if (outputFile != null) {
                writer = getOutputFileWriter();
                liquibase.rollback(rollbackCount, rollbackScript, new Contexts(getContexts()), getLabels(), writer);
            } else {
                liquibase.rollback(rollbackCount, rollbackScript, new Contexts(getContexts()), getLabels());
            }
        } else if (rollbackTag != null) {
            if (outputFile != null) {
                writer = getOutputFileWriter();
                liquibase.rollback(rollbackTag, rollbackScript, new Contexts(getContexts()), getLabels(), writer);
            } else {
                liquibase.rollback(rollbackTag, rollbackScript, new Contexts(getContexts()), getLabels());
            }
        } else if (rollbackDate != null) {
            if (outputFile != null) {
                writer = getOutputFileWriter();
                liquibase.rollback(rollbackDate, rollbackScript, new Contexts(getContexts()), getLabels(), writer);
            } else {
                liquibase.rollback(rollbackDate, rollbackScript, new Contexts(getContexts()), getLabels());
            }
        } else {
            throw new BuildException("Unable to rollback database. No count, tag, or date set.");
        }
    } catch (LiquibaseException e) {
        throw new BuildException("Unable to rollback database: " + e.getMessage(), e);
    } catch (UnsupportedEncodingException e) {
        throw new BuildException("Unable to generate rollback SQL. Encoding [" + getOutputEncoding() + "] is not supported.", e);
    } catch (IOException e) {
        throw new BuildException("Unable to generate rollback SQL. Error creating output writer.", e);
    } finally {
        FileUtils.close(writer);
    }
}
Also used : Liquibase(liquibase.Liquibase) FileResource(org.apache.tools.ant.types.resources.FileResource) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BuildException(org.apache.tools.ant.BuildException) LiquibaseException(liquibase.exception.LiquibaseException) IOException(java.io.IOException) Contexts(liquibase.Contexts) Writer(java.io.Writer)

Example 8 with Contexts

use of liquibase.Contexts in project liquibase by liquibase.

the class DatabaseUpdateTask method executeWithLiquibaseClassloader.

@Override
public void executeWithLiquibaseClassloader() throws BuildException {
    Writer writer = null;
    Liquibase liquibase = getLiquibase();
    try {
        FileResource outputFile = getOutputFile();
        if (outputFile != null) {
            writer = getOutputFileWriter();
            liquibase.update(toTag, new Contexts(getContexts()), getLabels(), writer);
        } else {
            if (dropFirst) {
                liquibase.dropAll();
            }
            liquibase.update(toTag, new Contexts(getContexts()), getLabels());
        }
    } catch (LiquibaseException e) {
        throw new BuildException("Unable to update database: " + e.getMessage(), e);
    } catch (UnsupportedEncodingException e) {
        throw new BuildException("Unable to generate update SQL. Encoding [" + getOutputEncoding() + "] is not supported.", e);
    } catch (IOException e) {
        throw new BuildException("Unable to generate update SQL. Error creating output writer.", e);
    } finally {
        FileUtils.close(writer);
    }
}
Also used : Liquibase(liquibase.Liquibase) FileResource(org.apache.tools.ant.types.resources.FileResource) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LiquibaseException(liquibase.exception.LiquibaseException) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) Contexts(liquibase.Contexts) Writer(java.io.Writer)

Example 9 with Contexts

use of liquibase.Contexts in project liquibase by liquibase.

the class LiquibaseChangeLogSyncMojo method performLiquibaseTask.

@Override
protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseException {
    super.performLiquibaseTask(liquibase);
    liquibase.changeLogSync(new Contexts(contexts), new LabelExpression(labels));
}
Also used : LabelExpression(liquibase.LabelExpression) Contexts(liquibase.Contexts)

Example 10 with Contexts

use of liquibase.Contexts in project liquibase by liquibase.

the class ChangeLogParametersTest method setParameterValue_rightDBRightContext.

@Test
public void setParameterValue_rightDBRightContext() {
    ChangeLogParameters changeLogParameters = new ChangeLogParameters(new H2Database());
    changeLogParameters.setContexts(new Contexts("junit"));
    changeLogParameters.set("doubleSet", "originalValue", "junit", "junitLabel", "baddb, h2", true, null);
    assertEquals("originalValue", changeLogParameters.getValue("doubleSet", null));
}
Also used : H2Database(liquibase.database.core.H2Database) Contexts(liquibase.Contexts) Test(org.junit.Test)

Aggregations

Contexts (liquibase.Contexts)32 Test (org.junit.Test)18 Liquibase (liquibase.Liquibase)16 ChangeSet (liquibase.changelog.ChangeSet)12 LabelExpression (liquibase.LabelExpression)10 LiquibaseException (liquibase.exception.LiquibaseException)8 IOException (java.io.IOException)5 Database (liquibase.database.Database)5 BuildException (org.apache.tools.ant.BuildException)5 FileResource (org.apache.tools.ant.types.resources.FileResource)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 RuntimeEnvironment (liquibase.RuntimeEnvironment)4 Writer (java.io.Writer)3 Connection (java.sql.Connection)3 ContextChangeSetFilter (liquibase.changelog.filter.ContextChangeSetFilter)3 JdbcConnection (liquibase.database.jvm.JdbcConnection)3 FileSystemResourceAccessor (liquibase.resource.FileSystemResourceAccessor)3 ResourceAccessor (liquibase.resource.ResourceAccessor)3 OutputStreamWriter (java.io.OutputStreamWriter)2 SQLException (java.sql.SQLException)2