/**
 * 
 */
package org.springblade.datasource.context;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.springblade.datasource.IGmetryDialect;
import org.springblade.datasource.enums.DsTypeEnum;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

/**
 * @author wookvn
 *
 */
@Slf4j
@Component
public class DialectContext {

	private final Map<DsTypeEnum, IGmetryDialect> dialectMap = new ConcurrentHashMap<>();
	
	public DialectContext(List<IGmetryDialect> dialectList) {
		log.info(":::::::[开始]注入数据库方言:::::::");
		dialectList.forEach(item -> {
			log.info("=====>>注入数据库方言:{}", item.dsType().name());
			dialectMap.put(item.dsType(), item);
		});
		log.info(":::::::[结束]注入数据库方言:::::::");
	}
	
	/**
	 * 获取
	 * @param dsType
	 * @return
	 */
	public IGmetryDialect getDialect(DsTypeEnum dsType) {
		return dialectMap.get(dsType);
	}
}
