KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: LinkDAO.java,v 1.4 2005/01/17 21:36:11 michelson Exp $
3  *
4  * Copyright (c) 2004 j2biz Group, http://www.j2biz.com
5  * Koeln / Duesseldorf , Germany
6  *
7  * @author Max Kalina
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
26 package com.j2biz.blogunity.dao;
27
28 import java.io.Serializable JavaDoc;
29
30 import net.sf.hibernate.HibernateException;
31 import net.sf.hibernate.Session;
32
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35
36 import com.j2biz.blogunity.exception.BlogunityException;
37 import com.j2biz.blogunity.i18n.I18N;
38 import com.j2biz.blogunity.i18n.I18NStatusFactory;
39 import com.j2biz.blogunity.pojo.Link;
40 import com.j2biz.blogunity.util.HibernateUtil;
41
42 /**
43  * @author michelson
44  * @version $$
45  * @since 0.1
46  *
47  *
48  */

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

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

58     public LinkDAO() {
59         super();
60     }
61
62     public Link getLinkByID(long id) throws BlogunityException {
63
64         return getLinkByID(new Long JavaDoc(id));
65     }
66
67     public Link getLinkByID(Long JavaDoc id) throws BlogunityException {
68
69         Session session = HibernateUtil.getSession();
70         Link blogCategory = null;
71         try {
72             blogCategory = (Link) session.load(Link.class, id);
73         } catch (HibernateException ex) {
74             log.error("getLinkByID(Long)", ex);
75             throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.NOT_FOUND_BY_ID,
76                     "Link", ex));
77         }
78
79         return blogCategory;
80     }
81
82     public Serializable JavaDoc createLink(Link link) throws BlogunityException {
83
84         Session session = HibernateUtil.getSession();
85         try {
86             Serializable JavaDoc returnSerializable = session.save(link);
87             if (log.isDebugEnabled()) {
88                 log.debug("createLink(Link) - end");
89             }
90             return returnSerializable;
91         } catch (HibernateException e) {
92             log.error("createLink(Link)", e);
93             throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.CREATE, "Link", e));
94         }
95     }
96
97     public void deleteLink(Link link) throws BlogunityException {
98
99         Session session = HibernateUtil.getSession();
100         try {
101             session.delete(link);
102         } catch (HibernateException e) {
103             log.error("deleteLink(Link)", e);
104             throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.DELETE, "Link", e));
105         }
106
107     }
108
109     public void updateLink(Link link) throws BlogunityException {
110
111         Session session = HibernateUtil.getSession();
112         try {
113             session.update(link);
114         } catch (HibernateException e) {
115             log.error("updateLink(Link)", e);
116             throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.UPDATE, "Link", e));
117         }
118
119     }
120
121 }
Popular Tags