package com.hzya.frame.datasource;

import com.alibaba.druid.pool.DruidDataSource;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.hzya.frame.web.entity.BaseEntity;
import com.hzya.frame.web.exception.BaseSystemException;
import org.apache.ibatis.mapping.DatabaseIdProvider;
import org.apache.ibatis.mapping.VendorDatabaseIdProvider;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * @Auther: xiang2lin
 * @Date: 2020/3/31 10:25
 * 数据源工具类
 */
@Component
public class DataSourceUtil {
    @Bean
    public  DatabaseIdProvider getDatabaseIdProvider() {
        //DBMS 后缀
        //Oracle oracle
        //DB2 db2
        //MSSQLServer mssql
        //MySQL mysql
        //PostgreSQL postgre
        //Firebird firebird
        //MaxDB maxdb
        //HSQL hsql
        //Derby derby
        //H2 h2
        //Sybase(1.0.43以后) sybase
        VendorDatabaseIdProvider dbProvider = new VendorDatabaseIdProvider();
        Properties setPro = new Properties();
        //此处可以添加其他的数据库型号.如MySQL这类厂商标识一定不要写错！！
        setPro.setProperty("MySQL", "mysql");  //MySQL必须这样写，但是mysql可以随意写，后面代码同此处.
        setPro.setProperty("Oracle", "oracle");
        setPro.setProperty("DM DBMS", "dm");
        dbProvider.setProperties(setPro);
        return dbProvider;
    }
}
