KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > business > hibernate > HibernateAutoPingManagerImpl


1 /*
2  * Copyright (c) 2005
3  * Anil R. Gangolli. All rights reserved.
4  *
5  * Distributed with the Roller Weblogger Project under the terms of the Roller Software
6  * License
7  */

8
9 package org.roller.business.hibernate;
10
11 import net.sf.hibernate.Criteria;
12 import net.sf.hibernate.HibernateException;
13 import net.sf.hibernate.Session;
14 import net.sf.hibernate.expression.Expression;
15 import org.roller.RollerException;
16 import org.roller.business.PersistenceStrategy;
17 import org.roller.business.AutoPingManagerImpl;
18 import org.roller.pojos.AutoPingData;
19 import org.roller.pojos.PingTargetData;
20 import org.roller.pojos.WeblogEntryData;
21 import org.roller.pojos.WebsiteData;
22
23 import java.util.Collection JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27
28 public class HibernateAutoPingManagerImpl extends AutoPingManagerImpl
29 {
30     static final long serialVersionUID = 5420615676256979199L;
31
32     public HibernateAutoPingManagerImpl(PersistenceStrategy persistenceStrategy)
33     {
34         super(persistenceStrategy);
35     }
36
37     public void removeAutoPing(PingTargetData pingTarget, WebsiteData website) throws RollerException
38     {
39         try
40         {
41             Session session = ((HibernateStrategy) persistenceStrategy).getSession();
42             Criteria criteria = session.createCriteria(AutoPingData.class);
43             // Currently category restrictions are not yet implemented, so we return all auto ping configs for the
44
// website.
45
criteria.add(Expression.eq("pingTarget", pingTarget));
46             criteria.add(Expression.eq("website", website));
47             List JavaDoc matches = criteria.list();
48             // This should have at most one element, but we remove them all regardless.
49
for (Iterator JavaDoc i = matches.iterator(); i.hasNext(); ) {
50                 ((AutoPingData) i.next()).remove();
51             }
52         }
53         catch (HibernateException e)
54         {
55             throw new RollerException(e);
56         }
57     }
58
59     public List JavaDoc getAutoPingsByWebsite(WebsiteData website) throws RollerException
60     {
61         try
62         {
63             Session session = ((HibernateStrategy) persistenceStrategy).getSession();
64             Criteria criteria = session.createCriteria(AutoPingData.class);
65             // Currently category restrictions are not yet implemented, so we return all auto ping configs for the
66
// website.
67
criteria.add(Expression.eq("website", website));
68             return criteria.list();
69         }
70         catch (HibernateException e)
71         {
72             throw new RollerException(e);
73         }
74     }
75
76     public List JavaDoc getAutoPingsByTarget(PingTargetData pingTarget) throws RollerException
77     {
78         try
79         {
80             Session session = ((HibernateStrategy) persistenceStrategy).getSession();
81             Criteria criteria = session.createCriteria(AutoPingData.class);
82             // Currently category restrictions are not yet implemented, so we return all auto ping configs for the
83
// website.
84
criteria.add(Expression.eq("pingTarget", pingTarget));
85             return criteria.list();
86         }
87         catch (HibernateException e)
88         {
89             throw new RollerException(e);
90         }
91     }
92
93     public void removeAllAutoPings() throws RollerException
94     {
95         try
96         {
97             Session session = ((HibernateStrategy) persistenceStrategy).getSession();
98             Criteria criteria = session.createCriteria(AutoPingData.class);
99             List JavaDoc allAutoPings = criteria.list();
100             removeAutoPings(allAutoPings);
101         }
102         catch (HibernateException e)
103         {
104             throw new RollerException(e);
105         }
106     }
107
108     public List JavaDoc getCategoryRestrictions(AutoPingData autoPing) throws RollerException
109     {
110         return Collections.EMPTY_LIST;
111     }
112
113     public void setCategoryRestrictions(AutoPingData autoPing, Collection JavaDoc newCategories)
114     {
115         // NOT YET IMPLEMENTED
116
return;
117     }
118
119     public List JavaDoc getApplicableAutoPings(WeblogEntryData changedWeblogEntry) throws RollerException
120     {
121         try
122         {
123             Session session = ((HibernateStrategy) persistenceStrategy).getSession();
124             Criteria criteria = session.createCriteria(AutoPingData.class);
125             // Currently category restrictions are not yet implemented, so we return all auto ping configs for the
126
// website.
127
criteria.add(Expression.eq("website", changedWeblogEntry.getWebsite()));
128             return criteria.list();
129         }
130         catch (HibernateException e)
131         {
132             throw new RollerException(e);
133         }
134     }
135 }
136
Popular Tags