01: /*
02: * Created on 08-Jan-2006
03: */
04: package uk.org.ponder.rsf.hibernate3;
05:
06: import java.util.List;
07:
08: import org.hibernate.Query;
09: import org.hibernate.Session;
10: import org.springframework.beans.factory.FactoryBean;
11:
12: /** A request-scope query bean that will return a list of objects in response
13: * to an HQL query string.
14: * @author Antranig Basman (antranig@caret.cam.ac.uk)
15: *
16: */
17: public class HQLQueryBean implements FactoryBean {
18: private Session session;
19: private String hqlstring;
20:
21: public void setSession(Session session) {
22: this .session = session;
23: }
24:
25: public void setHQLString(String hqlstring) {
26: this .hqlstring = hqlstring;
27: }
28:
29: private List cached;
30:
31: public Object getObject() throws Exception {
32: if (cached == null) {
33: Query query = session.createQuery(hqlstring);
34: cached = query.list();
35: }
36: return cached;
37: }
38:
39: public Class getObjectType() {
40: return List.class;
41: }
42:
43: public boolean isSingleton() {
44: return true;
45: }
46: }
|