Share on Google+Share on Google+

net.roseindia.dao

Advertisement
This section contains the DAO interface and its implementation class.

net.roseindia.dao

This section contains the DAO interface and its implementation class.

ArticleDao.java

package net.roseindia.dao;

import java.util.List;

import net.roseindia.model.Article;

public interface ArticleDao {
	// To Save the article detail
	public void saveArticle(Article Article);
	
	// To get list of all articles
	public List<Article> listArticles();
}

ArticleDaoImpl.java

package net.roseindia.dao;

import java.util.Date;
import java.util.List;

import net.roseindia.model.Article;

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

@Repository("articleDao")
public class ArticleDaoImpl implements ArticleDao {
	
	@Autowired
	private SessionFactory sessionFactory;
	
	// To Save the article detail
	public void saveArticle(Article article) {
	article.setAddedDate(new Date());
	sessionFactory.getCurrentSession().saveOrUpdate(article);
	}
	
	// To get list of all articles
	@SuppressWarnings("unchecked")
	public List<Article> listArticles() {
	return (List<Article>) sessionFactory.getCurrentSession()
	.createCriteria(Article.class).list();
	}
}

Advertisements

Posted on: March 28, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Comments:0