Search in sources :

Example 86 with Liquibase

use of liquibase.Liquibase 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.getMessage(), 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 87 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class GenerateChangeLogTask method executeWithLiquibaseClassloader.

@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) {
            throw new BuildException("Unable to generate a change log. Error configuring parser.", e);
        } catch (DatabaseException e) {
            throw new BuildException("Unable to generate a change log: " + e.getMessage(), e);
        } finally {
            FileUtils.close(printStream);
        }
    }
}
Also used : PrintStream(java.io.PrintStream) FileResource(org.apache.tools.ant.types.resources.FileResource) DiffOutputControl(liquibase.diff.output.DiffOutputControl) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ChangeLogSerializer(liquibase.serializer.ChangeLogSerializer) JsonChangeLogSerializer(liquibase.serializer.core.json.JsonChangeLogSerializer) StringChangeLogSerializer(liquibase.serializer.core.string.StringChangeLogSerializer) IOException(java.io.IOException) CatalogAndSchema(liquibase.CatalogAndSchema) ChangeLogOutputFile(liquibase.integration.ant.type.ChangeLogOutputFile) Liquibase(liquibase.Liquibase) Database(liquibase.database.Database) DiffToChangeLog(liquibase.diff.output.changelog.DiffToChangeLog) BuildException(org.apache.tools.ant.BuildException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DatabaseException(liquibase.exception.DatabaseException)

Example 88 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class OracleIntegrationTest method indexCreatedOnCorrectSchema.

@Test
public void indexCreatedOnCorrectSchema() throws Exception {
    assumeNotNull(this.getDatabase());
    Liquibase liquibase = createLiquibase(this.indexOnSchemaChangeLog);
    clearDatabase();
    try {
        liquibase.update(this.contexts);
    } catch (ValidationFailedException e) {
        e.printDescriptiveError(System.out);
        throw e;
    }
    Statement queryIndex = ((JdbcConnection) this.getDatabase().getConnection()).getUnderlyingConnection().createStatement();
    ResultSet indexOwner = queryIndex.executeQuery("SELECT owner FROM ALL_INDEXES WHERE index_name = 'IDX_BOOK_ID'");
    assertTrue(indexOwner.next());
    String owner = indexOwner.getString("owner");
    assertEquals("LBCAT2", owner);
    // check that the automatically rollback now works too
    try {
        liquibase.rollback(new Date(0), this.contexts);
    } catch (ValidationFailedException e) {
        e.printDescriptiveError(System.out);
        throw e;
    }
}
Also used : Liquibase(liquibase.Liquibase) ValidationFailedException(liquibase.exception.ValidationFailedException) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) Date(java.util.Date) Test(org.junit.Test) AbstractIntegrationTest(liquibase.dbtest.AbstractIntegrationTest)

Example 89 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class OracleIntegrationTest method sqlplusChangelog.

@Test
public void sqlplusChangelog() throws Exception {
    Database database = this.getDatabase();
    assumeNotNull(database);
    Liquibase liquibase = createLiquibase(this.customExecutorChangeLog);
    clearDatabase();
    // 
    // Add a visitor so we can assert
    // 
    DatabaseChangeLog changeLog = liquibase.getDatabaseChangeLog();
    for (ChangeSet changeSet : changeLog.getChangeSets()) {
        changeSet.addSqlVisitor(new TestSqlVisitor());
    }
    try {
        liquibase.update(this.contexts);
    } catch (ValidationFailedException e) {
        e.printDescriptiveError(System.out);
        throw e;
    }
    database.commit();
}
Also used : Liquibase(liquibase.Liquibase) ValidationFailedException(liquibase.exception.ValidationFailedException) Database(liquibase.database.Database) ChangeSet(liquibase.changelog.ChangeSet) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) Test(org.junit.Test) AbstractIntegrationTest(liquibase.dbtest.AbstractIntegrationTest)

Example 90 with Liquibase

use of liquibase.Liquibase in project liquibase by liquibase.

the class OracleIntegrationTest method testHubChangelog.

@Test
public void testHubChangelog() throws Exception {
    assumeNotNull(this.getDatabase());
    Liquibase liquibase = createLiquibase(this.hubTestChangelog);
    clearDatabase();
    try {
        liquibase.update(this.contexts);
    } catch (ValidationFailedException e) {
        e.printDescriptiveError(System.out);
        throw e;
    }
}
Also used : Liquibase(liquibase.Liquibase) ValidationFailedException(liquibase.exception.ValidationFailedException) Test(org.junit.Test) AbstractIntegrationTest(liquibase.dbtest.AbstractIntegrationTest)

Aggregations

Liquibase (liquibase.Liquibase)125 LiquibaseException (liquibase.exception.LiquibaseException)37 JdbcConnection (liquibase.database.jvm.JdbcConnection)35 Database (liquibase.database.Database)33 ClassLoaderResourceAccessor (liquibase.resource.ClassLoaderResourceAccessor)33 Test (org.junit.Test)30 IOException (java.io.IOException)27 Contexts (liquibase.Contexts)24 SQLException (java.sql.SQLException)23 ResourceAccessor (liquibase.resource.ResourceAccessor)14 ChangeSet (liquibase.changelog.ChangeSet)13 DatabaseException (liquibase.exception.DatabaseException)12 ValidationFailedException (liquibase.exception.ValidationFailedException)12 LabelExpression (liquibase.LabelExpression)11 Connection (java.sql.Connection)10 AbstractIntegrationTest (liquibase.dbtest.AbstractIntegrationTest)10 FileSystemResourceAccessor (liquibase.resource.FileSystemResourceAccessor)10 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 BuildException (org.apache.tools.ant.BuildException)10 LockException (liquibase.exception.LockException)9