1 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 ; 24 import java.util.Collections ; 25 import java.util.Iterator ; 26 import java.util.List ; 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 criteria.add(Expression.eq("pingTarget", pingTarget)); 46 criteria.add(Expression.eq("website", website)); 47 List matches = criteria.list(); 48 for (Iterator 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 getAutoPingsByWebsite(WebsiteData website) throws RollerException 60 { 61 try 62 { 63 Session session = ((HibernateStrategy) persistenceStrategy).getSession(); 64 Criteria criteria = session.createCriteria(AutoPingData.class); 65 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 getAutoPingsByTarget(PingTargetData pingTarget) throws RollerException 77 { 78 try 79 { 80 Session session = ((HibernateStrategy) persistenceStrategy).getSession(); 81 Criteria criteria = session.createCriteria(AutoPingData.class); 82 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 allAutoPings = criteria.list(); 100 removeAutoPings(allAutoPings); 101 } 102 catch (HibernateException e) 103 { 104 throw new RollerException(e); 105 } 106 } 107 108 public List getCategoryRestrictions(AutoPingData autoPing) throws RollerException 109 { 110 return Collections.EMPTY_LIST; 111 } 112 113 public void setCategoryRestrictions(AutoPingData autoPing, Collection newCategories) 114 { 115 return; 117 } 118 119 public List getApplicableAutoPings(WeblogEntryData changedWeblogEntry) throws RollerException 120 { 121 try 122 { 123 Session session = ((HibernateStrategy) persistenceStrategy).getSession(); 124 Criteria criteria = session.createCriteria(AutoPingData.class); 125 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 |