All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liquibase.ext.parser.JavaScriptMongoshChangeLogParser Maven / Gradle / Ivy

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"));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy