package com.javahonk.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.javahonk.model.EquitySwapTestModel;


@Repository
@Transactional
public class GenericDaoHandler<T> implements GenericDao<T>{
	
	@Autowired
	private SessionFactory sessionFactory;
	
	@Value("${query_getEquitySwapTestData}")
	private String query_getEquitySwapTestData;

	@SuppressWarnings("unchecked")
	@Override
	public List<T> getEquitySwapByNativeSelectQuery(int eventDate) {
		
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createSQLQuery("SELECT * FROM OTC.dbo.EquitySwapTest where eventDate = :eventDate").addEntity(EquitySwapTestModel.class);
		query.setParameter("eventDate", eventDate);
		List<T> dividendPayDate = query.list();
		return dividendPayDate;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<T> getEquitySwapByHibernateORM(int eventDate) {
		
		Session session = sessionFactory.getCurrentSession();
		Query query = session.getNamedQuery(query_getEquitySwapTestData);
		query.setParameter("eventDate", eventDate);		
		List<T> dividendPayDate = query.list();
		return dividendPayDate;
	}

	

}
