package com.liangjian.dataplatform.member.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * @Author: 黄子奇
 * @Date: 2019/11/11
 */

@Configuration
public class DataSourceConfig {
    @Bean(name = "primaryDataSource")
    @Primary
    @Qualifier("primaryDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.primary")
    public DataSource primaryDatasource() {
        //return DataSourceBuilder.create().build();
        return new DruidDataSource(); //druid数据源
    }

    @Bean(name = "secondaryDataSource")
    @Qualifier("secondaryDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.secondary")
    public DataSource secondaryDataSource() {
        //return DataSourceBuilder.create().build();
        return new DruidDataSource(); //druid数据源
    }

    @Bean(name = "fourthlyDataSource")
    @Qualifier("fourthlyDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.fourthly")
    public DataSource fourthlyDataSource() {
        //return DataSourceBuilder.create().build();
        return new DruidDataSource(); //druid数据源
    }

    //正式库用的，这里只允许读
    @Bean(name = "tertiaryDataSource")
    @Qualifier("tertiaryDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.tertiary")
    public DataSource tertiaryDataSource() {
        return new DruidDataSource();
    }

    //分表库，基本配置信息的
    @Bean(name = "subtablesDataSource")
    @Qualifier("subtablesDataSource")
    @ConfigurationProperties(prefix = "sharding.jdbc.datasource.subtables")
    public DataSource subtablesDataSourceConfig() {
        return new DruidDataSource();
    }

//    //分表库，基本配置信息的
//    @Bean(name = "subtablesDataSource1")
//    @ConfigurationProperties(prefix = "dataSources.ds0")
//    public DataSource subtables1DataSourceConfig() {
//        return new DruidDataSource();
//    }
}
