net.roseindia.dao

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

Share on Google+Share on Google+

net.roseindia.dao

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

Advertisements

Ads
 

Discuss: net.roseindia.dao  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads