Search in sources :

Example 26 with LiquibaseException

use of liquibase.exception.LiquibaseException in project liquibase by liquibase.

the class LiquibaseGenerateChangeLogMojo method performLiquibaseTask.

@Override
protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseException {
    ClassLoader cl = null;
    try {
        cl = getClassLoaderIncludingProjectClasspath();
        Thread.currentThread().setContextClassLoader(cl);
    } catch (MojoExecutionException e) {
        throw new LiquibaseException("Could not create the class loader, " + e, e);
    }
    Database database = liquibase.getDatabase();
    getLog().info("Generating Change Log from database " + database.toString());
    try {
        DiffOutputControl diffOutputControl = new DiffOutputControl(outputDefaultCatalog, outputDefaultSchema, true, null);
        if (diffExcludeObjects != null && diffIncludeObjects != null) {
            throw new UnexpectedLiquibaseException("Cannot specify both excludeObjects and includeObjects");
        }
        if (diffExcludeObjects != null) {
            diffOutputControl.setObjectChangeFilter(new StandardObjectChangeFilter(StandardObjectChangeFilter.FilterType.EXCLUDE, diffExcludeObjects));
        }
        if (diffIncludeObjects != null) {
            diffOutputControl.setObjectChangeFilter(new StandardObjectChangeFilter(StandardObjectChangeFilter.FilterType.INCLUDE, diffIncludeObjects));
        }
        CommandLineUtils.doGenerateChangeLog(outputChangeLogFile, database, defaultCatalogName, defaultSchemaName, StringUtils.trimToNull(diffTypes), StringUtils.trimToNull(changeSetAuthor), StringUtils.trimToNull(changeSetContext), StringUtils.trimToNull(dataDir), diffOutputControl);
        getLog().info("Output written to Change Log file, " + outputChangeLogFile);
    } catch (IOException e) {
        throw new LiquibaseException(e);
    } catch (ParserConfigurationException e) {
        throw new LiquibaseException(e);
    }
}
Also used : StandardObjectChangeFilter(liquibase.diff.output.StandardObjectChangeFilter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Database(liquibase.database.Database) DiffOutputControl(liquibase.diff.output.DiffOutputControl) LiquibaseException(liquibase.exception.LiquibaseException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 27 with LiquibaseException

use of liquibase.exception.LiquibaseException in project liquibase by liquibase.

the class DropAllTask method executeWithLiquibaseClassloader.

@Override
public void executeWithLiquibaseClassloader() throws BuildException {
    Liquibase liquibase = getLiquibase();
    try {
        if (StringUtils.trimToNull(schemas) != null) {
            List<String> schemaNames = StringUtils.splitAndTrim(this.schemas, ",");
            List<CatalogAndSchema> schemas = new ArrayList<CatalogAndSchema>();
            for (String name : schemaNames) {
                schemas.add(new CatalogAndSchema(catalog, name));
            }
            liquibase.dropAll(schemas.toArray(new CatalogAndSchema[schemas.size()]));
        } else {
            liquibase.dropAll();
        }
    } catch (LiquibaseException e) {
        throw new BuildException("Unable to drop all objects from database. " + e.toString(), e);
    }
}
Also used : Liquibase(liquibase.Liquibase) ArrayList(java.util.ArrayList) LiquibaseException(liquibase.exception.LiquibaseException) BuildException(org.apache.tools.ant.BuildException) CatalogAndSchema(liquibase.CatalogAndSchema)

Example 28 with LiquibaseException

use of liquibase.exception.LiquibaseException in project liquibase by liquibase.

the class MarkNextChangeSetRanTask method executeWithLiquibaseClassloader.

@Override
public void executeWithLiquibaseClassloader() throws BuildException {
    Liquibase liquibase = getLiquibase();
    Writer writer = null;
    try {
        FileResource outputFile = getOutputFile();
        if (outputFile != null) {
            writer = getOutputFileWriter();
            liquibase.markNextChangeSetRan(new Contexts(getContexts()), getLabels(), writer);
        } else {
            liquibase.markNextChangeSetRan(new Contexts(getContexts()), getLabels());
        }
    } catch (LiquibaseException e) {
        throw new BuildException("Unable to mark next changeset as ran. " + e.toString(), e);
    } catch (IOException e) {
        throw new BuildException("Unable to mark next changeset as ran. Error creating output writer.", e);
    } finally {
        FileUtils.close(writer);
    }
}
Also used : Liquibase(liquibase.Liquibase) FileResource(org.apache.tools.ant.types.resources.FileResource) LiquibaseException(liquibase.exception.LiquibaseException) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) Contexts(liquibase.Contexts) Writer(java.io.Writer)

Example 29 with LiquibaseException

use of liquibase.exception.LiquibaseException in project liquibase by liquibase.

the class Liquibase method reportUnexpectedChangeSets.

public void reportUnexpectedChangeSets(boolean verbose, Contexts contexts, LabelExpression labelExpression, Writer out) throws LiquibaseException {
    changeLogParameters.setContexts(contexts);
    changeLogParameters.setLabels(labelExpression);
    try {
        Collection<RanChangeSet> unexpectedChangeSets = listUnexpectedChangeSets(contexts, labelExpression);
        if (unexpectedChangeSets.size() == 0) {
            out.append(getDatabase().getConnection().getConnectionUserName());
            out.append("@");
            out.append(getDatabase().getConnection().getURL());
            out.append(" contains no unexpected changes!");
            out.append(StreamUtil.getLineSeparator());
        } else {
            out.append(String.valueOf(unexpectedChangeSets.size()));
            out.append(" unexpected changes were found in ");
            out.append(getDatabase().getConnection().getConnectionUserName());
            out.append("@");
            out.append(getDatabase().getConnection().getURL());
            out.append(StreamUtil.getLineSeparator());
            if (verbose) {
                for (RanChangeSet ranChangeSet : unexpectedChangeSets) {
                    out.append("     ").append(ranChangeSet.toString()).append(StreamUtil.getLineSeparator());
                }
            }
        }
        out.flush();
    } catch (IOException e) {
        throw new LiquibaseException(e);
    }
}
Also used : UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) LiquibaseException(liquibase.exception.LiquibaseException)

Example 30 with LiquibaseException

use of liquibase.exception.LiquibaseException in project liquibase by liquibase.

the class Liquibase method update.

public void update(int changesToApply, Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException {
    changeLogParameters.setContexts(contexts);
    changeLogParameters.setLabels(labelExpression);
    Executor oldTemplate = ExecutorService.getInstance().getExecutor(database);
    LoggingExecutor loggingExecutor = new LoggingExecutor(ExecutorService.getInstance().getExecutor(database), output, database);
    ExecutorService.getInstance().setExecutor(database, loggingExecutor);
    outputHeader("Update " + changesToApply + " Change Sets Database Script");
    update(changesToApply, contexts, labelExpression);
    try {
        output.flush();
    } catch (IOException e) {
        throw new LiquibaseException(e);
    }
    resetServices();
    ExecutorService.getInstance().setExecutor(database, oldTemplate);
}
Also used : Executor(liquibase.executor.Executor) LoggingExecutor(liquibase.executor.LoggingExecutor) LoggingExecutor(liquibase.executor.LoggingExecutor) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) LiquibaseException(liquibase.exception.LiquibaseException)

Aggregations

LiquibaseException (liquibase.exception.LiquibaseException)38 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)23 Executor (liquibase.executor.Executor)12 Liquibase (liquibase.Liquibase)10 LoggingExecutor (liquibase.executor.LoggingExecutor)10 BuildException (org.apache.tools.ant.BuildException)8 IOException (java.io.IOException)7 Database (liquibase.database.Database)7 Contexts (liquibase.Contexts)6 DatabaseException (liquibase.exception.DatabaseException)5 ArrayList (java.util.ArrayList)4 ResourceAccessor (liquibase.resource.ResourceAccessor)4 FileResource (org.apache.tools.ant.types.resources.FileResource)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Writer (java.io.Writer)3 CatalogAndSchema (liquibase.CatalogAndSchema)3 OracleDatabase (liquibase.database.core.OracleDatabase)3 DiffOutputControl (liquibase.diff.output.DiffOutputControl)3 Test (org.junit.Test)3 File (java.io.File)2