KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > j2biz > blogunity > dao > TrackbackDAO


1 /*
2  * $Id: TrackbackDAO.java,v 1.6 2005/01/17 21:36:10 michelson Exp $
3  *
4  * Copyright (c) 2004 j2biz Group, http://www.j2biz.com
5  * Koeln / Duesseldorf , Germany
6  *
7  * @author Antonio Agudo
8  *
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  *
24  */

25 package com.j2biz.blogunity.dao;
26
27 import java.io.Serializable JavaDoc;
28 import java.util.List JavaDoc;
29
30 import net.sf.hibernate.HibernateException;
31 import net.sf.hibernate.Query;
32 import net.sf.hibernate.Session;
33
34 import org.apache.commons.logging.Log;
35 import org.apache.commons.logging.LogFactory;
36
37 import com.j2biz.blogunity.exception.BlogunityException;
38 import com.j2biz.blogunity.i18n.I18N;
39 import com.j2biz.blogunity.i18n.I18NStatusFactory;
40 import com.j2biz.blogunity.pojo.Trackback;
41 import com.j2biz.blogunity.util.HibernateUtil;
42
43 /**
44  * @author tag
45  *
46  * TODO To change the template for this generated type comment go to Window -
47  * Preferences - Java - Code Style - Code Templates
48  */

49 public class TrackbackDAO extends AbstractDAO {
50     /**
51      * Logger for this class
52      */

53     private static final Log log = LogFactory.getLog(EntryDAO.class);
54
55     /**
56      *
57      */

58     public TrackbackDAO() {
59         super();
60     }
61
62     public Trackback getTrackbackByID(Long JavaDoc id) throws BlogunityException {
63
64         Session session = HibernateUtil.getSession();
65         try {
66             return (Trackback) session.load(Trackback.class, id);
67         } catch (HibernateException ex) {
68
69             log.error("getTrackbackByID(Long)", ex);
70             throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.NOT_FOUND_BY_ID,
71                     "Trackback", ex));
72         }
73     }
74
75     public List JavaDoc getTrackbacksForEntry(Long JavaDoc entryId) throws BlogunityException {
76         Session session = HibernateUtil.getSession();
77         try {
78             // TODO: I left this static for now, i'll make this statement
79
// cacheable later
80
Query q = session
81                     .createQuery("from Trackback trackback where trackback.referencedEntryId = "
82                             + entryId + " order by trackback.date");
83             return q.list();
84         } catch (HibernateException ex) {
85             log.error("getTrackbacksForEntry(Long)", ex);
86             throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.NOT_FOUND_BY_ID,
87                     "Trackback", ex));
88         }
89     }
90
91     public List JavaDoc getTrackbacksForEntryAndDirection(Long JavaDoc entryId, String JavaDoc direction)
92             throws BlogunityException {
93         Session session = HibernateUtil.getSession();
94         try {
95             // TODO: I left this static for now, i'll make this statement
96
// cacheable later
97
Query q = session
98                     .createQuery("from Trackback trackback where trackback.referencedEntryId = "
99                             + entryId + " and direction='" + direction
100                             + "' order by trackback.date");
101             return q.list();
102         } catch (HibernateException ex) {
103             log.error("getTrackbacksForEntryAndDirection(Long)", ex);
104             throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.NOT_FOUND_BY_ID,
105                     "Trackback", ex));
106         }
107     }
108
109     public Serializable JavaDoc createTrackback(Trackback trackback) throws BlogunityException {
110
111         Session session = HibernateUtil.getSession();
112         try {
113             Serializable JavaDoc returnSerializable = session.save(trackback);
114             return returnSerializable;
115         } catch (HibernateException e) {
116             log.error("createTrackback(Trackback)", e);
117             throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.CREATE, "Trackback",
118                     e));
119         }
120     }
121 }
Popular Tags