1 25 26 package com.j2biz.blogunity.dao; 27 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 31 import net.sf.hibernate.HibernateException; 32 import net.sf.hibernate.Query; 33 import net.sf.hibernate.Session; 34 35 import com.j2biz.blogunity.exception.BlogunityException; 36 import com.j2biz.blogunity.i18n.I18N; 37 import com.j2biz.blogunity.i18n.I18NStatusFactory; 38 import com.j2biz.blogunity.pojo.Blog; 39 import com.j2biz.blogunity.util.HibernateUtil; 40 41 public class StatisticsDAO extends AbstractDAO { 42 43 private static final Log log = LogFactory.getLog(StatisticsDAO.class); 44 45 48 public StatisticsDAO() { 49 super(); 50 } 51 52 public final Object getNumberOfRegisteredUsers() throws BlogunityException { 53 Session session = HibernateUtil.getSession(); 54 try { 55 Query q = session.createQuery("select count(*) from User u"); 56 q.setCacheable(true); 57 return q.uniqueResult(); 58 } catch (HibernateException e) { 59 log.error("getNumberOfRegisteredUsers()", e); 60 throw new BlogunityException(I18NStatusFactory.create( 61 I18N.ERRORS.STATISTIC_NUMBER_OF_REGISTERED_USERS, e)); 62 63 } 64 } 65 66 public final Object getNumberOfIndividualBlogs() throws BlogunityException { 67 Session session = HibernateUtil.getSession(); 68 try { 69 Query q = session.createQuery("select count(*) from Blog b where b.type = :type"); 70 q.setParameter("type", new Integer (Blog.INDIVIDUAL_BLOG)); 71 q.setCacheable(true); 72 return q.uniqueResult(); 73 } catch (HibernateException e) { 74 75 log.error("getNumberOfIndividualBlogs()", e); 76 throw new BlogunityException(I18NStatusFactory.create( 77 I18N.ERRORS.STATISTIC_NUMBER_OF_INDIVIDUAL_BLOGS, e)); 78 79 } 80 } 81 82 public final Object getNumberOfCommunityBlogs() throws BlogunityException { 83 Session session = HibernateUtil.getSession(); 84 try { 85 Query q = session.createQuery("select count(*) from Blog b where b.type = :type"); 86 q.setParameter("type", new Integer (Blog.COMMUNITY_BLOG)); 87 q.setCacheable(true); 88 return q.uniqueResult(); 89 } catch (HibernateException e) { 90 91 log.error("getNumberOfCommunityBlogs()", e); 92 throw new BlogunityException(I18NStatusFactory.create( 93 I18N.ERRORS.STATISTIC_NUMBER_OF_COMMUNITY_BLOGS, e)); 94 95 } 96 } 97 98 public final Object getNumberOfPosts() throws BlogunityException { 99 Session session = HibernateUtil.getSession(); 100 try { 101 Query q = session.createQuery("select count(*) from Entry e"); 102 q.setCacheable(true); 103 return q.uniqueResult(); 104 } catch (HibernateException e) { 105 106 log.error("getNumberOfPosts()", e); 107 throw new BlogunityException(I18NStatusFactory.create( 108 I18N.ERRORS.STATISTIC_NUMBER_OF_POSTS, e)); 109 110 } 111 } 112 113 public final Object getNumberOfComments() throws BlogunityException { 114 Session session = HibernateUtil.getSession(); 115 try { 116 Query q = session.createQuery("select count(*) from Comment c"); 117 q.setCacheable(true); 118 return q.uniqueResult(); 119 } catch (HibernateException e) { 120 121 log.error("getNumberOfComments()", e); 122 throw new BlogunityException(I18NStatusFactory.create( 123 I18N.ERRORS.STATISTIC_NUMBER_OF_COMMENTS, e)); 124 125 } 126 } 127 } | Popular Tags |