KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > website > generic > model > hibernate > HqlModelBuilder


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2007
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.website.generic.model.hibernate;
25
26 import java.io.Serializable JavaDoc;
27
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29
30 import org.hibernate.EntityMode;
31 import org.hibernate.Hibernate;
32 import org.hibernate.Query;
33 import org.riotfamily.cachius.TaggingContext;
34
35 /**
36  * @author Felix Gnass [fgnass at neteye dot de]
37  * @since 6.5
38  */

39 public class HqlModelBuilder extends AbstractHqlModelBuilder {
40
41     protected Object JavaDoc getResult(Query query) {
42         query.setMaxResults(1);
43         return query.uniqueResult();
44     }
45     
46     protected void tagResult(Query query, Object JavaDoc item,
47             HttpServletRequest JavaDoc request) {
48         
49         if (item != null) {
50             Class JavaDoc clazz = Hibernate.getClass(item);
51             Serializable JavaDoc id = getSessionFactory()
52                     .getClassMetadata(clazz).getIdentifier(
53                     item, EntityMode.POJO);
54
55             TaggingContext.tag(request, clazz.getName() + "#" + id);
56         }
57         else {
58             Class JavaDoc clazz = query.getReturnTypes()[0].getReturnedClass();
59             TaggingContext.tag(request, clazz.getName());
60         }
61     }
62 }
63
Popular Tags