package com.eactive.eai.rms.common.datasource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

import com.eactive.eai.rms.data.config.TenantIdentifierResolver;

public class RoutingDataSource extends AbstractRoutingDataSource {

	@Autowired
	private TenantIdentifierResolver tenantIdentifierResolver;

	@Override
	protected Object determineCurrentLookupKey() {
		return tenantIdentifierResolver.resolveCurrentTenantIdentifier();
	}

	@Override
	public String toString() {
		return new StringBuilder()
				.append(super.toString())
				.append(":[")
				.append(DataSourceContextHolder.getDataSourceType())
				.append("]")
				.toString();
	}

}
