package com.yuyu.srdisassemble.data;

import com.yuyu.srdisassemble.SrDisassemble;
import org.apache.ibatis.datasource.DataSourceFactory;
import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory;

import java.util.Properties;

public class DataSource implements DataSourceFactory {
    private static UnpooledDataSourceFactory unpooledDataSourceFactory = new UnpooledDataSourceFactory();


    public DataSource(){


    }


    @Override
    public void setProperties(Properties props) {
        props.setProperty("driver", SrDisassemble.getConfigManager().getDriver());
    props.setProperty("url", SrDisassemble.getConfigManager().getUrl());


        props.setProperty("username", SrDisassemble.getConfigManager().getUsername());
        props.setProperty("password", SrDisassemble.getConfigManager().getPassword());


    }

    @Override
    public javax.sql.DataSource getDataSource() {
        Properties props = new Properties();
        props.setProperty("driver", SrDisassemble.getConfigManager().getDriver());
        props.setProperty("url", SrDisassemble.getConfigManager().getUrl());
        props.setProperty("username", SrDisassemble.getConfigManager().getUsername());
        props.setProperty("password", SrDisassemble.getConfigManager().getPassword());

        unpooledDataSourceFactory.setProperties(props);
        return unpooledDataSourceFactory.getDataSource();
    }
}
