package inventory;

import java.util.Properties;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;

import com.atomikos.jdbc.AtomikosDataSourceBean;

@SpringBootApplication
@PropertySource("classpath:inventory.properties")
public class InventoryApplication extends SpringBootServletInitializer {

	public static void main(String[] args) {
		System.setProperty("com.atomikos.icatch.rest_port_url", "http://localhost:9091/transactions/atomikos"); 
		new InventoryApplication()
		.configure(new SpringApplicationBuilder(InventoryApplication.class))
		.run(args);
	}
	
	
	@Bean
	public AtomikosDataSourceBean dataSourceBean() {
		AtomikosDataSourceBean ds = new AtomikosDataSourceBean();
		ds.setUniqueResourceName("inventory");
		ds.setXaDataSourceClassName("org.h2.jdbcx.JdbcDataSource");
		Properties xaProperties = new Properties();
		xaProperties.setProperty("URL", "jdbc:h2:mem:inventory");
		xaProperties.setProperty("user", "sa");
		ds.setXaProperties(xaProperties);
		// OPTIONAL pool size
		ds.setPoolSize(5);
		// OPTIONAL timeout in secs between pool cleanup tasks
		ds.setBorrowConnectionTimeout(60);

		return ds;
	}
}
