package com.javahonk;

import java.time.LocalDate;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.javahonk.dao.GenericDao;
import com.javahonk.dao.InterestRateDao;
import com.javahonk.model.EquitySwapInterestRateModel;
import com.javahonk.model.EquitySwapTestModel;

public class SpringHibernateMultipleTestApp {

	private static final Logger logger = LogManager.getLogger(SpringHibernateMultipleTestApp.class.getName());

	@SuppressWarnings({ "unchecked" })
	public static void main(String[] args) {

		logger.info("Starting HibernateTestApp...");

		ApplicationContext context = new ClassPathXmlApplicationContext("spring-context.xml");

		GenericDao<?> genericDao = context.getBean(GenericDao.class);
		InterestRateDao<?> interestRateDao = context.getBean(InterestRateDao.class);
		
		List<EquitySwapTestModel> dataList2 = (List<EquitySwapTestModel>) genericDao
				.getEquitySwapByNativeSelectQuery(20151028);
		logger.info("Got the data: {}", dataList2);
		
		dataList2 = (List<EquitySwapTestModel>) genericDao
				.getEquitySwapByHibernateORM(20151028);
		logger.info("Got the data: {}", dataList2);
		
		//Other DB call
		
		List<EquitySwapInterestRateModel> interestList = (List<EquitySwapInterestRateModel>) interestRateDao
				.getInterestRates();
		logger.info("Got the data: {}", interestList);
		
		interestList = (List<EquitySwapInterestRateModel>) interestRateDao
				.getInterestRateBasedOnRicAndDate("EUR1YFSR=", LocalDate.now());
		logger.info("Got the data: {}", interestList);
		
		((AbstractApplicationContext) context).close();

	}

}
