com.liquibase.ext.parser.JavaScriptMongoshChangeLogParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of liquibase-commercial-mongodb Show documentation
Show all versions of liquibase-commercial-mongodb Show documentation
Liquibase Commercial Extension for MongoDB
The newest version!
package com.liquibase.ext.parser;
import liquibase.changelog.ChangeLogParameters;
import liquibase.changelog.DatabaseChangeLog;
import liquibase.exception.ChangeLogParseException;
import liquibase.parser.ChangeLogParser;
import liquibase.resource.Resource;
import liquibase.resource.ResourceAccessor;
import liquibase.util.FileUtil;
import java.io.IOException;
import java.util.ResourceBundle;
public class JavaScriptMongoshChangeLogParser implements ChangeLogParser {
private static final ResourceBundle mongoshBundle = ResourceBundle.getBundle("liquibase/i18n/liquibase-mongosh");
private static final String CHANGELOG_IS_NOT_SUPPORTED = mongoshBundle.getString("changelog.is.not.supported");
@Override
public boolean supports(String changeLogFile, ResourceAccessor resourceAccessor) {
return changeLogFile.toLowerCase().endsWith(".js");
}
@Override
public int getPriority() {
return PRIORITY_DEFAULT;
}
@Override
public DatabaseChangeLog parse(String physicalChangeLogLocation, ChangeLogParameters changeLogParameters, ResourceAccessor resourceAccessor) throws ChangeLogParseException {
try {
Resource resource = resourceAccessor.get(physicalChangeLogLocation);
if (!resource.exists()) {
throw new ChangeLogParseException(FileUtil.getFileNotFoundMessage(physicalChangeLogLocation));
}
} catch (IOException e) {
throw new ChangeLogParseException(e);
}
throw new ChangeLogParseException(String.format(CHANGELOG_IS_NOT_SUPPORTED, physicalChangeLogLocation, "1", "// liquibase formatted mongo"));
}
}