package kr.gmtc.tss.db;

import javax.sql.DataSource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
//@MapperScan(value = "kr.gmtc.eyesvtss.mapper", sqlSessionFactoryRef = "batchSqlSessionFactory" )
@EnableTransactionManagement
public class DbConfig {
	
	@Bean(name = "dbDataSource")
	@ConfigurationProperties(prefix = "spring.db.datasource")
	public DataSource db5DataSource() {

		return DataSourceBuilder.create().build();
	}

	@Bean(name="batchSqlSessionFactory")
    public SqlSessionFactory batchSqlSessionFactoryBean(@Qualifier("dbDataSource") DataSource batchDataSource, ApplicationContext applicationContext)
            throws Exception {
        SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
        factoryBean.setDataSource(batchDataSource);
    	factoryBean.setConfigLocation(applicationContext.getResource("classpath:/mybatis-config.xml"));
        return factoryBean.getObject();
    }
//	
//	@Bean(name = "packetQ")
//	public Queue<String> packetQ(){
//		return new LinkedBlockingQueue<String>();
//	}	
}

