@Test public void parse() throws Exception { ChangeLogParameters params = new ChangeLogParameters(); params.set("tablename", "table4"); DatabaseChangeLog changeLog = new MockFormattedSqlChangeLogParser(VALID_CHANGELOG).parse("asdf.sql", params, new JUnitResourceAccessor()); assertEquals("asdf.sql", changeLog.getLogicalFilePath()); assertEquals(8, changeLog.getChangeSets().size()); assertEquals("nvoxland", changeLog.getChangeSets().get(0).getAuthor()); assertEquals("1", changeLog.getChangeSets().get(0).getId()); assertEquals(1, changeLog.getChangeSets().get(0).getChanges().size()); assertEquals("select * from table1;", ((RawSQLChange) changeLog.getChangeSets().get(0).getChanges().get(0)).getSql()); assertNull(((RawSQLChange) changeLog.getChangeSets().get(0).getChanges().get(0)).getEndDelimiter()); assertTrue(((RawSQLChange) changeLog.getChangeSets().get(0).getChanges().get(0)).isSplittingStatements()); assertTrue(((RawSQLChange) changeLog.getChangeSets().get(0).getChanges().get(0)).isStrippingComments()); assertFalse(changeLog.getChangeSets().get(0).isAlwaysRun()); assertFalse(changeLog.getChangeSets().get(0).isRunOnChange()); assertTrue(changeLog.getChangeSets().get(0).isRunInTransaction()); assertNull(changeLog.getChangeSets().get(0).getContexts()); assertNull(changeLog.getChangeSets().get(0).getDbmsSet()); assertEquals("nvoxland", changeLog.getChangeSets().get(1).getAuthor()); assertEquals("2", changeLog.getChangeSets().get(1).getId()); assertEquals(1, changeLog.getChangeSets().get(1).getChanges().size()); assertEquals("create table table1 (\n" + " id int primary key\n" + ");", ((RawSQLChange) changeLog.getChangeSets().get(1).getChanges().get(0)).getSql()); assertEquals("X", ((RawSQLChange) changeLog.getChangeSets().get(1).getChanges().get(0)).getEndDelimiter()); assertFalse(((RawSQLChange) changeLog.getChangeSets().get(1).getChanges().get(0)).isSplittingStatements()); assertFalse(((RawSQLChange) changeLog.getChangeSets().get(1).getChanges().get(0)).isStrippingComments()); assertEquals("X", ((RawSQLChange) changeLog.getChangeSets().get(1).getChanges().get(0)).getEndDelimiter()); assertFalse(((RawSQLChange) changeLog.getChangeSets().get(1).getChanges().get(0)).isSplittingStatements()); assertFalse(((RawSQLChange) changeLog.getChangeSets().get(1).getChanges().get(0)).isStrippingComments()); assertTrue(changeLog.getChangeSets().get(1).isAlwaysRun()); assertTrue(changeLog.getChangeSets().get(1).isRunOnChange()); assertFalse(changeLog.getChangeSets().get(1).isRunInTransaction()); assertEquals("y", StringUtils.join(changeLog.getChangeSets().get(1).getContexts(), ",")); assertEquals("mysql", StringUtils.join(changeLog.getChangeSets().get(1).getDbmsSet(), ",")); assertEquals(1, changeLog.getChangeSets().get(1).getRollBackChanges().length); assertEquals("delete from table1;\n" + "drop table table1;", ((RawSQLChange) changeLog.getChangeSets().get(1).getRollBackChanges()[0]).getSql()); assertEquals("nvoxland", changeLog.getChangeSets().get(2).getAuthor()); assertEquals("3", changeLog.getChangeSets().get(2).getId()); assertEquals(1, changeLog.getChangeSets().get(2).getChanges().size()); assertEquals("create table table2 (\n" + " id int primary key\n" + ");\n" + "create table table3 (\n" + " id int primary key\n" + ");", ((RawSQLChange) changeLog.getChangeSets().get(2).getChanges().get(0)).getSql()); assertNull(((RawSQLChange) changeLog.getChangeSets().get(2).getChanges().get(0)).getEndDelimiter()); assertTrue(((RawSQLChange) changeLog.getChangeSets().get(2).getChanges().get(0)).isSplittingStatements()); assertTrue(((RawSQLChange) changeLog.getChangeSets().get(2).getChanges().get(0)).isStrippingComments()); assertEquals(1, changeLog.getChangeSets().get(2).getRollBackChanges().length); assertTrue(changeLog.getChangeSets().get(2).getRollBackChanges()[0] instanceof RawSQLChange); assertEquals("drop table table2;", ((RawSQLChange) changeLog.getChangeSets().get(2).getRollBackChanges()[0]).getSql()); assertEquals("alwyn", changeLog.getChangeSets().get(3).getAuthor()); assertEquals("4", changeLog.getChangeSets().get(3).getId()); assertEquals(1, changeLog.getChangeSets().get(3).getRollBackChanges().length); assertTrue(changeLog.getChangeSets().get(3).getRollBackChanges()[0] instanceof EmptyChange); assertEquals("nvoxland", changeLog.getChangeSets().get(4).getAuthor()); assertEquals("5", changeLog.getChangeSets().get(4).getId()); assertEquals(1, changeLog.getChangeSets().get(4).getRollBackChanges().length); assertTrue(changeLog.getChangeSets().get(4).getRollBackChanges()[0] instanceof EmptyChange); assertEquals("paikens", changeLog.getChangeSets().get(5).getAuthor()); assertEquals("6", changeLog.getChangeSets().get(5).getId()); assertEquals(1, changeLog.getChangeSets().get(5).getChanges().size()); assertTrue(changeLog.getChangeSets().get(5).getChanges().get(0) instanceof RawSQLChange); assertEquals("create table table4 (\n" + " id int primary key\n" + ");", ((RawSQLChange) changeLog.getChangeSets().get(5).getChanges().get(0)).getSql()); assertEquals(1, changeLog.getChangeSets().get(5).getRollBackChanges().length); assertTrue(changeLog.getChangeSets().get(5).getRollBackChanges()[0] instanceof RawSQLChange); assertEquals("drop table table4;", ((RawSQLChange) changeLog.getChangeSets().get(5).getRollBackChanges()[0]).getSql()); assertEquals("mysql", changeLog.getChangeSets().get(6).getAuthor()); assertEquals("1", changeLog.getChangeSets().get(6).getId()); assertEquals(1, changeLog.getChangeSets().get(6).getChanges().size()); assertTrue(changeLog.getChangeSets().get(6).getChanges().get(0) instanceof RawSQLChange); assertEquals("create table mysql_boo (\n" + " id int primary key\n" + ");", ((RawSQLChange) changeLog.getChangeSets().get(6).getChanges().get(0)).getSql()); assertEquals(1, changeLog.getChangeSets().get(6).getRollBackChanges().length); assertTrue(changeLog.getChangeSets().get(6).getRollBackChanges()[0] instanceof RawSQLChange); assertEquals("drop table mysql_boo;", ((RawSQLChange) changeLog.getChangeSets().get(6).getRollBackChanges()[0]).getSql()); ChangeSet cs = changeLog.getChangeSets().get(7); assertEquals("bboisvert", cs.getAuthor()); assertEquals("with_preconditions", cs.getId()); PreconditionContainer pc = cs.getPreconditions(); assertNotNull(pc); assertEquals(PreconditionContainer.FailOption.MARK_RAN, pc.getOnFail()); assertEquals(PreconditionContainer.ErrorOption.HALT, pc.getOnError()); assertEquals(PreconditionContainer.OnSqlOutputOption.FAIL, pc.getOnSqlOutput()); assertEquals(2, pc.getNestedPreconditions().size()); assertTrue(pc.getNestedPreconditions().get(0) instanceof SqlPrecondition); SqlPrecondition p0 = (SqlPrecondition) pc.getNestedPreconditions().get(0); assertEquals("0 table(s)", p0.getExpectedResult()); assertEquals("select count(*) || ' table(s)' from information_schema.tables where table_name = 'my_table'", p0.getSql()); assertTrue(pc.getNestedPreconditions().get(1) instanceof SqlPrecondition); SqlPrecondition p1 = (SqlPrecondition) pc.getNestedPreconditions().get(1); assertEquals("0", p1.getExpectedResult()); assertEquals("select count(*) from information_schema.columns where table_name = 'my_table' and column_name = 'id'", p1.getSql()); assertEquals(1, cs.getChanges().size()); assertTrue(cs.getChanges().get(0) instanceof RawSQLChange); assertEquals("create table my_table (\n" + " id int primary key\n" + ");", ((RawSQLChange) cs.getChanges().get(0)).getSql()); assertEquals(1, cs.getRollBackChanges().length); assertTrue(cs.getRollBackChanges()[0] instanceof RawSQLChange); assertEquals("drop table my_table;", ((RawSQLChange) cs.getRollBackChanges()[0]).getSql()); }
public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor) throws ChangeLogParseException { DatabaseChangeLog changeLog = new DatabaseChangeLog(); changeLog.setPhysicalFilePath(physicalChangeLogLocation); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(openChangeLogFile(physicalChangeLogLocation, resourceAccessor))); StringBuffer currentSql = new StringBuffer(); StringBuffer currentRollbackSql = new StringBuffer(); ChangeSet changeSet = null; RawSQLChange change = null; Pattern changeSetPattern = Pattern.compile("\\-\\-[\\s]*changeset (\\S+):(\\S+).*", Pattern.CASE_INSENSITIVE); Pattern rollbackPattern = Pattern.compile("\\s*\\-\\-[\\s]*rollback (.*)", Pattern.CASE_INSENSITIVE); Pattern preconditionsPattern = Pattern.compile("\\s*\\-\\-[\\s]*preconditions(.*)", Pattern.CASE_INSENSITIVE); Pattern preconditionPattern = Pattern.compile("\\s*\\-\\-[\\s]*precondition\\-([a-zA-Z0-9-]+) (.*)", Pattern.CASE_INSENSITIVE); Pattern stripCommentsPattern = Pattern.compile(".*stripComments:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern splitStatementsPattern = Pattern.compile(".*splitStatements:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern endDelimiterPattern = Pattern.compile(".*endDelimiter:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern runOnChangePattern = Pattern.compile(".*runOnChange:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern runAlwaysPattern = Pattern.compile(".*runAlways:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern contextPattern = Pattern.compile(".*context:(\\S+).*", Pattern.CASE_INSENSITIVE); Pattern runInTransactionPattern = Pattern.compile(".*runInTransaction:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern dbmsPattern = Pattern.compile(".*dbms:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern failOnErrorPattern = Pattern.compile(".*failOnError:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern onFailPattern = Pattern.compile(".*onFail:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern onErrorPattern = Pattern.compile(".*onError:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern onUpdateSqlPattern = Pattern.compile(".*onUpdateSQL:(\\w+).*", Pattern.CASE_INSENSITIVE); String line; while ((line = reader.readLine()) != null) { Matcher changeSetPatternMatcher = changeSetPattern.matcher(line); if (changeSetPatternMatcher.matches()) { String finalCurrentSql = changeLogParameters.expandExpressions(StringUtils.trimToNull(currentSql.toString())); if (changeSet != null) { if (finalCurrentSql == null) { throw new ChangeLogParseException("No SQL for changeset " + changeSet.toString(false)); } change.setSql(finalCurrentSql); if (StringUtils.trimToNull(currentRollbackSql.toString()) != null) { try { 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); } } catch (UnsupportedChangeException e) { throw new RuntimeException(e); } } } Matcher stripCommentsPatternMatcher = stripCommentsPattern.matcher(line); Matcher splitStatementsPatternMatcher = splitStatementsPattern.matcher(line); Matcher endDelimiterPatternMatcher = endDelimiterPattern.matcher(line); Matcher runOnChangePatternMatcher = runOnChangePattern.matcher(line); Matcher runAlwaysPatternMatcher = runAlwaysPattern.matcher(line); Matcher contextPatternMatcher = contextPattern.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 dbms = parseString(dbmsPatternMatcher); changeSet = new ChangeSet(changeSetPatternMatcher.group(2), changeSetPatternMatcher.group(1), runAlways, runOnChange, physicalChangeLogLocation, context, dbms, runInTransaction); 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 rollbackMatcher = rollbackPattern.matcher(line); Matcher preconditionsMatcher = preconditionsPattern.matcher(line); Matcher preconditionMatcher = preconditionPattern.matcher(line); 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) { 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) { try { 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); } } catch (UnsupportedChangeException e) { throw new RuntimeException(e); } } } } catch (IOException e) { throw new ChangeLogParseException(e); } finally { if (reader != null) { try { reader.close(); } catch (IOException ignore) { } } } return changeLog; }
FormattedSqlChangeLogParser implements ChangeLogParser { public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor) throws ChangeLogParseException { DatabaseChangeLog changeLog = new DatabaseChangeLog(); changeLog.setPhysicalFilePath(physicalChangeLogLocation); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(openChangeLogFile(physicalChangeLogLocation, resourceAccessor))); StringBuffer currentSql = new StringBuffer(); StringBuffer currentRollbackSql = new StringBuffer(); ChangeSet changeSet = null; RawSQLChange change = null; Pattern changeSetPattern = Pattern.compile("\\-\\-[\\s]*changeset (\\S+):(\\S+).*", Pattern.CASE_INSENSITIVE); Pattern rollbackPattern = Pattern.compile("\\s*\\-\\-[\\s]*rollback (.*)", Pattern.CASE_INSENSITIVE); Pattern preconditionsPattern = Pattern.compile("\\s*\\-\\-[\\s]*preconditions(.*)", Pattern.CASE_INSENSITIVE); Pattern preconditionPattern = Pattern.compile("\\s*\\-\\-[\\s]*precondition\\-([a-zA-Z0-9-]+) (.*)", Pattern.CASE_INSENSITIVE); Pattern stripCommentsPattern = Pattern.compile(".*stripComments:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern splitStatementsPattern = Pattern.compile(".*splitStatements:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern endDelimiterPattern = Pattern.compile(".*endDelimiter:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern runOnChangePattern = Pattern.compile(".*runOnChange:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern runAlwaysPattern = Pattern.compile(".*runAlways:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern contextPattern = Pattern.compile(".*context:(\\S+).*", Pattern.CASE_INSENSITIVE); Pattern runInTransactionPattern = Pattern.compile(".*runInTransaction:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern dbmsPattern = Pattern.compile(".*dbms:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern failOnErrorPattern = Pattern.compile(".*failOnError:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern onFailPattern = Pattern.compile(".*onFail:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern onErrorPattern = Pattern.compile(".*onError:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern onUpdateSqlPattern = Pattern.compile(".*onUpdateSQL:(\\w+).*", Pattern.CASE_INSENSITIVE); String line; while ((line = reader.readLine()) != null) { Matcher changeSetPatternMatcher = changeSetPattern.matcher(line); if (changeSetPatternMatcher.matches()) { String finalCurrentSql = changeLogParameters.expandExpressions(StringUtils.trimToNull(currentSql.toString())); if (changeSet != null) { if (finalCurrentSql == null) { throw new ChangeLogParseException("No SQL for changeset " + changeSet.toString(false)); } change.setSql(finalCurrentSql); if (StringUtils.trimToNull(currentRollbackSql.toString()) != null) { try { 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); } } catch (UnsupportedChangeException e) { throw new RuntimeException(e); } } } Matcher stripCommentsPatternMatcher = stripCommentsPattern.matcher(line); Matcher splitStatementsPatternMatcher = splitStatementsPattern.matcher(line); Matcher endDelimiterPatternMatcher = endDelimiterPattern.matcher(line); Matcher runOnChangePatternMatcher = runOnChangePattern.matcher(line); Matcher runAlwaysPatternMatcher = runAlwaysPattern.matcher(line); Matcher contextPatternMatcher = contextPattern.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 dbms = parseString(dbmsPatternMatcher); changeSet = new ChangeSet(changeSetPatternMatcher.group(2), changeSetPatternMatcher.group(1), runAlways, runOnChange, physicalChangeLogLocation, context, dbms, runInTransaction); 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 rollbackMatcher = rollbackPattern.matcher(line); Matcher preconditionsMatcher = preconditionsPattern.matcher(line); Matcher preconditionMatcher = preconditionPattern.matcher(line); 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) { 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) { try { 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); } } catch (UnsupportedChangeException e) { throw new RuntimeException(e); } } } } catch (IOException e) { throw new ChangeLogParseException(e); } finally { if (reader != null) { try { reader.close(); } catch (IOException ignore) { } } } return changeLog; } }
FormattedSqlChangeLogParser implements ChangeLogParser { public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor) throws ChangeLogParseException { DatabaseChangeLog changeLog = new DatabaseChangeLog(); changeLog.setPhysicalFilePath(physicalChangeLogLocation); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(openChangeLogFile(physicalChangeLogLocation, resourceAccessor))); StringBuffer currentSql = new StringBuffer(); StringBuffer currentRollbackSql = new StringBuffer(); ChangeSet changeSet = null; RawSQLChange change = null; Pattern changeSetPattern = Pattern.compile("\\-\\-[\\s]*changeset (\\S+):(\\S+).*", Pattern.CASE_INSENSITIVE); Pattern rollbackPattern = Pattern.compile("\\s*\\-\\-[\\s]*rollback (.*)", Pattern.CASE_INSENSITIVE); Pattern preconditionsPattern = Pattern.compile("\\s*\\-\\-[\\s]*preconditions(.*)", Pattern.CASE_INSENSITIVE); Pattern preconditionPattern = Pattern.compile("\\s*\\-\\-[\\s]*precondition\\-([a-zA-Z0-9-]+) (.*)", Pattern.CASE_INSENSITIVE); Pattern stripCommentsPattern = Pattern.compile(".*stripComments:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern splitStatementsPattern = Pattern.compile(".*splitStatements:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern endDelimiterPattern = Pattern.compile(".*endDelimiter:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern runOnChangePattern = Pattern.compile(".*runOnChange:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern runAlwaysPattern = Pattern.compile(".*runAlways:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern contextPattern = Pattern.compile(".*context:(\\S+).*", Pattern.CASE_INSENSITIVE); Pattern runInTransactionPattern = Pattern.compile(".*runInTransaction:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern dbmsPattern = Pattern.compile(".*dbms:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern failOnErrorPattern = Pattern.compile(".*failOnError:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern onFailPattern = Pattern.compile(".*onFail:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern onErrorPattern = Pattern.compile(".*onError:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern onUpdateSqlPattern = Pattern.compile(".*onUpdateSQL:(\\w+).*", Pattern.CASE_INSENSITIVE); String line; while ((line = reader.readLine()) != null) { Matcher changeSetPatternMatcher = changeSetPattern.matcher(line); if (changeSetPatternMatcher.matches()) { String finalCurrentSql = changeLogParameters.expandExpressions(StringUtils.trimToNull(currentSql.toString())); if (changeSet != null) { if (finalCurrentSql == null) { throw new ChangeLogParseException("No SQL for changeset " + changeSet.toString(false)); } change.setSql(finalCurrentSql); if (StringUtils.trimToNull(currentRollbackSql.toString()) != null) { try { 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); } } catch (UnsupportedChangeException e) { throw new RuntimeException(e); } } } Matcher stripCommentsPatternMatcher = stripCommentsPattern.matcher(line); Matcher splitStatementsPatternMatcher = splitStatementsPattern.matcher(line); Matcher endDelimiterPatternMatcher = endDelimiterPattern.matcher(line); Matcher runOnChangePatternMatcher = runOnChangePattern.matcher(line); Matcher runAlwaysPatternMatcher = runAlwaysPattern.matcher(line); Matcher contextPatternMatcher = contextPattern.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 dbms = parseString(dbmsPatternMatcher); changeSet = new ChangeSet(changeSetPatternMatcher.group(2), changeSetPatternMatcher.group(1), runAlways, runOnChange, physicalChangeLogLocation, context, dbms, runInTransaction); 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 rollbackMatcher = rollbackPattern.matcher(line); Matcher preconditionsMatcher = preconditionsPattern.matcher(line); Matcher preconditionMatcher = preconditionPattern.matcher(line); 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) { 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) { try { 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); } } catch (UnsupportedChangeException e) { throw new RuntimeException(e); } } } } catch (IOException e) { throw new ChangeLogParseException(e); } finally { if (reader != null) { try { reader.close(); } catch (IOException ignore) { } } } return changeLog; }  }
FormattedSqlChangeLogParser implements ChangeLogParser { public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor) throws ChangeLogParseException { DatabaseChangeLog changeLog = new DatabaseChangeLog(); changeLog.setPhysicalFilePath(physicalChangeLogLocation); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(openChangeLogFile(physicalChangeLogLocation, resourceAccessor))); StringBuffer currentSql = new StringBuffer(); StringBuffer currentRollbackSql = new StringBuffer(); ChangeSet changeSet = null; RawSQLChange change = null; Pattern changeSetPattern = Pattern.compile("\\-\\-[\\s]*changeset (\\S+):(\\S+).*", Pattern.CASE_INSENSITIVE); Pattern rollbackPattern = Pattern.compile("\\s*\\-\\-[\\s]*rollback (.*)", Pattern.CASE_INSENSITIVE); Pattern preconditionsPattern = Pattern.compile("\\s*\\-\\-[\\s]*preconditions(.*)", Pattern.CASE_INSENSITIVE); Pattern preconditionPattern = Pattern.compile("\\s*\\-\\-[\\s]*precondition\\-([a-zA-Z0-9-]+) (.*)", Pattern.CASE_INSENSITIVE); Pattern stripCommentsPattern = Pattern.compile(".*stripComments:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern splitStatementsPattern = Pattern.compile(".*splitStatements:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern endDelimiterPattern = Pattern.compile(".*endDelimiter:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern runOnChangePattern = Pattern.compile(".*runOnChange:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern runAlwaysPattern = Pattern.compile(".*runAlways:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern contextPattern = Pattern.compile(".*context:(\\S+).*", Pattern.CASE_INSENSITIVE); Pattern runInTransactionPattern = Pattern.compile(".*runInTransaction:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern dbmsPattern = Pattern.compile(".*dbms:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern failOnErrorPattern = Pattern.compile(".*failOnError:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern onFailPattern = Pattern.compile(".*onFail:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern onErrorPattern = Pattern.compile(".*onError:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern onUpdateSqlPattern = Pattern.compile(".*onUpdateSQL:(\\w+).*", Pattern.CASE_INSENSITIVE); String line; while ((line = reader.readLine()) != null) { Matcher changeSetPatternMatcher = changeSetPattern.matcher(line); if (changeSetPatternMatcher.matches()) { String finalCurrentSql = changeLogParameters.expandExpressions(StringUtils.trimToNull(currentSql.toString())); if (changeSet != null) { if (finalCurrentSql == null) { throw new ChangeLogParseException("No SQL for changeset " + changeSet.toString(false)); } change.setSql(finalCurrentSql); if (StringUtils.trimToNull(currentRollbackSql.toString()) != null) { try { 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); } } catch (UnsupportedChangeException e) { throw new RuntimeException(e); } } } Matcher stripCommentsPatternMatcher = stripCommentsPattern.matcher(line); Matcher splitStatementsPatternMatcher = splitStatementsPattern.matcher(line); Matcher endDelimiterPatternMatcher = endDelimiterPattern.matcher(line); Matcher runOnChangePatternMatcher = runOnChangePattern.matcher(line); Matcher runAlwaysPatternMatcher = runAlwaysPattern.matcher(line); Matcher contextPatternMatcher = contextPattern.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 dbms = parseString(dbmsPatternMatcher); changeSet = new ChangeSet(changeSetPatternMatcher.group(2), changeSetPatternMatcher.group(1), runAlways, runOnChange, physicalChangeLogLocation, context, dbms, runInTransaction); 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 rollbackMatcher = rollbackPattern.matcher(line); Matcher preconditionsMatcher = preconditionsPattern.matcher(line); Matcher preconditionMatcher = preconditionPattern.matcher(line); 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) { 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) { try { 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); } } catch (UnsupportedChangeException e) { throw new RuntimeException(e); } } } } catch (IOException e) { throw new ChangeLogParseException(e); } finally { if (reader != null) { try { reader.close(); } catch (IOException ignore) { } } } return changeLog; }  boolean supports(String changeLogFile, ResourceAccessor resourceAccessor); int getPriority(); DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor); }
FormattedSqlChangeLogParser implements ChangeLogParser { public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor) throws ChangeLogParseException { DatabaseChangeLog changeLog = new DatabaseChangeLog(); changeLog.setPhysicalFilePath(physicalChangeLogLocation); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(openChangeLogFile(physicalChangeLogLocation, resourceAccessor))); StringBuffer currentSql = new StringBuffer(); StringBuffer currentRollbackSql = new StringBuffer(); ChangeSet changeSet = null; RawSQLChange change = null; Pattern changeSetPattern = Pattern.compile("\\-\\-[\\s]*changeset (\\S+):(\\S+).*", Pattern.CASE_INSENSITIVE); Pattern rollbackPattern = Pattern.compile("\\s*\\-\\-[\\s]*rollback (.*)", Pattern.CASE_INSENSITIVE); Pattern preconditionsPattern = Pattern.compile("\\s*\\-\\-[\\s]*preconditions(.*)", Pattern.CASE_INSENSITIVE); Pattern preconditionPattern = Pattern.compile("\\s*\\-\\-[\\s]*precondition\\-([a-zA-Z0-9-]+) (.*)", Pattern.CASE_INSENSITIVE); Pattern stripCommentsPattern = Pattern.compile(".*stripComments:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern splitStatementsPattern = Pattern.compile(".*splitStatements:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern endDelimiterPattern = Pattern.compile(".*endDelimiter:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern runOnChangePattern = Pattern.compile(".*runOnChange:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern runAlwaysPattern = Pattern.compile(".*runAlways:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern contextPattern = Pattern.compile(".*context:(\\S+).*", Pattern.CASE_INSENSITIVE); Pattern runInTransactionPattern = Pattern.compile(".*runInTransaction:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern dbmsPattern = Pattern.compile(".*dbms:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern failOnErrorPattern = Pattern.compile(".*failOnError:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern onFailPattern = Pattern.compile(".*onFail:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern onErrorPattern = Pattern.compile(".*onError:(\\w+).*", Pattern.CASE_INSENSITIVE); Pattern onUpdateSqlPattern = Pattern.compile(".*onUpdateSQL:(\\w+).*", Pattern.CASE_INSENSITIVE); String line; while ((line = reader.readLine()) != null) { Matcher changeSetPatternMatcher = changeSetPattern.matcher(line); if (changeSetPatternMatcher.matches()) { String finalCurrentSql = changeLogParameters.expandExpressions(StringUtils.trimToNull(currentSql.toString())); if (changeSet != null) { if (finalCurrentSql == null) { throw new ChangeLogParseException("No SQL for changeset " + changeSet.toString(false)); } change.setSql(finalCurrentSql); if (StringUtils.trimToNull(currentRollbackSql.toString()) != null) { try { 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); } } catch (UnsupportedChangeException e) { throw new RuntimeException(e); } } } Matcher stripCommentsPatternMatcher = stripCommentsPattern.matcher(line); Matcher splitStatementsPatternMatcher = splitStatementsPattern.matcher(line); Matcher endDelimiterPatternMatcher = endDelimiterPattern.matcher(line); Matcher runOnChangePatternMatcher = runOnChangePattern.matcher(line); Matcher runAlwaysPatternMatcher = runAlwaysPattern.matcher(line); Matcher contextPatternMatcher = contextPattern.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 dbms = parseString(dbmsPatternMatcher); changeSet = new ChangeSet(changeSetPatternMatcher.group(2), changeSetPatternMatcher.group(1), runAlways, runOnChange, physicalChangeLogLocation, context, dbms, runInTransaction); 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 rollbackMatcher = rollbackPattern.matcher(line); Matcher preconditionsMatcher = preconditionsPattern.matcher(line); Matcher preconditionMatcher = preconditionPattern.matcher(line); 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) { 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) { try { 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); } } catch (UnsupportedChangeException e) { throw new RuntimeException(e); } } } } catch (IOException e) { throw new ChangeLogParseException(e); } finally { if (reader != null) { try { reader.close(); } catch (IOException ignore) { } } } return changeLog; }  boolean supports(String changeLogFile, ResourceAccessor resourceAccessor); int getPriority(); DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor);  }