/* * Created on Dec 6, 2004 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ /* The Broad Institute SOFTWARE COPYRIGHT NOTICE AGREEMENT This software and its documentation are copyright (2006) by the Broad Institute/Massachusetts Institute of Technology. All rights are reserved. This software is supplied without any warranty or guaranteed support whatsoever. Neither the Broad Institute nor MIT can be responsible for its use, misuse, or functionality. */ package calhoun.gebo.internal.db; //import net.sf.hibernate.Query; //import net.sf.hibernate.ScrollableResults; import org.hibernate.Query; import org.hibernate.ScrollableResults; import calhoun.gebo.db.SearchResults; import calhoun.gebo.util.Informer; import calhoun.util.DbSession; /** * @author reinhard * * TODO To change the template for this generated type comment go to Window - * Preferences - Java - Code Style - Code Templates */ public class HQLSearchResults implements SearchResults { private static Informer I = new Informer(HQLSearchResults.class); public HQLSearchResults(Class c, String hql) { super(); m_class = c; m_hql = hql; } public Class getResultClass() { return m_class; } public Object getResult(int position) throws Exception { checkInit(); m_results.setRowNumber(position); return m_results.get(0); } public int count() { try { checkInit(); m_results.last(); return m_results.getRowNumber() + 1; } catch (Exception e) { I.error("Error getting count: ", e); } return 0; } public void cleanUp() { // I think something actually needs to be done here. try { if ( m_results != null){ m_results.close(); } m_s.cancelQuery(); } catch (Throwable t){ I.error("Error closing results: ", t ); } } public void init() throws Exception { m_s = CalhounConnectionManager.getInstance().getDbSession(); m_query = m_s.createQuery(m_hql); m_results = m_query.scroll(); } private void checkInit() throws Exception { if (m_results == null) { init(); } } private Query m_query; private Class m_class; private int m_lastPosition; private String m_hql; private DbSession m_s; private ScrollableResults m_results; }