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

com.sap.cloud.mt.runtime.HikariDataSourceLookup 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 com.sap.cloud.mt.subscription.InstanceLifecycleManager;
import com.sap.cloud.mt.subscription.exceptions.InternalError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.sql.DataSource;
import java.io.Closeable;
import java.io.IOException;

public class HikariDataSourceLookup extends DataSourceLookup {
    private static Logger logger = LoggerFactory.getLogger(HikariDataSourceLookup.class);
    private final EnvironmentAccess environment;
    private final DataPoolSettings poolSettings;


    public HikariDataSourceLookup(InstanceLifecycleManager instanceLifecycleManager, EnvironmentAccess environment,
                                  DataPoolSettings poolSettings, boolean oneDataSourcePerDb) {
        super(instanceLifecycleManager, oneDataSourcePerDb);
        this.environment = environment;
        this.poolSettings = poolSettings;
    }

    @Override
    public DataSource create(DataSourceInfo info) throws InternalError {
        DataSourceCreator dataSourceCreator = null;
        logger.debug("Hikari data source pool taken");
        dataSourceCreator = new DataSourceCreatorHikari(poolSettings);
        return dataSourceCreator.create(info, environment);
    }

    @Override
    public void closeDataSource(DataSource dataSource) {
        if (dataSource == null) {
            return;
        }
        logger.debug("Close Hikari data source pool");
        Closeable closeable = (Closeable) dataSource;
        try {
            closeable.close();
        } catch (IOException e) {
            logger.error("Could not close Hikari data source pool ", e);
        }
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy