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 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 ; 23 import java.util.List ; 24 import java.util.Collection ; 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 38 public List 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 58 public List 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 77 public void removeCustomPingTargets(WebsiteData website) throws RollerException 78 { 79 List customTargets = getCustomPingTargets(website); 80 removeTargets(customTargets); 81 } 82 83 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 allCustomTargets = criteria.list(); 94 removeTargets(allCustomTargets); 95 } 96 catch (HibernateException e) 97 { 98 throw new RollerException(e); 99 } 100 } 101 102 private void removeTargets(Collection customTargets) 104 throws RollerException 105 { 106 for (Iterator i = customTargets.iterator(); i.hasNext();) 107 { 108 PingTargetData pt = (PingTargetData) i.next(); 109 pt.remove(); 110 } 111 } 112 113 } 114 | Popular Tags |