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;
}
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());
}
}
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"));
}
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());
}
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());
}
Aggregations