HQLQueryBean.java :  » Web-Framework » RSF » uk » org » ponder » rsf » hibernate3 » Java Open Source

Java Open Source » Web Framework » RSF 
RSF » uk » org » ponder » rsf » hibernate3 » HQLQueryBean.java
/*
 * Created on 08-Jan-2006
 */
package uk.org.ponder.rsf.hibernate3;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.beans.factory.FactoryBean;

/** A request-scope query bean that will return a list of objects in response
 * to an HQL query string.
 * @author Antranig Basman (antranig@caret.cam.ac.uk)
 *
 */
public class HQLQueryBean implements FactoryBean {
  private Session session;
  private String hqlstring;

  public void setSession(Session session) {
    this.session = session;
  }
  
  public void setHQLString(String hqlstring) {
    this.hqlstring = hqlstring;
  }

  private List cached;
  
  public Object getObject() throws Exception {
    if (cached == null) {
      Query query = session.createQuery(hqlstring);
      cached = query.list();
    }
    return cached;
  }

  public Class getObjectType() {
    return List.class;
  }

  public boolean isSingleton() {
   return true;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.