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

com.sap.cds.jdbc.hana.HanaDbContext Maven / Gradle / Ivy

There is a newer version: 3.4.0
Show newest version
/************************************************************************
 * © 2020-2023 SAP SE or an SAP affiliate company. All rights reserved. *
 ************************************************************************/
package com.sap.cds.jdbc.hana;

import java.util.Locale;
import java.util.TimeZone;

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

import com.sap.cds.CdsDataStoreConnector;
import com.sap.cds.CdsDataStoreConnector.Capabilities;
import com.sap.cds.DataStoreConfiguration;
import com.sap.cds.jdbc.generic.GenericDbContext;
import com.sap.cds.jdbc.generic.LocaleVariableTableNameResolver;
import com.sap.cds.jdbc.hana.search.HanaSearchResolver;
import com.sap.cds.jdbc.spi.ExceptionAnalyzer;
import com.sap.cds.jdbc.spi.PredicateMapper;
import com.sap.cds.jdbc.spi.SearchResolver;
import com.sap.cds.jdbc.spi.SessionVariableSetter;
import com.sap.cds.jdbc.spi.StatementResolver;
import com.sap.cds.jdbc.spi.TableNameResolver;
import com.sap.cds.jdbc.spi.ValueBinder;
import com.sap.cds.reflect.CdsModel;

public final class HanaDbContext extends GenericDbContext {
	private static final Logger logger = LoggerFactory.getLogger(HanaDbContext.class);
	private final int majorVersion;

	public HanaDbContext(DataStoreConfiguration dataStoreConfiguration, int majorVersion) {
		super(dataStoreConfiguration);
		this.majorVersion = majorVersion;
	}

	@Override
	public TableNameResolver createTableNameResolver(Locale locale) {
		return new LocaleVariableTableNameResolver(this::getSqlMapping, locale);
	}

	@Override
	public SearchResolver createSearchResolver(CdsModel model, Locale locale) {
		boolean useLocalizedViewSearchResolver = dataStoreConfiguration
				.getProperty(DataStoreConfiguration.USE_LOCALIZED_VIEW_SEARCH_RESOLVER, false);

		if (useLocalizedViewSearchResolver) {
			logger.debug("Switched to LocalizedViewSearchResolver due to provided configuration.");
			return new LocalizedViewSearchResolver(model, locale);
		}
		return new HanaSearchResolver(model, locale);
	}

	@Override
	public StatementResolver getStatementResolver() {
		return new HanaStatementResolver(dataStoreConfiguration, majorVersion);
	}

	@Override
	public PredicateMapper getPredicateMapper() {
		return new HanaPredicateMapper();
	}

	@Override
	public ExceptionAnalyzer getExceptionAnalyzer() {
		return new HanaExceptionAnalyzer();
	}

	@Override
	public Capabilities getCapabilities() {
		return CdsDataStoreConnector.Capabilities.ALL;
	}

	@Override
	public ValueBinder getBinder(TimeZone timeZone) {
		return new HanaBinder(timeZone);
	}

	@Override
	public SessionVariableSetter getSessionVariableSetter() {
		return new HanaSessionVariableSetter();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy