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

com.sap.cds.jdbc.generic.LocaleVariableTableNameResolver Maven / Gradle / Ivy

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

import static com.sap.cds.impl.localized.LocaleUtils.isLocalized;

import java.util.Locale;
import java.util.function.Function;

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

import com.sap.cds.jdbc.spi.SqlMapping;
import com.sap.cds.jdbc.spi.TableNameResolver;
import com.sap.cds.reflect.CdsEntity;
import com.sap.cds.reflect.CdsStructuredType;

/**
 * A {@link TableNameResolver} that resolves localized strings using
 * locale-unspecific views using session variables
 */
public class LocaleVariableTableNameResolver implements TableNameResolver {
	private static final Logger logger = LoggerFactory.getLogger(LocaleVariableTableNameResolver.class);

	private final Function mapping;
	private final Locale locale;

	public LocaleVariableTableNameResolver(Function mapping, Locale locale) {
		this.mapping = mapping;
		this.locale = locale;
	}

	@Override
	public String tableName(CdsEntity entity) {
		SqlMapping sqlMapping = mapping.apply(entity);
		if (isLocalized(entity) && locale != null) {
			return sqlMapping.localizedViewName();
		}
		logger.debug("Resolve to plain table name due to missing locale.");
		return sqlMapping.tableName();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy