package org.intermine.web;

/*
 * Copyright (C) 2002-2004 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import org.intermine.objectstore.ObjectStore;
import org.intermine.objectstore.ObjectStoreFactory;
import org.intermine.objectstore.query.Query;
import org.intermine.objectstore.query.QueryCloner;
import org.intermine.objectstore.query.Results;

/**
 * Implementation of <strong>Action</strong> that runs a Query. The query to run
 * is passed in as a session parameter and the results are put on to the session as well.
 *
 * @author Andrew Varley
 */

public class RunQueryAction extends Action
{

    /**
     * Process the specified HTTP request, and create the corresponding HTTP
     * response (or forward to another web component that will create it).
     * Return an <code>ActionForward</code> instance describing where and how
     * control should be forwarded, or <code>null</code> if the response has
     * already been completed.
     *
     * @param mapping The ActionMapping used to select this instance
     * @param form The optional ActionForm bean for this request (if any)
     * @param request The HTTP request we are processing
     * @param response The HTTP response we are creating
     * @return an ActionForward object defining where control goes next
     *
     * @exception Exception if the application business logic throws
     *  an exception
     */
    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
        throws Exception {
        HttpSession session = request.getSession();

        Query q = (Query) session.getAttribute(Constants.QUERY);

        if (q == null) {
            return mapping.findForward("buildquery");
        } else {
            ObjectStore os = ObjectStoreFactory.getObjectStore();

            Results results = os.execute(QueryCloner.cloneQuery(q));
            session.setAttribute("results", results);

            return mapping.findForward("results");
        }
    }
}

@@ -319,16 +319,53 @@
  *%0A */%0A%0A
+import javax.servlet.ServletContext;%0A
 import j
@@ -488,16 +488,17 @@
 sponse;%0A
+%0A
 import o
@@ -718,61 +718,8 @@
 re;%0A
-import org.intermine.objectstore.ObjectStoreFactory;%0A
 impo
@@ -2210,16 +2210,85 @@
 ssion();
+%0A        ServletContext servletContext = session.getServletContext();
 %0A%0A      
@@ -2472,16 +2472,17 @@
 re os = 
+(
 ObjectSt
@@ -2488,31 +2488,59 @@
 tore
-Factory.getObjectStore(
+) servletContext.getAttribute(Constants.OBJECTSTORE
 );%0A%0A

Use ObjectStore from Application context