package com.yonge.toolset.datasource;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class DataSourceContextHolder {
	
	public final static String TENANT_ID = "master";

	private static final ThreadLocal<Object> contextHolder = new ThreadLocal<Object>() {
		@Override
		protected String initialValue() {
			return TENANT_ID;
		}
	};

	public static List<Object> dataSourceKeys = new ArrayList<Object>();

	public static void setDataSourceKey(String key) {
		contextHolder.set(key);
	}

	/**
	 * 获取数据源
	 * @return
	 */
	public static Object getDataSourceKey() {
		return contextHolder.get();
	}

	/**
	 * 重置数据源
	 */
	public static void clearDataSourceKey() {
		contextHolder.remove();
	}

	public static boolean containDataSourceKey(Object key) {
		return dataSourceKeys.contains(key);
	}

	public static boolean addDataSourceKeys(Collection<? extends Object> keys) {
		return dataSourceKeys.addAll(keys);
	}
}
