1 24 package org.riotfamily.components.dao.hibernate; 25 26 import java.util.List ; 27 28 import org.hibernate.Query; 29 import org.hibernate.SessionFactory; 30 import org.riotfamily.components.ComponentList; 31 import org.riotfamily.components.Location; 32 import org.riotfamily.components.VersionContainer; 33 import org.riotfamily.components.dao.AbstractComponentDao; 34 import org.riotfamily.riot.hibernate.support.HibernateHelper; 35 import org.springframework.util.Assert; 36 37 42 public class HibernateComponentDao extends AbstractComponentDao { 43 44 private HibernateHelper hibernate; 45 46 public HibernateComponentDao() { 47 } 48 49 public void setSessionFactory(SessionFactory sessionFactory) { 50 this.hibernate = new HibernateHelper(sessionFactory, "components"); 51 } 52 53 protected void initDao() { 54 Assert.notNull(hibernate, "A SessionFactory must be set."); 55 } 56 57 public ComponentList findComponentList(Location location) { 58 Query query = hibernate.createCacheableQuery("from " 59 + ComponentList.class.getName() + " list where " 60 + "list.location = :location and list.parent is null"); 61 62 hibernate.setParameter(query, "location", location); 63 return (ComponentList) hibernate.uniqueResult(query); 64 } 65 66 public ComponentList findComponentList(VersionContainer parent, String slot) { 67 Query query = hibernate.createCacheableQuery("from " 68 + ComponentList.class.getName() + " list where list.parent = " 69 +":parent and list.location.slot = :slot"); 70 71 hibernate.setParameter(query, "parent", parent); 72 hibernate.setParameter(query, "slot", slot); 73 return (ComponentList) query.uniqueResult(); 74 } 75 76 public List findComponentLists(String type, String path) { 77 Query query = hibernate.createCacheableQuery("from " 78 + ComponentList.class.getName() + " list where " 79 + "list.location.type = :type " 80 + "and list.location.path = :path " 81 + "and list.parent is null"); 82 83 hibernate.setParameter(query, "type", type); 84 hibernate.setParameter(query, "path", path); 85 return hibernate.list(query); 86 } 87 88 public List findDirtyComponentLists() { 89 Query query = hibernate.createCacheableQuery("from " 90 + ComponentList.class.getName() 91 + " list where list.dirty = true"); 92 93 return hibernate.list(query); 94 } 95 96 protected Object loadObject(Class clazz, Long id) { 97 return hibernate.load(clazz, id); 98 } 99 100 protected void saveObject(Object object) { 101 hibernate.save(object); 102 } 103 104 protected void updateObject(Object object) { 105 hibernate.update(object); 106 } 108 109 protected void deleteObject(Object object) { 110 hibernate.delete(object); 111 } 112 113 } 114 | Popular Tags |