

package org.intellij.xquery.runner.rt.xqj;

import org.intellij.xquery.runner.rt.XQueryRunConfig;

import javax.xml.xquery.XQConnection;
import javax.xml.xquery.XQDataSource;

public class ConnectionFactory {
    private final XQueryRunConfig config;

    public ConnectionFactory(XQueryRunConfig config) {
        this.config = config;
    }

    public XQConnection getConnection(XQDataSource dataSource) throws Exception {
        XQConnection connection;
        if (config.getDataSourceType().connectionPropertiesAreSupported()
                && config.getUsername() != null && config.getUsername().length() > 0) {
            connection = dataSource.getConnection(config.getUsername(), config.getPassword());
        } else {
            connection = dataSource.getConnection();
        }
        return connection;
    }
}