KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > javabb > dao > hibernate > PrivMsgReciviedHibernateDAO


1 /*
2  * Copyright 2004 JavaFree.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.javabb.dao.hibernate;
18
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21
22 import org.javabb.dao.entity.IPrivMsgReciviedDAO;
23 import org.javabb.vo.PrivMsg;
24 import org.javabb.vo.PrivMsgRecivied;
25 import org.javabb.vo.User;
26
27 /**
28  * @author Lucas Teixeira - <a HREF="mailto:lucas@javabb.org">lucas@javabb.org</a>
29  */

30
31 public class PrivMsgReciviedHibernateDAO extends HibernateDAO implements IPrivMsgReciviedDAO {
32
33     public List JavaDoc retrieveUserInbox(User u) throws Exception JavaDoc {
34         return find(PrivMsgRecivied.class, "o.userTo.idUser=?", new Object JavaDoc[] { u.getId() },
35                 "o.data DESC", ALL_PAGES, 0);
36     }
37
38     public int countMessagesByUser( User u ) {
39         return countRowsWhere(PrivMsgRecivied.class, "o.id", "o.userTo.idUser=? and o.read=0",
40             new Object JavaDoc[] { u.getId() });
41     }
42     
43     public PrivMsgRecivied load(Long JavaDoc id) throws Exception JavaDoc {
44         return (PrivMsgRecivied) getHibernateTemplate().load(PrivMsgRecivied.class, id);
45     }
46
47     public Long JavaDoc save(PrivMsgRecivied p) throws Exception JavaDoc {
48         return (Long JavaDoc)getHibernateTemplate().save(p);
49     }
50
51     public void delete(PrivMsgRecivied p) throws Exception JavaDoc {
52         getHibernateTemplate().update(p);
53     }
54     
55     public void delete(List JavaDoc l) throws Exception JavaDoc {
56         String JavaDoc sql = "delete from jbb_privmsg_inbox where id_privmsg in (";
57         for (Iterator JavaDoc i=l.iterator(); i.hasNext(); )
58             sql+= ((PrivMsg) i.next()).getId() + ",";
59         sql = sql.substring(0, sql.length()-1);
60         sql += ");";
61         this.executeSQL(sql);
62     }
63
64 }
65
Popular Tags