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

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

The newest version!
/*******************************************************************************
 *   © 2019-2024 SAP SE or an SAP affiliate company. All rights reserved.
 ******************************************************************************/

package com.sap.cloud.mt.runtime;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.function.BiFunction;


public class ConnectionProviderFunction implements BiFunction {
	private static final ConnectionProvider HANA_CONNECTION_PROVIDER = new HanaConnectionProvider();
	private static final ConnectionProvider GENERIC_CONNECTION_PROVIDER = new GenericConnectionProvider();
	private static final ConnectionProvider SCHEMALESS_CONNECTION_PROVIDER = new SchemalessConnectionProvider();
	private static final ConnectionProvider GENERIC_CONNECTION_PROVIDER_ONE_POOL_PER_TENANT = new GenericConnectionProviderOnePoolPerTenant();
	private static final Logger logger = LoggerFactory.getLogger(ConnectionProviderFunction.class);
	private static final String USE_GENERIC_CONNECTION_PROVIDER = "Use generic connection provider";
	private static final String USE_GENERIC_CONNECTION_PROVIDER_ONE_POOL_PER_TENANT = "Use generic connection provider one pool per tenant";

	public ConnectionProvider apply(String driver, Boolean onDataSourcePerDb) {
		if (onDataSourcePerDb == null) {
			onDataSourcePerDb = false;
		}
		switch (driver) {
			case "com.sap.db.jdbc.Driver":
				if (onDataSourcePerDb) {
					logger.debug("Use HANA connection provider");
					return HANA_CONNECTION_PROVIDER;
				} else {
					logger.debug(USE_GENERIC_CONNECTION_PROVIDER_ONE_POOL_PER_TENANT);
					return GENERIC_CONNECTION_PROVIDER_ONE_POOL_PER_TENANT;
				}
			case "org.sqlite.JDBC":
				return SCHEMALESS_CONNECTION_PROVIDER;
			default:
				logger.debug(USE_GENERIC_CONNECTION_PROVIDER);
				return GENERIC_CONNECTION_PROVIDER;
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy