/* // $Id: //guest/julian_hyde/mondrian/src/main/mondrian/web/servlet/MDXQueryServlet.java#2 $ // (C) Copyright 2002 Kana Software, Inc. // This software is subject to the terms of the Common Public License // Agreement, available at the following URL: // http://www.opensource.org/licenses/cpl.html. // (C) Copyright 2002 Kana Software, Inc. and others. // All Rights Reserved. // You must accept the terms of that agreement to use this software. // // Sean McCullough, 13 February, 2002, 10:25 PM */ package mondrian.web.servlet; import mondrian.olap.*; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.StringTokenizer; /** * <code>MDXQueryServlet</code> is a servlet which receives MDX queries, * executes them, and formats the results in an HTML table. * * @author Sean McCullough * @since 13 February, 2002 * @version $Id: //guest/julian_hyde/mondrian/src/main/mondrian/web/servlet/MDXQueryServlet.java#2 $ */ public class MDXQueryServlet extends HttpServlet { String connectString; /** Initializes the servlet. */ public void init(ServletConfig config) throws ServletException { super.init(config); String resourceURL = config.getInitParameter("resourceURL"); System.getProperties().put("mondrian.resourceURL", resourceURL); mondrian.olap.Util.setThreadRes(MondrianResource.instance()); connectString = config.getInitParameter("connectString"); String jdbcDrivers = config.getInitParameter("jdbcDrivers"); StringTokenizer tok = new java.util.StringTokenizer(jdbcDrivers, ","); while (tok.hasMoreTokens()) { String jdbcDriver = tok.nextToken(); try { Class.forName(jdbcDriver); } catch (ClassNotFoundException e) { e.printStackTrace(); } } } /** Destroys the servlet. */ public void destroy() { } /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request * @param response servlet response */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { String queryString = request.getParameter("queryString"); request.setAttribute("queryString", queryString); String resultString = "result"; mondrian.olap.Connection mdxConnection = null; StringBuffer html = new StringBuffer(); //execute the query try { mdxConnection = DriverManager.getConnection(connectString, null, false); Query q = mdxConnection.parseQuery(queryString); Result result = mdxConnection.execute(q); Position slicers[] = result.getSlicerAxis().positions; html.append("<table class='resulttable' cellspacing=1 border=0><tr><td nowrap class='slicer'>"); for (int i=0; i<slicers.length; i++) { Position position = slicers[i]; for (int j = 0; j < position.members.length; j++) { Member member = position.members[j]; html.append(member.getUniqueName()); } } html.append(" </td>"); Position columns[] = result.getAxes()[0].positions; for (int i=0; i<columns.length; i++) { Position position = columns[i]; for (int j = 0; j < position.members.length; j++) { Member member = position.members[j]; html.append("<td nowrap class='columnheading'>" + member.getUniqueName() + "</td>"); } } html.append("</tr>"); if (result.getAxes().length > 1) { for (int i=0; i<result.getAxes()[1].positions.length; i++) { //TODO: fix this to iterate over multiple members if they exist for this position Member m = result.getAxes()[1].positions[i].members[0]; html.append("<tr><td nowrap class='rowheading'>" + m.getUniqueName() + "</td>"); for (int j=0; j<result.getAxes()[0].positions.length; j++) { Cell cell = result.getCell(new int[]{j,i}); html.append("<td class='cell'>" + cell.getFormattedValue() + "</td>"); } html.append("</tr>"); } } else { for (int i=0; i<result.getAxes()[0].positions.length; i++) { Cell cell = result.getCell(new int[]{i}); html.append("<tr><td></td><td class='cell'>" + cell.getFormattedValue() + "</td></tr>"); } } html.append("</table>"); } catch (Throwable e) { html.append("Error: " + e.getMessage()); e.printStackTrace(); } finally { if (mdxConnection != null) { mdxConnection.close(); } } request.setAttribute("result", html.toString()); getServletContext().getRequestDispatcher("/index.jsp").include(request, response); } /** Handles the HTTP <code>GET</code> method. * @param request servlet request * @param response servlet response */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { processRequest(request, response); } /** Handles the HTTP <code>POST</code> method. * @param request servlet request * @param response servlet response */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { processRequest(request, response); } /** Returns a short description of the servlet. */ public String getServletInfo() { return "Process an MDX query and return the result formatted as an HTML table"; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 1576 | Julian Hyde |
mondrian: fix dataset (add column customer.ordinal); create dataset for oracle; get queries working on oracle; get format strings working; refactor out new packages mondrian.rolap.agg and mondrian.rolap.sql. |
||
#1 | 1509 | Julian Hyde | Mondrian: environment fixes. | ||
//guest/julian_hyde/mondrian/src/main/mondrian/web/MDXQueryServlet.java | |||||
#1 | 1507 | Julian Hyde |
Mondrian: Forgot to add MDXQueryServlet.java; Installation instructions for Tomcat. |