1 6 7 package org.roller.business.hibernate; 8 9 import java.util.HashMap ; 10 import java.util.Iterator ; 11 import java.util.List ; 12 import java.util.Map ; 13 import net.sf.hibernate.Criteria; 14 import net.sf.hibernate.HibernateException; 15 import net.sf.hibernate.Session; 16 import net.sf.hibernate.expression.Expression; 17 import org.apache.commons.logging.Log; 18 import org.apache.commons.logging.LogFactory; 19 import org.roller.RollerException; 20 import org.roller.business.PersistenceStrategy; 21 import org.roller.business.PropertiesManagerImpl; 22 import org.roller.pojos.RollerPropertyData; 23 24 29 public class HibernatePropertiesManagerImpl extends PropertiesManagerImpl { 30 31 static final long serialVersionUID = -4326713177137796936L; 32 33 private static Log mLogger = 34 LogFactory.getFactory().getInstance(HibernatePropertiesManagerImpl.class); 35 36 37 38 public HibernatePropertiesManagerImpl(PersistenceStrategy strategy) { 39 super(strategy); 40 mLogger.debug("Instantiating Hibernate Properties Manager"); 41 } 42 43 44 45 public RollerPropertyData getProperty(String name) throws RollerException { 46 try 47 { 48 Session session = ((HibernateStrategy) mStrategy).getSession(); 49 Criteria criteria = session.createCriteria(RollerPropertyData.class); 50 criteria.add(Expression.eq("name", name)); 51 criteria.setMaxResults(1); 52 List list = criteria.list(); 53 return (list.size()!= 0) ? (RollerPropertyData)list.get(0) : null; 54 } 55 catch (HibernateException e) 56 { 57 throw new RollerException(e); 58 } 59 } 60 61 62 63 public Map getProperties() throws RollerException { 64 65 HashMap props = new HashMap (); 66 67 try 68 { 69 Session session = ((HibernateStrategy) mStrategy).getSession(); 70 Criteria criteria = session.createCriteria(RollerPropertyData.class); 71 List list = criteria.list(); 72 73 RollerPropertyData prop = null; 78 Iterator it = list.iterator(); 79 while(it.hasNext()) { 80 prop = (RollerPropertyData) it.next(); 81 props.put(prop.getName(), prop); 82 } 83 } 84 catch (HibernateException e) 85 { 86 throw new RollerException(e); 87 } 88 89 return props; 90 } 91 92 } 93 | Popular Tags |