@Test public void nestedRelativeChangeLog() throws Exception { final String nestedFileName = "liquibase/parser/core/xml/nestedRelativeChangeLog.xml"; DatabaseChangeLog changeLog = new XMLChangeLogSAXParser().parse(nestedFileName, new ChangeLogParameters(), new JUnitResourceAccessor()); nestedFileAssertions(changeLog, nestedFileName); }
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);  }