Package liquibase

Examples of liquibase.Liquibase


            ResourceAccessor fsFO = new FileSystemResourceAccessor();


            database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
            database.setDefaultSchemaName(getDefaultSchema());
            Liquibase liquibase = new Liquibase(getChangeLogFile(), new CompositeResourceAccessor(clFO, fsFO, threadClFO), database);

            @SuppressWarnings("unchecked")
            Enumeration<String> initParameters = servletContext.getInitParameterNames();
            while (initParameters.hasMoreElements()) {
                String name = initParameters.nextElement().trim();
                if (name.startsWith(LIQUIBASE_PARAMETER + ".")) {
                    liquibase.setChangeLogParameter(name.substring(LIQUIBASE_PARAMETER.length()), servletValueContainer.getValue(name));
                }
            }

            liquibase.update(new Contexts(getContexts()), new LabelExpression(getLabels()));
        }
        finally {
            if (database != null) {
                database.close();
            } else if (connection != null) {
View Full Code Here


    private String schemas;
    private String catalog;

    @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);
        }
    }
View Full Code Here

import java.io.IOException;

public class DatabaseRollbackFutureTask extends AbstractChangeLogBasedTask {
    @Override
    public void executeWithLiquibaseClassloader() throws BuildException {
        Liquibase liquibase = getLiquibase();
        try {
            liquibase.futureRollbackSQL(null, new Contexts(getContexts()), getLabels(), getOutputFileWriter());
        } catch (LiquibaseException e) {
            throw new BuildException("Unable to generate future rollback SQL.", e);
        } catch (IOException e) {
            throw new BuildException("Unable to generate future rollback SQL. Error creating output writer.", e);
        }
View Full Code Here

    private boolean dropFirst = false;

    @Override
    public void executeWithLiquibaseClassloader() throws BuildException {
        Writer writer = null;
        Liquibase liquibase = getLiquibase();
        try {
            FileResource outputFile = getOutputFile();
            if(outputFile != null) {
                writer = getOutputFileWriter();
                liquibase.update(new Contexts(getContexts()), getLabels(), writer);
            } else {
                if(dropFirst) {
                    liquibase.dropAll();
                }
                liquibase.update(new Contexts(getContexts()), getLabels());
            }
        } catch (LiquibaseException e) {
            throw new BuildException("Unable to update database.", e);
        } catch (UnsupportedEncodingException e) {
            throw new BuildException("Unable to generate update SQL. Encoding [" + getOutputEncoding() + "] is not supported.", e);
View Full Code Here

public class TagDatabaseTask extends BaseLiquibaseTask {
    private String tag;

    @Override
    public void executeWithLiquibaseClassloader() throws BuildException {
        Liquibase liquibase = getLiquibase();
        try {
            liquibase.tag(tag);
        } catch (LiquibaseException e) {
            throw new BuildException("Unable to tag database.", e);
        }
    }
View Full Code Here

public class DatabaseUpdateTestingRollbackTask extends AbstractChangeLogBasedTask {
    private boolean dropFirst = false;

    @Override
    public void executeWithLiquibaseClassloader() throws BuildException {
        Liquibase liquibase = getLiquibase();
        try {
            if (isDropFirst()) {
                liquibase.dropAll();
            }
            liquibase.updateTestingRollback(new Contexts(getContexts()), getLabels());
        } catch (LiquibaseException e) {
            throw new BuildException("Unable to update database with a rollback test.", e);
        }
    }
View Full Code Here

import java.io.Writer;

public class MarkNextChangeSetRanTask extends AbstractChangeLogBasedTask {
    @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);
        } catch (IOException e) {
            throw new BuildException("Unable to mark next changeset as ran. Error creating output writer.", e);
View Full Code Here

public abstract class AbstractDatabaseDiffTask extends BaseLiquibaseTask {
    private DatabaseType referenceDatabaseType;
    private String diffTypes;

    protected DiffResult getDiffResult() {
        Liquibase liquibase = getLiquibase();
        Database targetDatabase = liquibase.getDatabase();
        Database referenceDatabase = createDatabaseFromType(referenceDatabaseType);

        CatalogAndSchema targetCatalogAndSchema = buildCatalogAndSchema(targetDatabase);
        CatalogAndSchema referenceCatalogAndSchema = buildCatalogAndSchema(referenceDatabase);
        CompareControl.SchemaComparison[] schemaComparisons = {
                new CompareControl.SchemaComparison(referenceCatalogAndSchema, targetCatalogAndSchema)
        };

        SnapshotGeneratorFactory snapshotGeneratorFactory = SnapshotGeneratorFactory.getInstance();
        DatabaseSnapshot referenceSnapshot;
        try {
            referenceSnapshot = snapshotGeneratorFactory.createSnapshot(referenceDatabase.getDefaultSchema(),
                    referenceDatabase, new SnapshotControl(referenceDatabase, diffTypes));
        } catch (LiquibaseException e) {
            throw new BuildException("Unable to create a DatabaseSnapshot.", e);
        }

        CompareControl compareControl = new CompareControl(schemaComparisons, referenceSnapshot.getSnapshotControl().getTypesToInclude());

        try {
            return liquibase.diff(referenceDatabase, targetDatabase, compareControl);
        } catch (LiquibaseException e) {
            throw new BuildException("Unable to diff databases.", e);
        }
    }
View Full Code Here

    private boolean includeCatalog = true;
    private boolean includeTablespace = true;

    @Override
  public void executeWithLiquibaseClassloader() throws BuildException {
        Liquibase liquibase = getLiquibase();
        Database database = liquibase.getDatabase();
        CatalogAndSchema catalogAndSchema = buildCatalogAndSchema(database);
        DiffOutputControl diffOutputControl = getDiffOutputControl();
        DiffToChangeLog diffToChangeLog = new DiffToChangeLog(diffOutputControl);

        for(ChangeLogOutputFile changeLogOutputFile : changeLogOutputFiles) {
            String encoding = getOutputEncoding(changeLogOutputFile);
            PrintStream printStream = null;
            try {
                FileResource outputFile = changeLogOutputFile.getOutputFile();
                ChangeLogSerializer changeLogSerializer = changeLogOutputFile.getChangeLogSerializer();
                log("Writing change log file " + outputFile.toString(), Project.MSG_INFO);
                printStream = new PrintStream(outputFile.getOutputStream(), true, encoding);
                liquibase.generateChangeLog(catalogAndSchema, diffToChangeLog, printStream, changeLogSerializer);
            } catch (UnsupportedEncodingException e) {
                throw new BuildException("Unable to generate a change log. Encoding [" + encoding + "] is not supported.", e);
            } catch (IOException e) {
                throw new BuildException("Unable to generate a change log. Error creating output stream.", e);
            } catch (ParserConfigurationException e) {
View Full Code Here

import java.io.UnsupportedEncodingException;

public class ChangeLogSyncTask extends AbstractChangeLogBasedTask {
    @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(new Contexts(getContexts()), getLabels(), writer);
            } else {
                liquibase.changeLogSync(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);
View Full Code Here

TOP

Related Classes of liquibase.Liquibase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.