package cn.fateverse.query.factory.impl;

import cn.fateverse.query.entity.DataSourceManage;
import cn.fateverse.query.mapper.DynamicDataSourceMapper;
import cn.fateverse.query.mapper.dynamic.MariaDynamicDataSourceMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;


/**
 * @author Clay
 * @date 2023-07-23
 */
public class MariaDynamicDataSourceFactory extends AbstractDynamicDataSourceFactory {

    @Override
    public SqlSessionFactory getSqlSessionFactory(DataSourceManage dataSourceManage) {
        return super.getSqlSessionFactory(dataSourceManage, "classpath:mapper/dynamic/MariaDynamicDataSourceMapper.xml");
    }

    @Override
    public DynamicDataSourceMapper getTableMapper(SqlSession sqlSession) {
        return sqlSession.getMapper(MariaDynamicDataSourceMapper.class);
    }

    @Override
    public String getDataBaseUrl(DataSourceManage dataSource) {
        return "jdbc:mariadb://" + dataSource.getHost() + ":" + dataSource.getPort() + "/" + dataSource.getDbName() + dataSource.getArgs();
    }

}
