package com.style24.core.support.config;

import javax.naming.NamingException;
import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.gagaframework.web.core.config.GagaJndiBaseConfig;

/**
 * Shop Transaction Manager 설정
 * 
 * @author gagamel
 * @since 2020. 10. 5
 */
@Configuration
@Lazy
@EnableTransactionManagement
public class TscJndiShopConfig extends GagaJndiBaseConfig {

	/**
	 * destroyMethod = "close" 속성은 apache commons DBCP와 BasicDataSource 등에서
	 * 즉시 DataSource를 종료하고자 할 때에 사용하는 것으로 DriverManagerDataSource에서는 필요하지 않다.
	 */
	@Override
//	@Bean(name = "defaultDataSource", destroyMethod = "close")
	@Bean(name = "shopDataSource")
	public DataSource dataSource() throws IllegalArgumentException, NamingException {
		return super.getDataSource("jdbc/shopDs");
	}

	@Override
	@Bean(name = "shopTxnManager")
	public PlatformTransactionManager transactionManager(@Qualifier("shopDataSource") DataSource dataSource) throws NamingException {
		return super.getTransactionManager(dataSource);
	}

}
