package com.bcxin.risk.config;

public class DataSourceHolder  {
	/**
	 * 子站主库数据源
	 */
	public static final String MASTER_DATA_SOURCE ="masterDataSource";
	/**
	 * 政务网库数据源
	 */
	public static final String GOV_DATA_SOURCE ="govDataSource";

	//用ThreadLocal来设置当前线程使用哪个dataSource
	private static final ThreadLocal<String> contextHolder = new ThreadLocal<String>();

	//设置当前线程要使用的数据源
	public static void setDataSourceType(String dataSourceType) {
		contextHolder.set(dataSourceType);
	}
	/**
	 * 获取要当前线程的数据源
	 */
	public static String getDataSourceType() {
		return contextHolder.get();
	}
	/**
	 *
	 * 清楚掉当前线程的数据源
	 */
	public static void clearDataSourceType() {
		contextHolder.remove();
	}
	/**
	 * 切换数据源
	 */
	public static void changeCurrentDataSource(String dataSourceType) {
		clearDataSourceType();
		setDataSourceType(dataSourceType);
	}
	/**
	 * 切换回默认数据源
	 */
	public static void change2DefaulDataSource() {
		clearDataSourceType();
	}

	public static String getCustomerType() {
		return contextHolder.get();
	}
	public static void clearCustomerType() {
		contextHolder.remove();
	}
	public static void setCustomerType(String customerType) {
		contextHolder.set(customerType);
	}
}
