change.setSql(finalCurrentSql);
if (StringUtils.trimToNull(currentRollbackSql.toString()) != null) {
if (currentRollbackSql.toString().trim().toLowerCase().matches("^not required.*")) {
changeSet.addRollbackChange(new EmptyChange());
} else {
RawSQLChange rollbackChange = new RawSQLChange();
rollbackChange.setSql(changeLogParameters.expandExpressions(currentRollbackSql.toString()));
changeSet.addRollbackChange(rollbackChange);
}
}
}
Matcher stripCommentsPatternMatcher = stripCommentsPattern.matcher(line);
Matcher splitStatementsPatternMatcher = splitStatementsPattern.matcher(line);
Matcher endDelimiterPatternMatcher = endDelimiterPattern.matcher(line);
Matcher logicalFilePathMatcher = logicalFilePathPattern.matcher (line);
Matcher runOnChangePatternMatcher = runOnChangePattern.matcher(line);
Matcher runAlwaysPatternMatcher = runAlwaysPattern.matcher(line);
Matcher contextPatternMatcher = contextPattern.matcher(line);
Matcher labelsPatternMatcher = labelsPattern.matcher(line);
Matcher runInTransactionPatternMatcher = runInTransactionPattern.matcher(line);
Matcher dbmsPatternMatcher = dbmsPattern.matcher(line);
Matcher failOnErrorPatternMatcher = failOnErrorPattern.matcher(line);
boolean stripComments = parseBoolean(stripCommentsPatternMatcher, changeSet, true);
boolean splitStatements = parseBoolean(splitStatementsPatternMatcher, changeSet, true);
boolean runOnChange = parseBoolean(runOnChangePatternMatcher, changeSet, false);
boolean runAlways = parseBoolean(runAlwaysPatternMatcher, changeSet, false);
boolean runInTransaction = parseBoolean(runInTransactionPatternMatcher, changeSet, true);
boolean failOnError = parseBoolean(failOnErrorPatternMatcher, changeSet, true);
String endDelimiter = parseString(endDelimiterPatternMatcher);
String context = parseString(contextPatternMatcher);
String labels = parseString(labelsPatternMatcher);
String logicalFilePath = parseString(logicalFilePathMatcher);
if (logicalFilePath == null || "".equals (logicalFilePath)) {
logicalFilePath = changeLog.getLogicalFilePath ();
}
String dbms = parseString(dbmsPatternMatcher);
changeSet = new ChangeSet(changeSetPatternMatcher.group(2), changeSetPatternMatcher.group(1), runAlways, runOnChange, logicalFilePath, context, dbms, runInTransaction, changeLog.getObjectQuotingStrategy(), changeLog);
changeSet.setLabels(new Labels(labels));
changeSet.setFailOnError(failOnError);
changeLog.addChangeSet(changeSet);
change = new RawSQLChange();
change.setSql(finalCurrentSql);
change.setResourceAccessor(resourceAccessor);
change.setSplitStatements(splitStatements);
change.setStripComments(stripComments);
change.setEndDelimiter(endDelimiter);
changeSet.addChange(change);
currentSql = new StringBuffer();
currentRollbackSql = new StringBuffer();
} else {
if (changeSet != null) {
Matcher commentMatcher = commentPattern.matcher(line);
Matcher rollbackMatcher = rollbackPattern.matcher(line);
Matcher preconditionsMatcher = preconditionsPattern.matcher(line);
Matcher preconditionMatcher = preconditionPattern.matcher(line);
if (commentMatcher.matches()) {
if (commentMatcher.groupCount() == 1) {
changeSet.setComments(commentMatcher.group(1));
}
} else if (rollbackMatcher.matches()) {
if (rollbackMatcher.groupCount() == 1) {
currentRollbackSql.append(rollbackMatcher.group(1)).append("\n");
}
} else if (preconditionsMatcher.matches()) {
if (preconditionsMatcher.groupCount() == 1) {
String body = preconditionsMatcher.group(1);
Matcher onFailMatcher = onFailPattern.matcher(body);
Matcher onErrorMatcher = onErrorPattern.matcher(body);
Matcher onUpdateSqlMatcher = onUpdateSqlPattern.matcher(body);
PreconditionContainer pc = new PreconditionContainer();
pc.setOnFail(StringUtils.trimToNull(parseString(onFailMatcher)));
pc.setOnError(StringUtils.trimToNull(parseString(onErrorMatcher)));
pc.setOnSqlOutput(StringUtils.trimToNull(parseString(onUpdateSqlMatcher)));
changeSet.setPreconditions(pc);
}
} else if (preconditionMatcher.matches()) {
if (changeSet.getPreconditions() == null) {
// create the defaults
changeSet.setPreconditions(new PreconditionContainer());
}
if (preconditionMatcher.groupCount() == 2) {
String name = StringUtils.trimToNull(preconditionMatcher.group(1));
if (name != null) {
String body = preconditionMatcher.group(2).trim();
if ("sql-check".equals(name)) {
changeSet.getPreconditions().addNestedPrecondition(parseSqlCheckCondition(body));
} else {
throw new ChangeLogParseException("The '" + name + "' precondition type is not supported.");
}
}
}
} else {
currentSql.append(line).append("\n");
}
}
}
}
if (changeSet != null) {
change.setSql(changeLogParameters.expandExpressions(StringUtils.trimToNull(currentSql.toString())));
if (StringUtils.trimToNull(currentRollbackSql.toString()) != null) {
if (currentRollbackSql.toString().trim().toLowerCase().matches("^not required.*")) {
changeSet.addRollbackChange(new EmptyChange());
} else {
RawSQLChange rollbackChange = new RawSQLChange();
rollbackChange.setSql(changeLogParameters.expandExpressions(currentRollbackSql.toString()));
changeSet.addRollbackChange(rollbackChange);
}