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

com.sap.cds.feature.postgresql.PostgreSqlDataSourceDescriptorFactory Maven / Gradle / Ivy

The newest version!
/**************************************************************************
 * (C) 2019-2024 SAP SE or an SAP affiliate company. All rights reserved. *
 **************************************************************************/
package com.sap.cds.feature.postgresql;

import java.util.List;
import java.util.stream.Collectors;

import com.sap.cds.services.datasource.DataSourceDescriptor;
import com.sap.cds.services.datasource.DataSourceDescriptorFactory;
import com.sap.cds.services.runtime.CdsRuntime;
import com.sap.cds.services.runtime.CdsRuntimeAware;
import com.sap.cds.services.utils.environment.ServiceBindingUtils;

/**
 * {@link DataSourceDescriptorFactory} for {@link PostgreSqlDataSourceDescriptor}
 */
public class PostgreSqlDataSourceDescriptorFactory implements DataSourceDescriptorFactory, CdsRuntimeAware {

	private static final String POSTGRESQL = "postgresql";
	private static final String POSTGRESQL_DB = "postgresql-db";

	private CdsRuntime runtime;

	@Override
	public void setCdsRuntime(CdsRuntime runtime) {
		this.runtime = runtime;
	}

	@Override
	public List create() {
		return runtime.getEnvironment().getServiceBindings()
				.filter(b ->
					ServiceBindingUtils.matches(b, POSTGRESQL)
							|| ServiceBindingUtils.matches(b, POSTGRESQL_DB)
				)
				.filter(b -> b.getTags() == null || !b.getTags().contains("mt-enabled"))
				.map(b -> new PostgreSqlDataSourceDescriptor(b))
				.collect(Collectors.toList());
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy