1 25 26 package com.j2biz.blogunity.dao; 27 28 import java.io.Serializable ; 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 49 public class LinkDAO extends AbstractDAO { 50 53 private static final Log log = LogFactory.getLog(LinkDAO.class); 54 55 58 public LinkDAO() { 59 super(); 60 } 61 62 public Link getLinkByID(long id) throws BlogunityException { 63 64 return getLinkByID(new Long (id)); 65 } 66 67 public Link getLinkByID(Long 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 createLink(Link link) throws BlogunityException { 83 84 Session session = HibernateUtil.getSession(); 85 try { 86 Serializable 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 |