KickJava   Java API By Example, From Geeks To Geeks.

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


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

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     /**
46      *
47      */

48     public StatisticsDAO() {
49         super();
50     }
51
52     public final Object JavaDoc 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 JavaDoc 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 JavaDoc(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 JavaDoc 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 JavaDoc(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 JavaDoc 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 JavaDoc 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