package net.roseindia.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import net.roseindia.model.Article;

@Repository("articleDao")
public class ArticleDaoImpl implements ArticleDao {

	@Autowired	
	private SessionFactory sessionFactory;

	// To get list of all articles
	@SuppressWarnings("unchecked")
	public List<Article> listArticles(){		
		return (List<Article>) sessionFactory.getCurrentSession().createCriteria(Article.class).list();
	 }
	
	public List<Article> getArticleByArticleId(Long articleId){
		return sessionFactory.getCurrentSession().createQuery("from Article where articleId=:articleId")
		      .setParameter("articleId", articleId)
		      .list();
	 }
}