package com.philisense.www.dynamic.druid.conf;

import java.util.Map;
import javax.sql.DataSource;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;


/**
 * 动态数据源
 * 
 */
public class DynamicDataSource extends AbstractRoutingDataSource
{
    public DynamicDataSource(DataSource defaultTargetDataSource, Map<Object, Object> targetDataSources)
    {
        super.setDefaultTargetDataSource(defaultTargetDataSource);
        super.setTargetDataSources(targetDataSources);
        super.afterPropertiesSet();        
        setRouterTargetDataSources(targetDataSources);
    }

    @Override
    protected Object determineCurrentLookupKey()
    {
        return DynamicDataSourceContextHolder.getDataSourceType();
    }
    
    private  Map<Object, Object> routerTargetDataSources;

	public Map<Object, Object> getRouterTargetDataSources() {
		return routerTargetDataSources;
	}

	public void setRouterTargetDataSources(Map<Object, Object> routerTargetDataSources) {
		this.routerTargetDataSources = routerTargetDataSources;
	}
}