Search in sources :

Example 1 with SqlPrecondition

use of liquibase.precondition.core.SqlPrecondition in project liquibase by liquibase.

the class FormattedSqlChangeLogParser method parseSqlCheckCondition.

private SqlPrecondition parseSqlCheckCondition(String body) throws ChangeLogParseException {
    Pattern[] patterns = new Pattern[] { Pattern.compile("^(?:expectedResult:)?(\\w+) (.*)", Pattern.CASE_INSENSITIVE), Pattern.compile("^(?:expectedResult:)?'([^']+)' (.*)", Pattern.CASE_INSENSITIVE), Pattern.compile("^(?:expectedResult:)?\"([^\"]+)\" (.*)", Pattern.CASE_INSENSITIVE) };
    for (Pattern pattern : patterns) {
        Matcher matcher = pattern.matcher(body);
        if (matcher.matches() && matcher.groupCount() == 2) {
            SqlPrecondition p = new SqlPrecondition();
            p.setExpectedResult(matcher.group(1));
            p.setSql(matcher.group(2));
            return p;
        }
    }
    throw new ChangeLogParseException("Could not parse a SqlCheck precondition from '" + body + "'.");
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ChangeLogParseException(liquibase.exception.ChangeLogParseException) SqlPrecondition(liquibase.precondition.core.SqlPrecondition)

Aggregations

Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ChangeLogParseException (liquibase.exception.ChangeLogParseException)1 SqlPrecondition (liquibase.precondition.core.SqlPrecondition)1