Search in sources :

Example 56 with ChangeSet

use of liquibase.changelog.ChangeSet in project liquibase by liquibase.

the class XMLChangeLogSerializer method createNode.

public Element createNode(LiquibaseSerializable object) {
    String namespace = object.getSerializedObjectNamespace();
    String nodeName = object.getSerializedObjectName();
    NamespaceDetails details = NamespaceDetailsFactory.getInstance().getNamespaceDetails(this, namespace);
    if ((details != null) && !"".equals(details.getShortName(namespace))) {
        nodeName = details.getShortName(namespace) + ":" + nodeName;
    }
    Element node = currentChangeLogFileDOM.createElementNS(namespace, nodeName);
    try {
        for (String field : object.getSerializableFields()) {
            setValueOnNode(node, object.getSerializableFieldNamespace(field), field, object.getSerializableFieldValue(field), object.getSerializableFieldType(field), namespace);
        }
    } catch (UnexpectedLiquibaseException e) {
        if (object instanceof ChangeSet && e.getMessage().startsWith(INVALID_STRING_ENCODING_MESSAGE)) {
            throw new UnexpectedLiquibaseException(e.getMessage() + " in changeSet " + ((ChangeSet) object).toString(false) + ". To resolve, remove the invalid character on the database and try again");
        }
        throw e;
    }
    return node;
}
Also used : NamespaceDetails(liquibase.parser.NamespaceDetails) Element(org.w3c.dom.Element) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) ChangeSet(liquibase.changelog.ChangeSet)

Example 57 with ChangeSet

use of liquibase.changelog.ChangeSet in project liquibase by liquibase.

the class FormattedSqlChangeLogSerializer method serialize.

@Override
public String serialize(LiquibaseSerializable object, boolean pretty) {
    if (object instanceof ChangeSet) {
        // 
        // If there is a Database object in the current scope, then use it for serialization
        // 
        ChangeSet changeSet = (ChangeSet) object;
        Database database = Scope.getCurrentScope().get(DiffToChangeLog.DIFF_SNAPSHOT_DATABASE, Database.class);
        if (database == null) {
            database = getTargetDatabase(changeSet);
        }
        StringBuilder builder = new StringBuilder();
        createChangeSetInfo(changeSet, builder);
        for (Change change : changeSet.getChanges()) {
            Sql[] sqls = SqlGeneratorFactory.getInstance().generateSql(change.generateStatements(database), database);
            if (sqls != null) {
                for (Sql sql : sqls) {
                    builder.append(sql.toSql()).append(sql.getEndDelimiter()).append("\n");
                }
            }
        }
        return builder.toString();
    } else {
        throw new UnexpectedLiquibaseException("Cannot serialize object type: " + object.getClass().getName());
    }
}
Also used : Database(liquibase.database.Database) Change(liquibase.change.Change) ChangeSet(liquibase.changelog.ChangeSet) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) Sql(liquibase.sql.Sql)

Example 58 with ChangeSet

use of liquibase.changelog.ChangeSet in project liquibase by liquibase.

the class MarkChangeSetRanGeneratorTest method generateSql_markRan.

@Test
public void generateSql_markRan() {
    Sql[] sqls = new MarkChangeSetRanGenerator().generateSql(new MarkChangeSetRanStatement(new ChangeSet("1", "a", false, false, "c", null, null, null), ChangeSet.ExecType.MARK_RAN), new MockDatabase(), new MockSqlGeneratorChain());
    assertEquals(1, sqls.length);
    assertTrue(sqls[0].toSql(), sqls[0].toSql().contains("MARK_RAN"));
}
Also used : MarkChangeSetRanStatement(liquibase.statement.core.MarkChangeSetRanStatement) MockDatabase(liquibase.database.core.MockDatabase) ChangeSet(liquibase.changelog.ChangeSet) Sql(liquibase.sql.Sql) MockSqlGeneratorChain(liquibase.sqlgenerator.MockSqlGeneratorChain) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 59 with ChangeSet

use of liquibase.changelog.ChangeSet in project liquibase by liquibase.

the class AfterTagChangeSetFilterTest method accepts.

@Test
public void accepts() throws Exception {
    ArrayList<RanChangeSet> ranChanges = new ArrayList<RanChangeSet>();
    ranChanges.add(new RanChangeSet("path/changelog", "1", "testAuthor", CheckSum.parse("12345"), new Date(), null, null, null, null, null, null, null));
    ranChanges.add(new RanChangeSet("path/changelog", "2", "testAuthor", CheckSum.parse("12345"), new Date(), "tag1", null, null, null, null, null, null));
    ranChanges.add(new RanChangeSet("path/changelog", "3", "testAuthor", CheckSum.parse("12345"), new Date(), null, null, null, null, null, null, null));
    AfterTagChangeSetFilter filter = new AfterTagChangeSetFilter("tag1", ranChanges);
    assertFalse(filter.accepts(new ChangeSet("1", "testAuthor", false, false, "path/changelog", null, null, null)).isAccepted());
    assertFalse(filter.accepts(new ChangeSet("2", "testAuthor", false, false, "path/changelog", null, null, null)).isAccepted());
    assertTrue(filter.accepts(new ChangeSet("3", "testAuthor", false, false, "path/changelog", null, null, null)).isAccepted());
}
Also used : ArrayList(java.util.ArrayList) RanChangeSet(liquibase.changelog.RanChangeSet) ChangeSet(liquibase.changelog.ChangeSet) Date(java.util.Date) RanChangeSet(liquibase.changelog.RanChangeSet) Test(org.junit.Test)

Example 60 with ChangeSet

use of liquibase.changelog.ChangeSet in project liquibase by liquibase.

the class ContextChangeSetFilterTest method singleContexts.

@Test
public void singleContexts() {
    ContextChangeSetFilter filter = new ContextChangeSetFilter(new Contexts("TEST1"));
    assertTrue(filter.accepts(new ChangeSet(null, null, false, false, null, "test1", null, null)).isAccepted());
    assertTrue(filter.accepts(new ChangeSet(null, null, false, false, null, "test1, test2", null, null)).isAccepted());
    assertFalse(filter.accepts(new ChangeSet(null, null, false, false, null, "test2", null, null)).isAccepted());
    assertTrue(filter.accepts(new ChangeSet(null, null, false, false, null, null, null, null)).isAccepted());
}
Also used : Contexts(liquibase.Contexts) ChangeSet(liquibase.changelog.ChangeSet) Test(org.junit.Test)

Aggregations

ChangeSet (liquibase.changelog.ChangeSet)75 Test (org.junit.Test)41 RanChangeSet (liquibase.changelog.RanChangeSet)13 Contexts (liquibase.Contexts)12 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)11 Database (liquibase.database.Database)11 ArrayList (java.util.ArrayList)10 Liquibase (liquibase.Liquibase)10 Change (liquibase.change.Change)9 LiquibaseException (liquibase.exception.LiquibaseException)9 DiffOutputControl (liquibase.diff.output.DiffOutputControl)7 DiffToChangeLog (liquibase.diff.output.changelog.DiffToChangeLog)7 IOException (java.io.IOException)6 ObjectQuotingStrategy (liquibase.database.ObjectQuotingStrategy)6 DiffResult (liquibase.diff.DiffResult)6 CompareControl (liquibase.diff.compare.CompareControl)6 LabelExpression (liquibase.LabelExpression)5 Sql (liquibase.sql.Sql)5 SqlStatement (liquibase.statement.SqlStatement)5 MarkChangeSetRanStatement (liquibase.statement.core.MarkChangeSetRanStatement)5