@Test public void multiChangeSetChangeLog() throws Exception { DatabaseChangeLog changeLog = new XMLChangeLogSAXParser().parse("liquibase/parser/core/xml/multiChangeSetChangeLog.xml", new ChangeLogParameters(), new JUnitResourceAccessor()); assertEquals("liquibase/parser/core/xml/multiChangeSetChangeLog.xml", changeLog.getLogicalFilePath()); assertEquals("liquibase/parser/core/xml/multiChangeSetChangeLog.xml", changeLog.getPhysicalFilePath()); assertEquals(0, changeLog.getPreconditions().getNestedPreconditions().size()); assertEquals(4, changeLog.getChangeSets().size()); ChangeSet changeSet = changeLog.getChangeSets().get(0); assertEquals("nvoxland", changeSet.getAuthor()); assertEquals("1", changeSet.getId()); assertEquals(1, changeSet.getChanges().size()); assertEquals("liquibase/parser/core/xml/multiChangeSetChangeLog.xml", changeSet.getFilePath()); assertNull(changeSet.getComments()); assertFalse(changeSet.shouldAlwaysRun()); assertFalse(changeSet.shouldRunOnChange()); Change change = changeSet.getChanges().get(0); assertEquals("createTable", change.getChangeMetaData().getName()); assertTrue(change instanceof CreateTableChange); changeSet = changeLog.getChangeSets().get(1); assertEquals("nvoxland", changeSet.getAuthor()); assertEquals("2", changeSet.getId()); assertEquals(2, changeSet.getChanges().size()); assertEquals("liquibase/parser/core/xml/multiChangeSetChangeLog.xml", changeSet.getFilePath()); assertEquals("Testing add column", changeSet.getComments()); assertTrue(changeSet.shouldAlwaysRun()); assertTrue(changeSet.shouldRunOnChange()); assertEquals(2, changeSet.getRollBackChanges().length); assertTrue(changeSet.getRollBackChanges()[0] instanceof RawSQLChange); assertTrue(changeSet.getRollBackChanges()[1] instanceof RawSQLChange); change = changeSet.getChanges().get(0); assertEquals("addColumn", change.getChangeMetaData().getName()); assertTrue(change instanceof AddColumnChange); change = changeSet.getChanges().get(1); assertEquals("addColumn", change.getChangeMetaData().getName()); assertTrue(change instanceof AddColumnChange); changeSet = changeLog.getChangeSets().get(2); assertEquals("bob", changeSet.getAuthor()); assertEquals("3", changeSet.getId()); assertEquals(1, changeSet.getChanges().size()); assertEquals("liquibase/parser/core/xml/multiChangeSetChangeLog.xml", changeSet.getFilePath()); assertNull(changeSet.getComments()); assertFalse(changeSet.shouldAlwaysRun()); assertFalse(changeSet.shouldRunOnChange()); change = changeSet.getChanges().get(0); assertEquals("createTable", change.getChangeMetaData().getName()); assertTrue(change instanceof CreateTableChange); changeSet = changeLog.getChangeSets().get(3); assertEquals(1, changeSet.getChanges().size()); change = changeSet.getChanges().get(0); assertTrue(change instanceof CustomChangeWrapper); CustomChangeWrapper wrapper = (CustomChangeWrapper) change; wrapper.generateStatements(null); assertTrue(wrapper.getCustomChange() instanceof ExampleCustomSqlChange); ExampleCustomSqlChange exChg = (ExampleCustomSqlChange) wrapper.getCustomChange(); assertEquals("table", exChg.getTableName()); assertEquals("column", exChg.getColumnName()); }
public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor) throws ChangeLogParseException { InputStream inputStream = null; try { SAXParser parser = saxParserFactory.newSAXParser(); try { parser.setProperty("http: } catch (SAXNotRecognizedException e) { } catch (SAXNotSupportedException e) { } XMLReader xmlReader = parser.getXMLReader(); LiquibaseEntityResolver resolver=new LiquibaseEntityResolver(); resolver.useResoureAccessor(resourceAccessor,FilenameUtils.getFullPath(physicalChangeLogLocation)); xmlReader.setEntityResolver(resolver); xmlReader.setErrorHandler(new ErrorHandler() { public void warning(SAXParseException exception) throws SAXException { LogFactory.getLogger().warning(exception.getMessage()); throw exception; } public void error(SAXParseException exception) throws SAXException { LogFactory.getLogger().severe(exception.getMessage()); throw exception; } public void fatalError(SAXParseException exception) throws SAXException { LogFactory.getLogger().severe(exception.getMessage()); throw exception; } }); inputStream = resourceAccessor.getResourceAsStream(physicalChangeLogLocation); if (inputStream == null) { throw new ChangeLogParseException(physicalChangeLogLocation + " does not exist"); } XMLChangeLogSAXHandler contentHandler = new XMLChangeLogSAXHandler(physicalChangeLogLocation, resourceAccessor, changeLogParameters); xmlReader.setContentHandler(contentHandler); xmlReader.parse(new InputSource(inputStream)); return contentHandler.getDatabaseChangeLog(); } catch (ChangeLogParseException e) { throw e; } catch (IOException e) { throw new ChangeLogParseException("Error Reading Migration File: " + e.getMessage(), e); } catch (SAXParseException e) { throw new ChangeLogParseException("Error parsing line " + e.getLineNumber() + " column " + e.getColumnNumber() + " of " + physicalChangeLogLocation +": " + e.getMessage(), e); } catch (SAXException e) { Throwable parentCause = e.getException(); while (parentCause != null) { if (parentCause instanceof ChangeLogParseException) { throw ((ChangeLogParseException) parentCause); } parentCause = parentCause.getCause(); } String reason = e.getMessage(); String causeReason = null; if (e.getCause() != null) { causeReason = e.getCause().getMessage(); } if (reason == null) { if (causeReason != null) { reason = causeReason; } else { reason = "Unknown Reason"; } } throw new ChangeLogParseException("Invalid Migration File: " + reason, e); } catch (Exception e) { throw new ChangeLogParseException(e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { } } } }
XMLChangeLogSAXParser implements ChangeLogParser { public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor) throws ChangeLogParseException { InputStream inputStream = null; try { SAXParser parser = saxParserFactory.newSAXParser(); try { parser.setProperty("http: } catch (SAXNotRecognizedException e) { } catch (SAXNotSupportedException e) { } XMLReader xmlReader = parser.getXMLReader(); LiquibaseEntityResolver resolver=new LiquibaseEntityResolver(); resolver.useResoureAccessor(resourceAccessor,FilenameUtils.getFullPath(physicalChangeLogLocation)); xmlReader.setEntityResolver(resolver); xmlReader.setErrorHandler(new ErrorHandler() { public void warning(SAXParseException exception) throws SAXException { LogFactory.getLogger().warning(exception.getMessage()); throw exception; } public void error(SAXParseException exception) throws SAXException { LogFactory.getLogger().severe(exception.getMessage()); throw exception; } public void fatalError(SAXParseException exception) throws SAXException { LogFactory.getLogger().severe(exception.getMessage()); throw exception; } }); inputStream = resourceAccessor.getResourceAsStream(physicalChangeLogLocation); if (inputStream == null) { throw new ChangeLogParseException(physicalChangeLogLocation + " does not exist"); } XMLChangeLogSAXHandler contentHandler = new XMLChangeLogSAXHandler(physicalChangeLogLocation, resourceAccessor, changeLogParameters); xmlReader.setContentHandler(contentHandler); xmlReader.parse(new InputSource(inputStream)); return contentHandler.getDatabaseChangeLog(); } catch (ChangeLogParseException e) { throw e; } catch (IOException e) { throw new ChangeLogParseException("Error Reading Migration File: " + e.getMessage(), e); } catch (SAXParseException e) { throw new ChangeLogParseException("Error parsing line " + e.getLineNumber() + " column " + e.getColumnNumber() + " of " + physicalChangeLogLocation +": " + e.getMessage(), e); } catch (SAXException e) { Throwable parentCause = e.getException(); while (parentCause != null) { if (parentCause instanceof ChangeLogParseException) { throw ((ChangeLogParseException) parentCause); } parentCause = parentCause.getCause(); } String reason = e.getMessage(); String causeReason = null; if (e.getCause() != null) { causeReason = e.getCause().getMessage(); } if (reason == null) { if (causeReason != null) { reason = causeReason; } else { reason = "Unknown Reason"; } } throw new ChangeLogParseException("Invalid Migration File: " + reason, e); } catch (Exception e) { throw new ChangeLogParseException(e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { } } } } }
XMLChangeLogSAXParser implements ChangeLogParser { public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor) throws ChangeLogParseException { InputStream inputStream = null; try { SAXParser parser = saxParserFactory.newSAXParser(); try { parser.setProperty("http: } catch (SAXNotRecognizedException e) { } catch (SAXNotSupportedException e) { } XMLReader xmlReader = parser.getXMLReader(); LiquibaseEntityResolver resolver=new LiquibaseEntityResolver(); resolver.useResoureAccessor(resourceAccessor,FilenameUtils.getFullPath(physicalChangeLogLocation)); xmlReader.setEntityResolver(resolver); xmlReader.setErrorHandler(new ErrorHandler() { public void warning(SAXParseException exception) throws SAXException { LogFactory.getLogger().warning(exception.getMessage()); throw exception; } public void error(SAXParseException exception) throws SAXException { LogFactory.getLogger().severe(exception.getMessage()); throw exception; } public void fatalError(SAXParseException exception) throws SAXException { LogFactory.getLogger().severe(exception.getMessage()); throw exception; } }); inputStream = resourceAccessor.getResourceAsStream(physicalChangeLogLocation); if (inputStream == null) { throw new ChangeLogParseException(physicalChangeLogLocation + " does not exist"); } XMLChangeLogSAXHandler contentHandler = new XMLChangeLogSAXHandler(physicalChangeLogLocation, resourceAccessor, changeLogParameters); xmlReader.setContentHandler(contentHandler); xmlReader.parse(new InputSource(inputStream)); return contentHandler.getDatabaseChangeLog(); } catch (ChangeLogParseException e) { throw e; } catch (IOException e) { throw new ChangeLogParseException("Error Reading Migration File: " + e.getMessage(), e); } catch (SAXParseException e) { throw new ChangeLogParseException("Error parsing line " + e.getLineNumber() + " column " + e.getColumnNumber() + " of " + physicalChangeLogLocation +": " + e.getMessage(), e); } catch (SAXException e) { Throwable parentCause = e.getException(); while (parentCause != null) { if (parentCause instanceof ChangeLogParseException) { throw ((ChangeLogParseException) parentCause); } parentCause = parentCause.getCause(); } String reason = e.getMessage(); String causeReason = null; if (e.getCause() != null) { causeReason = e.getCause().getMessage(); } if (reason == null) { if (causeReason != null) { reason = causeReason; } else { reason = "Unknown Reason"; } } throw new ChangeLogParseException("Invalid Migration File: " + reason, e); } catch (Exception e) { throw new ChangeLogParseException(e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { } } } } XMLChangeLogSAXParser(); }
XMLChangeLogSAXParser implements ChangeLogParser { public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor) throws ChangeLogParseException { InputStream inputStream = null; try { SAXParser parser = saxParserFactory.newSAXParser(); try { parser.setProperty("http: } catch (SAXNotRecognizedException e) { } catch (SAXNotSupportedException e) { } XMLReader xmlReader = parser.getXMLReader(); LiquibaseEntityResolver resolver=new LiquibaseEntityResolver(); resolver.useResoureAccessor(resourceAccessor,FilenameUtils.getFullPath(physicalChangeLogLocation)); xmlReader.setEntityResolver(resolver); xmlReader.setErrorHandler(new ErrorHandler() { public void warning(SAXParseException exception) throws SAXException { LogFactory.getLogger().warning(exception.getMessage()); throw exception; } public void error(SAXParseException exception) throws SAXException { LogFactory.getLogger().severe(exception.getMessage()); throw exception; } public void fatalError(SAXParseException exception) throws SAXException { LogFactory.getLogger().severe(exception.getMessage()); throw exception; } }); inputStream = resourceAccessor.getResourceAsStream(physicalChangeLogLocation); if (inputStream == null) { throw new ChangeLogParseException(physicalChangeLogLocation + " does not exist"); } XMLChangeLogSAXHandler contentHandler = new XMLChangeLogSAXHandler(physicalChangeLogLocation, resourceAccessor, changeLogParameters); xmlReader.setContentHandler(contentHandler); xmlReader.parse(new InputSource(inputStream)); return contentHandler.getDatabaseChangeLog(); } catch (ChangeLogParseException e) { throw e; } catch (IOException e) { throw new ChangeLogParseException("Error Reading Migration File: " + e.getMessage(), e); } catch (SAXParseException e) { throw new ChangeLogParseException("Error parsing line " + e.getLineNumber() + " column " + e.getColumnNumber() + " of " + physicalChangeLogLocation +": " + e.getMessage(), e); } catch (SAXException e) { Throwable parentCause = e.getException(); while (parentCause != null) { if (parentCause instanceof ChangeLogParseException) { throw ((ChangeLogParseException) parentCause); } parentCause = parentCause.getCause(); } String reason = e.getMessage(); String causeReason = null; if (e.getCause() != null) { causeReason = e.getCause().getMessage(); } if (reason == null) { if (causeReason != null) { reason = causeReason; } else { reason = "Unknown Reason"; } } throw new ChangeLogParseException("Invalid Migration File: " + reason, e); } catch (Exception e) { throw new ChangeLogParseException(e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { } } } } XMLChangeLogSAXParser(); int getPriority(); static String getSchemaVersion(); static String getDatabaseChangeLogNameSpace(); boolean supports(String changeLogFile, ResourceAccessor resourceAccessor); DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor); }
XMLChangeLogSAXParser implements ChangeLogParser { public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor) throws ChangeLogParseException { InputStream inputStream = null; try { SAXParser parser = saxParserFactory.newSAXParser(); try { parser.setProperty("http: } catch (SAXNotRecognizedException e) { } catch (SAXNotSupportedException e) { } XMLReader xmlReader = parser.getXMLReader(); LiquibaseEntityResolver resolver=new LiquibaseEntityResolver(); resolver.useResoureAccessor(resourceAccessor,FilenameUtils.getFullPath(physicalChangeLogLocation)); xmlReader.setEntityResolver(resolver); xmlReader.setErrorHandler(new ErrorHandler() { public void warning(SAXParseException exception) throws SAXException { LogFactory.getLogger().warning(exception.getMessage()); throw exception; } public void error(SAXParseException exception) throws SAXException { LogFactory.getLogger().severe(exception.getMessage()); throw exception; } public void fatalError(SAXParseException exception) throws SAXException { LogFactory.getLogger().severe(exception.getMessage()); throw exception; } }); inputStream = resourceAccessor.getResourceAsStream(physicalChangeLogLocation); if (inputStream == null) { throw new ChangeLogParseException(physicalChangeLogLocation + " does not exist"); } XMLChangeLogSAXHandler contentHandler = new XMLChangeLogSAXHandler(physicalChangeLogLocation, resourceAccessor, changeLogParameters); xmlReader.setContentHandler(contentHandler); xmlReader.parse(new InputSource(inputStream)); return contentHandler.getDatabaseChangeLog(); } catch (ChangeLogParseException e) { throw e; } catch (IOException e) { throw new ChangeLogParseException("Error Reading Migration File: " + e.getMessage(), e); } catch (SAXParseException e) { throw new ChangeLogParseException("Error parsing line " + e.getLineNumber() + " column " + e.getColumnNumber() + " of " + physicalChangeLogLocation +": " + e.getMessage(), e); } catch (SAXException e) { Throwable parentCause = e.getException(); while (parentCause != null) { if (parentCause instanceof ChangeLogParseException) { throw ((ChangeLogParseException) parentCause); } parentCause = parentCause.getCause(); } String reason = e.getMessage(); String causeReason = null; if (e.getCause() != null) { causeReason = e.getCause().getMessage(); } if (reason == null) { if (causeReason != null) { reason = causeReason; } else { reason = "Unknown Reason"; } } throw new ChangeLogParseException("Invalid Migration File: " + reason, e); } catch (Exception e) { throw new ChangeLogParseException(e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { } } } } XMLChangeLogSAXParser(); int getPriority(); static String getSchemaVersion(); static String getDatabaseChangeLogNameSpace(); boolean supports(String changeLogFile, ResourceAccessor resourceAccessor); DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor);  }