/[projects]/android/PicturePosterService/src/dk/thoerup/pictureposterservice/PostingDAO.java
ViewVC logotype

Annotation of /android/PicturePosterService/src/dk/thoerup/pictureposterservice/PostingDAO.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1347 - (hide annotations) (download)
Wed Apr 20 17:30:33 2011 UTC (13 years, 1 month ago) by torben
File size: 1025 byte(s)
no need to open transactions in read-only sessions
1 torben 602 package dk.thoerup.pictureposterservice;
2    
3     import java.util.List;
4    
5     import org.hibernate.*;
6     import org.hibernate.criterion.*;
7    
8    
9    
10     public class PostingDAO {
11    
12     @SuppressWarnings("unchecked")
13     static public List<Posting> getAll() {
14 torben 1347 Session session = HibernateUtil.getSessionFactory().openSession();
15     //no need to open transaction for a readonly session
16 torben 602
17     Criteria c = session.createCriteria(Posting.class);
18     java.util.List<Posting> list = c.list();
19 torben 1347
20 torben 602 session.close();
21    
22     return list;
23     }
24    
25     static public void savePosting(Posting post) {
26     Session session = HibernateUtil.getSessionFactory().openSession();
27    
28     Transaction tx = session.beginTransaction();
29     session.persist(post);
30     tx.commit();
31    
32     session.close();
33     }
34    
35     static public Posting getPostingById(int id) {
36     Session session = HibernateUtil.getSessionFactory().getCurrentSession();
37    
38     Criteria c = session.createCriteria(Posting.class);
39     c.add( Restrictions.eq("id", id));
40     Posting post = (Posting) c.uniqueResult();
41    
42     return post;
43     }
44    
45     }

  ViewVC Help
Powered by ViewVC 1.1.20