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

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

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

import static com.sap.cds.util.CdsTypeUtils.sqlTimestamp;

import java.sql.Connection;
import java.sql.SQLException;
import java.time.Instant;
import java.util.Map;
import java.util.Map.Entry;

import com.sap.cds.jdbc.spi.SessionVariableSetter;

public class HanaSessionVariableSetter implements SessionVariableSetter {

	@Override
	public void set(Connection conn, Map contextVariables) throws SQLException {
		for (Entry setting : contextVariables.entrySet()) {
			set(conn, setting.getKey(), setting.getValue());
		}

	}

	private void set(Connection conn, String key, Object value) throws SQLException {
		String val = switch (key) {
			case VALID_FROM, VALID_TO -> sqlTimestamp((Instant) value, 7);
			default -> value != null ? value.toString() : null;
		};
		if (TENANT.equals(key)) {
			key = "APPLICATIONTENANT";
		}
		conn.setClientInfo(key, val);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy