1 24 package org.riotfamily.website.generic.model.hibernate; 25 26 import java.io.Serializable ; 27 28 import javax.servlet.http.HttpServletRequest ; 29 30 import org.hibernate.EntityMode; 31 import org.hibernate.Hibernate; 32 import org.hibernate.Query; 33 import org.riotfamily.cachius.TaggingContext; 34 35 39 public class HqlModelBuilder extends AbstractHqlModelBuilder { 40 41 protected Object getResult(Query query) { 42 query.setMaxResults(1); 43 return query.uniqueResult(); 44 } 45 46 protected void tagResult(Query query, Object item, 47 HttpServletRequest request) { 48 49 if (item != null) { 50 Class clazz = Hibernate.getClass(item); 51 Serializable id = getSessionFactory() 52 .getClassMetadata(clazz).getIdentifier( 53 item, EntityMode.POJO); 54 55 TaggingContext.tag(request, clazz.getName() + "#" + id); 56 } 57 else { 58 Class clazz = query.getReturnTypes()[0].getReturnedClass(); 59 TaggingContext.tag(request, clazz.getName()); 60 } 61 } 62 } 63 | Popular Tags |