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

com.sap.cloud.mt.runtime.TomcatDataSourceLookup 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;

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


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

    public TomcatDataSourceLookup(InstanceLifecycleManager instanceLifecycleManager, EnvironmentAccess environment,
                                  DataPoolSettings poolSettings, boolean oneDataSourcePerDb) {
        this(instanceLifecycleManager, environment, poolSettings, oneDataSourcePerDb, false);
    }

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

    @Override
    public void closeDataSource(DataSource dataSource) {
        if (dataSource == null) {
            return;
        }
        logger.debug("Close Tomcat pooling data source");
        org.apache.tomcat.jdbc.pool.DataSource tomcatDataSource = (org.apache.tomcat.jdbc.pool.DataSource) dataSource;
        tomcatDataSource.close();
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy