1 18 19 package org.apache.roller.business.hibernate; 20 21 import org.hibernate.Criteria; 22 import org.hibernate.HibernateException; 23 import org.hibernate.Session; 24 import org.hibernate.criterion.Expression; 25 import org.apache.roller.RollerException; 26 import org.apache.roller.pojos.AutoPingData; 27 import org.apache.roller.pojos.PingTargetData; 28 import org.apache.roller.pojos.WeblogEntryData; 29 import org.apache.roller.pojos.WebsiteData; 30 import java.util.Collection ; 31 import java.util.Collections ; 32 import java.util.Iterator ; 33 import java.util.List ; 34 import org.apache.commons.logging.Log; 35 import org.apache.commons.logging.LogFactory; 36 import org.apache.roller.config.PingConfig; 37 import org.apache.roller.model.AutoPingManager; 38 import org.apache.roller.model.PingQueueManager; 39 import org.apache.roller.model.RollerFactory; 40 41 42 47 public class HibernateAutoPingManagerImpl implements AutoPingManager { 48 49 static final long serialVersionUID = 5420615676256979199L; 50 51 private static Log log = LogFactory.getLog(HibernateAutoPingManagerImpl.class); 52 53 private HibernatePersistenceStrategy strategy = null; 54 55 56 public HibernateAutoPingManagerImpl(HibernatePersistenceStrategy strat) { 57 this.strategy = strat; 58 } 59 60 61 public AutoPingData getAutoPing(String id) throws RollerException { 62 return (AutoPingData) strategy.load(id, AutoPingData.class); 63 } 64 65 66 public void saveAutoPing(AutoPingData autoPing) throws RollerException { 67 strategy.store(autoPing); 68 } 69 70 71 public void removeAutoPing(AutoPingData autoPing) throws RollerException { 72 strategy.remove(autoPing); 74 } 75 76 77 public void removeAutoPing(PingTargetData pingTarget, WebsiteData website) throws RollerException { 78 try { 79 Session session = strategy.getSession(); 80 Criteria criteria = session.createCriteria(AutoPingData.class); 81 82 criteria.add(Expression.eq("pingTarget", pingTarget)); 85 criteria.add(Expression.eq("website", website)); 86 List matches = criteria.list(); 87 88 this.removeAutoPings(matches); 90 } catch (HibernateException e) { 91 throw new RollerException(e); 92 } 93 } 94 95 96 public void removeAutoPings(Collection autopings) throws RollerException { 97 98 Iterator pings = autopings.iterator(); 100 while (pings.hasNext()) { 101 this.strategy.remove((AutoPingData) pings.next()); 102 } 103 } 104 105 106 public void removeAllAutoPings() throws RollerException { 107 try { 108 Session session = ((HibernatePersistenceStrategy) strategy).getSession(); 109 Criteria criteria = session.createCriteria(AutoPingData.class); 110 List allAutoPings = criteria.list(); 111 this.removeAutoPings(allAutoPings); 112 } catch (HibernateException e) { 113 throw new RollerException(e); 114 } 115 } 116 117 118 public void queueApplicableAutoPings(WeblogEntryData changedWeblogEntry) throws RollerException { 119 if (PingConfig.getSuspendPingProcessing()) { 120 if (log.isDebugEnabled()) log.debug("Ping processing is suspended. No auto pings will be queued."); 121 return; 122 } 123 124 PingQueueManager pingQueueMgr = RollerFactory.getRoller().getPingQueueManager(); 126 List applicableAutopings = getApplicableAutoPings(changedWeblogEntry); 127 for (Iterator i = applicableAutopings.iterator(); i.hasNext(); ) { 128 AutoPingData autoPing = (AutoPingData) i.next(); 129 pingQueueMgr.addQueueEntry(autoPing); 130 } 131 } 132 133 134 public List getAutoPingsByWebsite(WebsiteData website) throws RollerException { 135 try { 136 Session session = ((HibernatePersistenceStrategy) strategy).getSession(); 137 Criteria criteria = session.createCriteria(AutoPingData.class); 138 criteria.add(Expression.eq("website", website)); 141 return criteria.list(); 142 } catch (HibernateException e) { 143 throw new RollerException(e); 144 } 145 } 146 147 148 public List getAutoPingsByTarget(PingTargetData pingTarget) throws RollerException { 149 try { 150 Session session = ((HibernatePersistenceStrategy) strategy).getSession(); 151 Criteria criteria = session.createCriteria(AutoPingData.class); 152 criteria.add(Expression.eq("pingTarget", pingTarget)); 155 return criteria.list(); 156 } catch (HibernateException e) { 157 throw new RollerException(e); 158 } 159 } 160 161 162 public List getApplicableAutoPings(WeblogEntryData changedWeblogEntry) throws RollerException { 163 try { 164 Session session = ((HibernatePersistenceStrategy) strategy).getSession(); 165 Criteria criteria = session.createCriteria(AutoPingData.class); 166 criteria.add(Expression.eq("website", changedWeblogEntry.getWebsite())); 169 return criteria.list(); 170 } catch (HibernateException e) { 171 throw new RollerException(e); 172 } 173 } 174 175 176 public List getCategoryRestrictions(AutoPingData autoPing) throws RollerException { 177 return Collections.EMPTY_LIST; 178 } 179 180 181 public void setCategoryRestrictions(AutoPingData autoPing, Collection newCategories) { 182 return; 184 } 185 186 187 public void release() {} 188 189 } 190 | Popular Tags |