KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > j2biz > blogunity > jobs > RefererAndVisitedPagesRemover


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

26
27 package com.j2biz.blogunity.jobs;
28
29 import java.util.Calendar JavaDoc;
30 import java.util.Date JavaDoc;
31
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34
35 import org.quartz.Job;
36 import org.quartz.JobExecutionContext;
37 import org.quartz.JobExecutionException;
38
39 import com.j2biz.blogunity.dao.RefererDAO;
40 import com.j2biz.blogunity.dao.VisitedPageDAO;
41 import com.j2biz.blogunity.exception.BlogunityException;
42 import com.j2biz.blogunity.util.HibernateUtil;
43
44 public class RefererAndVisitedPagesRemover implements Job {
45     /**
46      * Logger for this class
47      */

48     private static final Log log = LogFactory.getLog(RefererAndVisitedPagesRemover.class);
49
50     /*
51      * (non-Javadoc)
52      *
53      * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
54      */

55     public void execute(JobExecutionContext ctx) throws JobExecutionException {
56
57         Date JavaDoc d = new Date JavaDoc();
58         Calendar JavaDoc calendar = Calendar.getInstance();
59         calendar.setTime(d);
60         calendar.set(Calendar.HOUR, 0);
61         calendar.set(Calendar.MINUTE, 0);
62         calendar.set(Calendar.SECOND, 0);
63
64         try {
65             if (log.isInfoEnabled()) {
66                 log
67                         .info("Executing job in RefererAndVisitedPagesRemover! Remove referers and pages older than "
68                                 + calendar.getTime());
69             }
70
71             RefererDAO refererDAO = new RefererDAO();
72             VisitedPageDAO visitedpageDAO = new VisitedPageDAO();
73
74             refererDAO.deleteRefererOlderThan(calendar.getTimeInMillis());
75             visitedpageDAO.deleteVisitedPageOlderThan(calendar.getTimeInMillis());
76
77             HibernateUtil.commitTransaction();
78
79         } catch (BlogunityException e) {
80
81             HibernateUtil.rollbackTransaction();
82             throw new JobExecutionException(e);
83
84         } finally {
85
86             HibernateUtil.closeSession();
87
88         }
89
90     }
91
92 }
Popular Tags