use of liquibase.ContextExpression in project liquibase by liquibase.
the class ChangeSet method load.
@Override
public void load(ParsedNode node, ResourceAccessor resourceAccessor) throws ParsedNodeException {
this.id = node.getChildValue(null, "id", String.class);
this.author = node.getChildValue(null, "author", String.class);
this.alwaysRun = node.getChildValue(null, "runAlways", node.getChildValue(null, "alwaysRun", false));
this.runOnChange = node.getChildValue(null, "runOnChange", false);
this.contexts = new ContextExpression(node.getChildValue(null, "context", String.class));
this.labels = new Labels(StringUtils.trimToNull(node.getChildValue(null, "labels", String.class)));
setDbms(node.getChildValue(null, "dbms", String.class));
this.runInTransaction = node.getChildValue(null, "runInTransaction", true);
this.created = node.getChildValue(null, "created", String.class);
this.runOrder = node.getChildValue(null, "runOrder", String.class);
this.comments = StringUtils.join(node.getChildren(null, "comment"), "\n", new StringUtils.StringUtilsFormatter() {
@Override
public String toString(Object obj) {
if (((ParsedNode) obj).getValue() == null) {
return "";
} else {
return ((ParsedNode) obj).getValue().toString();
}
}
});
this.comments = StringUtils.trimToNull(this.comments);
String objectQuotingStrategyString = StringUtils.trimToNull(node.getChildValue(null, "objectQuotingStrategy", String.class));
if (changeLog != null) {
this.objectQuotingStrategy = changeLog.getObjectQuotingStrategy();
}
if (objectQuotingStrategyString != null) {
this.objectQuotingStrategy = ObjectQuotingStrategy.valueOf(objectQuotingStrategyString);
}
if (this.objectQuotingStrategy == null) {
this.objectQuotingStrategy = ObjectQuotingStrategy.LEGACY;
}
this.filePath = StringUtils.trimToNull(node.getChildValue(null, "logicalFilePath", String.class));
if (filePath == null) {
filePath = changeLog.getFilePath();
}
this.setFailOnError(node.getChildValue(null, "failOnError", Boolean.class));
String onValidationFailString = node.getChildValue(null, "onValidationFail", "HALT");
this.setOnValidationFail(ValidationFailOption.valueOf(onValidationFailString));
for (ParsedNode child : node.getChildren()) {
handleChildNode(child, resourceAccessor);
}
}
use of liquibase.ContextExpression in project liquibase by liquibase.
the class ChangeSet method getInheritableContexts.
public Collection<ContextExpression> getInheritableContexts() {
Collection<ContextExpression> expressions = new ArrayList<ContextExpression>();
DatabaseChangeLog changeLog = getChangeLog();
while (changeLog != null) {
ContextExpression expression = changeLog.getContexts();
if (expression != null && !expression.isEmpty()) {
expressions.add(expression);
}
ContextExpression includeExpression = changeLog.getIncludeContexts();
if (includeExpression != null && !includeExpression.isEmpty()) {
expressions.add(includeExpression);
}
changeLog = changeLog.getParentChangeLog();
}
return Collections.unmodifiableCollection(expressions);
}
use of liquibase.ContextExpression in project liquibase by liquibase.
the class DatabaseChangeLog method load.
public void load(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException, SetupException {
setLogicalFilePath(parsedNode.getChildValue(null, "logicalFilePath", String.class));
setContexts(new ContextExpression(parsedNode.getChildValue(null, "context", String.class)));
String objectQuotingStrategy = parsedNode.getChildValue(null, "objectQuotingStrategy", String.class);
if (objectQuotingStrategy != null) {
setObjectQuotingStrategy(ObjectQuotingStrategy.valueOf(objectQuotingStrategy));
}
for (ParsedNode childNode : parsedNode.getChildren()) {
handleChildNode(childNode, resourceAccessor);
}
}
use of liquibase.ContextExpression in project liquibase by liquibase.
the class DatabaseChangeLog method handleChildNode.
protected void handleChildNode(ParsedNode node, ResourceAccessor resourceAccessor) throws ParsedNodeException, SetupException {
expandExpressions(node);
String nodeName = node.getName();
if (nodeName.equals("changeSet")) {
this.addChangeSet(createChangeSet(node, resourceAccessor));
} else if (nodeName.equals("include")) {
String path = node.getChildValue(null, "file", String.class);
if (path == null) {
throw new UnexpectedLiquibaseException("No 'file' attribute on 'include'");
}
path = path.replace('\\', '/');
ContextExpression includeContexts = new ContextExpression(node.getChildValue(null, "context", String.class));
try {
include(path, node.getChildValue(null, "relativeToChangelogFile", false), resourceAccessor, includeContexts);
} catch (LiquibaseException e) {
throw new SetupException(e);
}
} else if (nodeName.equals("includeAll")) {
String path = node.getChildValue(null, "path", String.class);
String resourceFilterDef = node.getChildValue(null, "filter", String.class);
if (resourceFilterDef == null) {
resourceFilterDef = node.getChildValue(null, "resourceFilter", String.class);
}
IncludeAllFilter resourceFilter = null;
if (resourceFilterDef != null) {
try {
resourceFilter = (IncludeAllFilter) Class.forName(resourceFilterDef).newInstance();
} catch (Exception e) {
throw new SetupException(e);
}
}
String resourceComparatorDef = node.getChildValue(null, "resourceComparator", String.class);
Comparator<?> resourceComparator = null;
if (resourceComparatorDef != null) {
try {
resourceComparator = (Comparator<?>) Class.forName(resourceComparatorDef).newInstance();
} catch (Exception e) {
//take default comparator
LogFactory.getInstance().getLog().info("no resourceComparator defined - taking default implementation");
resourceComparator = getStandardChangeLogComparator();
}
}
ContextExpression includeContexts = new ContextExpression(node.getChildValue(null, "context", String.class));
includeAll(path, node.getChildValue(null, "relativeToChangelogFile", false), resourceFilter, node.getChildValue(null, "errorIfMissingOrEmpty", true), getStandardChangeLogComparator(), resourceAccessor, includeContexts);
} else if (nodeName.equals("preConditions")) {
this.preconditionContainer = new PreconditionContainer();
try {
this.preconditionContainer.load(node, resourceAccessor);
} catch (ParsedNodeException e) {
e.printStackTrace();
}
} else if (nodeName.equals("property")) {
try {
String context = node.getChildValue(null, "context", String.class);
String dbms = node.getChildValue(null, "dbms", String.class);
String labels = node.getChildValue(null, "labels", String.class);
Boolean global = node.getChildValue(null, "global", Boolean.class);
if (global == null) {
// okay behave like liquibase < 3.4 and set global == true
global = true;
}
String file = node.getChildValue(null, "file", String.class);
if (file == null) {
// direct referenced property, no file
String name = node.getChildValue(null, "name", String.class);
String value = node.getChildValue(null, "value", String.class);
this.changeLogParameters.set(name, value, context, labels, dbms, global, this);
} else {
// read properties from the file
Properties props = new Properties();
InputStream propertiesStream = StreamUtil.singleInputStream(file, resourceAccessor);
if (propertiesStream == null) {
LogFactory.getInstance().getLog().info("Could not open properties file " + file);
} else {
props.load(propertiesStream);
for (Map.Entry entry : props.entrySet()) {
this.changeLogParameters.set(entry.getKey().toString(), entry.getValue().toString(), context, labels, dbms, global, this);
}
}
}
} catch (IOException e) {
throw new ParsedNodeException(e);
}
}
}
use of liquibase.ContextExpression in project liquibase by liquibase.
the class OfflineChangeLogHistoryService method getRanChangeSets.
@Override
public List<RanChangeSet> getRanChangeSets() throws DatabaseException {
Reader reader = null;
try {
reader = new InputStreamReader(new FileInputStream(this.changeLogFile), LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding());
CSVReader csvReader = new CSVReader(reader);
String[] line = csvReader.readNext();
if (line == null) {
//empty file
writeHeader(this.changeLogFile);
return new ArrayList<RanChangeSet>();
}
if (!line[COLUMN_ID].equals("ID")) {
throw new DatabaseException("Missing header in file " + this.changeLogFile.getAbsolutePath());
}
List<RanChangeSet> returnList = new ArrayList<RanChangeSet>();
while ((line = csvReader.readNext()) != null) {
ContextExpression contexts = new ContextExpression();
if (line.length > COLUMN_CONTEXTS) {
contexts = new ContextExpression(line[COLUMN_CONTEXTS]);
}
Labels labels = new Labels();
if (line.length > COLUMN_LABELS) {
labels = new Labels(line[COLUMN_LABELS]);
}
String deploymentId = null;
if (line.length > DEPLOYMENT_ID) {
deploymentId = line[DEPLOYMENT_ID];
}
returnList.add(new RanChangeSet(line[COLUMN_FILENAME], line[COLUMN_ID], line[COLUMN_AUTHOR], CheckSum.parse(line[COLUMN_MD5SUM]), new ISODateFormat().parse(line[COLUMN_DATEEXECUTED]), line[COLUMN_TAG], ChangeSet.ExecType.valueOf(line[COLUMN_EXECTYPE]), line[COLUMN_DESCRIPTION], line[COLUMN_COMMENTS], contexts, labels, deploymentId));
}
return returnList;
} catch (Exception e) {
throw new DatabaseException(e);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ignore) {
}
}
}
}
Aggregations