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

com.sap.cloud.mt.runtime.GenericConnectionProvider Maven / Gradle / Ivy

There is a newer version: 3.3.3
Show newest version
/******************************************************************************
 * © 2020 SAP SE or an SAP affiliate company. All rights reserved.            *
 ******************************************************************************/

package com.sap.cloud.mt.runtime;

import com.sap.cloud.mt.subscription.DataSourceInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.SQLException;

public class GenericConnectionProvider implements ConnectionProvider {
    private static Logger logger = LoggerFactory.getLogger(GenericConnectionProvider.class);

    @Override
    public Connection getConnection(String tenantId, DataSourceAndInfo dataSourceAndInfo) throws SQLException {
        DataSourceInfo info = dataSourceAndInfo.getDataSourceInfo();
        Connection connection = dataSourceAndInfo.getDataSource().getConnection();//NOSONAR
        logger.debug("Set schema to {}", info.getSchema());
        connection.setSchema(info.getSchema());
        if (!connection.getSchema().equals(info.getSchema())) {
            connection.close();
            throw new SQLException("Could not set schema " + info.getSchema());
        }
        return connection;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy