use of liquibase.ContextExpression in project liquibase by liquibase.
the class StandardChangeLogHistoryService method getRanChangeSets.
/**
* Returns the ChangeSets that have been run against the current getDatabase().
*/
public List<RanChangeSet> getRanChangeSets() throws DatabaseException {
if (this.ranChangeSetList == null) {
Database database = getDatabase();
String databaseChangeLogTableName = getDatabase().escapeTableName(getLiquibaseCatalogName(), getLiquibaseSchemaName(), getDatabaseChangeLogTableName());
List<RanChangeSet> ranChangeSetList = new ArrayList<RanChangeSet>();
if (hasDatabaseChangeLogTable()) {
LogFactory.getLogger().info("Reading from " + databaseChangeLogTableName);
List<Map<String, ?>> results = queryDatabaseChangeLogTable(database);
for (Map rs : results) {
String fileName = rs.get("FILENAME").toString();
String author = rs.get("AUTHOR").toString();
String id = rs.get("ID").toString();
String md5sum = rs.get("MD5SUM") == null || !databaseChecksumsCompatible ? null : rs.get("MD5SUM").toString();
String description = rs.get("DESCRIPTION") == null ? null : rs.get("DESCRIPTION").toString();
String comments = rs.get("COMMENTS") == null ? null : rs.get("COMMENTS").toString();
Object tmpDateExecuted = rs.get("DATEEXECUTED");
Date dateExecuted = null;
if (tmpDateExecuted instanceof Date) {
dateExecuted = (Date) tmpDateExecuted;
} else {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
dateExecuted = df.parse((String) tmpDateExecuted);
} catch (ParseException e) {
}
}
String tmpOrderExecuted = rs.get("ORDEREXECUTED").toString();
Integer orderExecuted = (tmpOrderExecuted == null ? null : Integer.valueOf(tmpOrderExecuted));
String tag = rs.get("TAG") == null ? null : rs.get("TAG").toString();
String execType = rs.get("EXECTYPE") == null ? null : rs.get("EXECTYPE").toString();
ContextExpression contexts = new ContextExpression((String) rs.get("CONTEXTS"));
Labels labels = new Labels((String) rs.get("LABELS"));
String deploymentId = (String) rs.get("DEPLOYMENT_ID");
try {
RanChangeSet ranChangeSet = new RanChangeSet(fileName, id, author, CheckSum.parse(md5sum), dateExecuted, tag, ChangeSet.ExecType.valueOf(execType), description, comments, contexts, labels, deploymentId);
ranChangeSet.setOrderExecuted(orderExecuted);
ranChangeSetList.add(ranChangeSet);
} catch (IllegalArgumentException e) {
LogFactory.getLogger().severe("Unknown EXECTYPE from database: " + execType);
throw e;
}
}
}
this.ranChangeSetList = ranChangeSetList;
}
return Collections.unmodifiableList(ranChangeSetList);
}
use of liquibase.ContextExpression in project liquibase by liquibase.
the class ContextChangeSetFilter method accepts.
@Override
public ChangeSetFilterResult accepts(ChangeSet changeSet) {
List<SqlVisitor> visitorsToRemove = new ArrayList<SqlVisitor>();
for (SqlVisitor visitor : changeSet.getSqlVisitors()) {
if (visitor.getContexts() != null && !visitor.getContexts().matches(contexts)) {
visitorsToRemove.add(visitor);
}
}
changeSet.getSqlVisitors().removeAll(visitorsToRemove);
if (contexts == null || contexts.isEmpty()) {
return new ChangeSetFilterResult(true, "No runtime context specified, all contexts will run", this.getClass());
}
Collection<ContextExpression> inheritableContexts = changeSet.getInheritableContexts();
if (changeSet.getContexts().isEmpty() && inheritableContexts.isEmpty()) {
return new ChangeSetFilterResult(true, "Change set runs under all contexts", this.getClass());
}
if (changeSet.getContexts().matches(contexts) && ContextExpression.matchesAll(inheritableContexts, contexts)) {
return new ChangeSetFilterResult(true, "Context matches '" + contexts.toString() + "'", this.getClass());
} else {
return new ChangeSetFilterResult(false, "Context does not match '" + contexts.toString() + "'", this.getClass());
}
}
use of liquibase.ContextExpression in project liquibase by liquibase.
the class ChangeSet method handleChildNode.
protected void handleChildNode(ParsedNode child, ResourceAccessor resourceAccessor) throws ParsedNodeException {
if (child.getName().equals("rollback")) {
handleRollbackNode(child, resourceAccessor);
} else if (child.getName().equals("validCheckSum") || child.getName().equals("validCheckSums")) {
if (child.getValue() == null) {
return;
}
if (child.getValue() instanceof Collection) {
for (Object checksum : (Collection) child.getValue()) {
addValidCheckSum((String) checksum);
}
} else {
addValidCheckSum(child.getValue(String.class));
}
} else if (child.getName().equals("modifySql")) {
String dbmsString = StringUtils.trimToNull(child.getChildValue(null, "dbms", String.class));
String contextString = StringUtils.trimToNull(child.getChildValue(null, "context", String.class));
String labelsString = StringUtils.trimToNull(child.getChildValue(null, "labels", String.class));
boolean applyToRollback = child.getChildValue(null, "applyToRollback", false);
Set<String> dbms = new HashSet<String>();
if (dbmsString != null) {
dbms.addAll(StringUtils.splitAndTrim(dbmsString, ","));
}
ContextExpression context = null;
if (contextString != null) {
context = new ContextExpression(contextString);
}
Labels labels = null;
if (labelsString != null) {
labels = new Labels(labelsString);
}
List<ParsedNode> potentialVisitors = child.getChildren();
for (ParsedNode node : potentialVisitors) {
SqlVisitor sqlVisitor = SqlVisitorFactory.getInstance().create(node.getName());
if (sqlVisitor != null) {
sqlVisitor.setApplyToRollback(applyToRollback);
if (dbms.size() > 0) {
sqlVisitor.setApplicableDbms(dbms);
}
sqlVisitor.setContexts(context);
sqlVisitor.setLabels(labels);
sqlVisitor.load(node, resourceAccessor);
addSqlVisitor(sqlVisitor);
}
}
} else if (child.getName().equals("preConditions")) {
this.preconditions = new PreconditionContainer();
try {
this.preconditions.load(child, resourceAccessor);
} catch (ParsedNodeException e) {
e.printStackTrace();
}
} else if (child.getName().equals("changes")) {
for (ParsedNode changeNode : child.getChildren()) {
handleChildNode(changeNode, resourceAccessor);
}
} else {
Change change = toChange(child, resourceAccessor);
if (change == null && child.getValue() instanceof String) {
this.setAttribute(child.getName(), child.getValue());
} else {
addChange(change);
}
}
}
use of liquibase.ContextExpression in project liquibase by liquibase.
the class ChangeLogIterator method createKey.
protected String createKey(ChangeSet changeSet) {
Labels labels = changeSet.getLabels();
ContextExpression contexts = changeSet.getContexts();
return changeSet.toString(true) + ":" + (labels == null ? null : labels.toString()) + ":" + (contexts == null ? null : contexts.toString()) + ":" + StringUtils.join(changeSet.getDbmsSet(), ",");
}
use of liquibase.ContextExpression in project liquibase by liquibase.
the class ChangeLogParametersTest method setParameterValue_multiDatabase.
@Test
public void setParameterValue_multiDatabase() {
ChangeLogParameters changeLogParameters = new ChangeLogParameters(new H2Database());
changeLogParameters.set("doubleSet", "originalValue", new ContextExpression(), new Labels(), "baddb, h2", true, null);
assertEquals("originalValue", changeLogParameters.getValue("doubleSet", null));
}
Aggregations