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

com.sap.cds.mtx.impl.CdsDataStoreConnectorCreatorImpl Maven / Gradle / Ivy

/*
 * ----------------------------------------------------------------
 * © 2019-2021 SAP SE or an SAP affiliate company. All rights reserved.
 * ----------------------------------------------------------------
 *
 */

package com.sap.cds.mtx.impl;

import com.sap.cds.CdsDataStoreConnector;
import com.sap.cds.DataStoreConfiguration;
import com.sap.cds.impl.JDBCDataStoreConnector;
import com.sap.cds.impl.SystemPropertyDataStoreConfiguration;
import com.sap.cds.mtx.CdsDataStoreConnectorCreator;
import com.sap.cds.mtx.MetaDataAccessor;
import com.sap.cds.transaction.TransactionManager;

import javax.sql.DataSource;
import java.util.function.Function;

public class CdsDataStoreConnectorCreatorImpl implements CdsDataStoreConnectorCreator {
	private final MetaDataAccessor metaDataAccessor;
	private final Function dataSourceForTenant;
	private final TransactionManager cdsTransactionManager;
	private final DataStoreConfiguration config;

	public CdsDataStoreConnectorCreatorImpl(MetaDataAccessor metaDataAccessor,
			Function dataSourceForTenant, TransactionManager cdsTransactionManager,
			DataStoreConfiguration config) {
		this.metaDataAccessor = metaDataAccessor;
		this.dataSourceForTenant = dataSourceForTenant;
		this.cdsTransactionManager = cdsTransactionManager;
		this.config = config;
	}

	public CdsDataStoreConnectorCreatorImpl(MetaDataAccessor metaDataAccessor,
			Function dataSourceForTenant, TransactionManager cdsTransactionManager) {
		this(metaDataAccessor, dataSourceForTenant, cdsTransactionManager, new SystemPropertyDataStoreConfiguration());
	}

	@Override
	public CdsDataStoreConnector create(String tenantId) {
		return JDBCDataStoreConnector.create(metaDataAccessor.getCdsModel(tenantId), cdsTransactionManager)
				.datasource(dataSourceForTenant.apply(tenantId)).config(config).build();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy