/*
 * Created on 27-09-2003
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package net.sf.hibern8ide;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import net.sf.hibernate.type.Type;


public class HQLQueryPage extends AbstractQueryPage {

	private Query query;
	public List getList() {
		if (list == null) {
			try {
				list = query.list();
			} catch (HibernateException e) {
				list = Collections.EMPTY_LIST;
				exceptions.add(e);
                release();
			}
		}
		return list;
	}

	/**
	 * @param session
	 * @param string
	 */
	public HQLQueryPage(Session session, String string) {
        super(session);
		try {			             
			query = this.session.createQuery(string);
		} catch (HibernateException e) {
			exceptions.add(e);
            release();
		}
	}

    /**
     * @return
     */
    public String getQueryString() {
    	return query.getQueryString();    
    }

    public List getPathNames() {
    	List l = Collections.EMPTY_LIST;
    
    	try {
    		Type[] t = query.getReturnTypes();
    		l = new ArrayList(t.length);
    
    		for (int i = 0; i < t.length; i++) {
    			Type type = t[i];
    			l.add(type.getName());
    		}
    	} catch (HibernateException he) {
    		exceptions.add(he);
            release();
    	}
    
    	return l;
    }
}