1 /***
2 *
3 */
4 package hu.elte.tribus.services;
5
6 import java.util.List;
7
8 import hu.elte.tribus.interfaces.QaDao;
9 import hu.elte.tribus.model.QA;
10 import hu.elte.tribus.model.Topic;
11
12 import org.hibernate.Criteria;
13 import org.hibernate.criterion.Restrictions;
14 import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
15
16 /***
17 * @author kocka
18 *
19 */
20 public class HibernateQaDao extends HibernateDaoSupport implements QaDao {
21
22
23
24
25 public QA getQaById(Integer id) {
26 return (QA) getHibernateTemplate().load(QA.class, id);
27 }
28
29
30
31
32 public void saveQa(QA qa) {
33 getHibernateTemplate().save(qa);
34 }
35
36 public void deleteQa(QA qa) {
37 getHibernateTemplate().delete(qa);
38 }
39
40 @SuppressWarnings("unchecked")
41 public List<QA> getQaList() {
42 return getSession().createCriteria(QA.class).list();
43 }
44
45 public void deleteTopic(Topic topic) {
46 getHibernateTemplate().delete(topic);
47 }
48
49 public Topic getTopicById(Integer id) {
50 return (Topic)getHibernateTemplate().load(Topic.class, id);
51 }
52
53 @SuppressWarnings("unchecked")
54 public List<Topic> getTopicList() {
55 return getSession().createCriteria(Topic.class).list();
56 }
57
58 public void saveTopic(Topic topic) {
59 getHibernateTemplate().save(topic);
60 }
61
62 public Topic getTopicByName(String name) {
63 Criteria criteria = getSession().createCriteria(Topic.class);
64 criteria.add(Restrictions.eq("name", name));
65 return (Topic) criteria.uniqueResult();
66 }
67
68 }