KickJava   Java API By Example, From Geeks To Geeks.

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


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 net.sf.hibernate.expression.Order;
16 import org.roller.RollerException;
17 import org.roller.business.PersistenceStrategy;
18 import org.roller.business.PingTargetManagerImpl;
19 import org.roller.pojos.PingTargetData;
20 import org.roller.pojos.WebsiteData;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Collection JavaDoc;
25
26 public class HibernatePingTargetManagerImpl extends PingTargetManagerImpl
27 {
28     static final long serialVersionUID = 121008492583382718L;
29
30     public HibernatePingTargetManagerImpl(PersistenceStrategy persistenceStrategy)
31     {
32         super(persistenceStrategy);
33     }
34
35     /**
36      * @see org.roller.model.PingTargetManager#getCommonPingTargets()
37      */

38     public List JavaDoc getCommonPingTargets() throws RollerException
39     {
40         try
41         {
42             Session session = ((HibernateStrategy) persistenceStrategy).getSession();
43             Criteria criteria = session.createCriteria(PingTargetData.class);
44             criteria.add(Expression.isNull("website"));
45             criteria.addOrder(Order.asc("name"));
46             return criteria.list();
47         }
48         catch (HibernateException e)
49         {
50             throw new RollerException(e);
51         }
52
53     }
54
55     /**
56      * @see org.roller.model.PingTargetManager#getCustomPingTargets(org.roller.pojos.WebsiteData)
57      */

58     public List JavaDoc getCustomPingTargets(WebsiteData website) throws RollerException
59     {
60         try
61         {
62             Session session = ((HibernateStrategy) persistenceStrategy).getSession();
63             Criteria criteria = session.createCriteria(PingTargetData.class);
64             criteria.add(Expression.eq("website", website));
65             criteria.addOrder(Order.asc("name"));
66             return criteria.list();
67         }
68         catch (HibernateException e)
69         {
70             throw new RollerException(e);
71         }
72     }
73
74     /**
75      * @see org.roller.model.PingTargetManager#removeCustomPingTargets(org.roller.pojos.WebsiteData)
76      */

77     public void removeCustomPingTargets(WebsiteData website) throws RollerException
78     {
79         List JavaDoc customTargets = getCustomPingTargets(website);
80         removeTargets(customTargets);
81     }
82
83     /**
84      * @see org.roller.model.PingTargetManager#removeAllCustomPingTargets()
85      */

86     public void removeAllCustomPingTargets() throws RollerException
87     {
88         try
89         {
90             Session session = ((HibernateStrategy) persistenceStrategy).getSession();
91             Criteria criteria = session.createCriteria(PingTargetData.class);
92             criteria.add(Expression.isNotNull("website"));
93             List JavaDoc allCustomTargets = criteria.list();
94             removeTargets(allCustomTargets);
95         }
96         catch (HibernateException e)
97         {
98             throw new RollerException(e);
99         }
100     }
101
102     // Private helper to remove a collection of targets.
103
private void removeTargets(Collection JavaDoc customTargets)
104         throws RollerException
105     {
106         for (Iterator JavaDoc i = customTargets.iterator(); i.hasNext();)
107         {
108             PingTargetData pt = (PingTargetData) i.next();
109             pt.remove();
110         }
111     }
112
113 }
114
Popular Tags