QueryTest.java

Go to the documentation of this file.
00001 package cedar.hepdata.webapp;
00002 
00003 import cedar.hepdata.model.*;
00004 import cedar.hepdata.xml.*;
00005 
00006 import java.io.*;
00007 import java.util.*;
00008 import javax.servlet.*;
00009 import javax.servlet.http.*;
00010 import java.sql.*;
00011 
00017 public class QueryTest extends HttpServlet {
00018 
00020     public String getServletInfo() {
00021         return "Test servlet. Do not use.";
00022     }
00023 
00025     public void doGet(HttpServletRequest request, HttpServletResponse response)
00026         throws IOException, ServletException
00027     {
00028         response.setContentType("text/html");
00029         PrintWriter out = response.getWriter();
00030         out.println("Currently disabled while the db code is refactored");
00031 
00032 //         // Get params from the query string
00033 //         String irnStr = request.getParameter("irn");
00034 //         String reacStr = request.getParameter("reac");
00035 //         String obsStr = request.getParameter("obs");
00036 //         String exptStr = request.getParameter("expt");
00037 //         String detrStr = request.getParameter("detr");
00038 //         if (irnStr == null)  irnStr = "";
00039 //         if (obsStr == null)  obsStr = "";
00040 //         if (reacStr == null) reacStr = "K+ P --> K0 X";
00041 //         if (exptStr == null) exptStr = "";
00042 //         if (detrStr == null) detrStr = "";
00043 
00044         try {
00045 //             String exptquery = "SELECT * FROM experiment WHERE description NOT LIKE '\\?%' ORDER BY description";
00046 //             String detrquery = "SELECT * FROM detector WHERE description NOT LIKE '\\?%' ORDER BY description";
00047 
00048 //             // Write out query form
00049 //             out.println("<h1>HepData query testing</h1>");
00050 //             out.println("<form style=\"margin-bottom:1em; padding:0.5em; background:beige; border:2px solid lightgrey;\" method=\"GET\" action=\"/server/hepdata-test/query\" />");
00051 //             out.println("<p>Empty fields will match any value of the corresponding quantity:</p>");
00052 //             out.println("<table>");
00053 //             // IRN field
00054 //             out.println("<tr><td><label for=\"irn\">Paper IRN: </label></td>");
00055 //             out.println("<td><input name=\"irn\" type=\"text\" value=\"" + irnStr + "\" size=\"20\"></td></tr>");
00056 //             // Reaction field
00057 //             out.println("<tr><td><label for=\"reac\">Reaction: </label></td>");
00058 //             out.println("<td><input name=\"reac\" type=\"text\" value=\"" + reacStr + "\" size=\"20\"></td></tr>");
00059 //             // Observable field
00060 //             out.println("<tr><td><label for=\"obs\">Observable: </label></td>");
00061 //             out.println("<td><select name=\"obs\">");
00062 //             out.println("<option value=\"ANY\">Any</option>");
00063 //             out.println("<option value=\"SIG\">Cross-section</option>");
00064 //             out.println("<option value=\"SQRTS\">CoM energy</option>");
00065 //             out.println("</select></td></tr>");
00066 //             // Experiment field
00067 //             /*
00068 //             out.println("<tr><td><label for=\"expt\">Experiment: </label></td>");
00069 //             out.println("<td><select name=\"expt\">");
00070 //             out.println("<option value=\"ANY\">Any</option>");
00071 //             while (rsexpts.next()) {
00072 //                 String exptDesc = rsexpts.getString("description");
00073 //                 String exptId = rsexpts.getString("experiment_id");
00074 //                 if (exptId != null && exptDesc != null) {
00075 //                     out.print("<option value=\"" + exptId + "\"");
00076 //                     if (exptStr.equals(exptId)) {
00077 //                         out.print(" selected=\"selected\"");
00078 //                     }
00079 //                     out.println(">" + exptDesc + "</option>");
00080 //                 }
00081 //             }
00082 //             out.println("</select></td></tr>");
00083 //             */
00084 //             // Detector field
00085 //             out.println("<tr><td><label for=\"expt\">Detector: </label></td>");
00086 //             out.println("<td><select name=\"detr\">");
00087 //             out.println("<option value=\"ANY\">Any</option>");
00088 //             while (rsdetrs.next()) {
00089 //                 String detrDesc = rsdetrs.getString("description");
00090 //                 String detrId = rsdetrs.getString("detector_id");
00091 //                 if (detrId != null && detrDesc != null) {
00092 //                     out.print("<option value=\"" + detrId + "\"");
00093 //                     if (detrStr.equals(detrId)) {
00094 //                         out.print(" selected=\"selected\"");
00095 //                     }
00096 //                     out.println(">" + detrDesc + "</option>");
00097 //                 }
00098 //             }
00099 //             out.println("</select></td></tr>");
00100 //             // Submit button
00101 //             out.println("<tr><td/><td><input type=\"submit\" value=\"Go!\" style=\"float:right\" /></td></tr>");
00102 //             out.println("</table>");
00103 //             out.println("</form>");
00104 
00105 //             // Show params from query string
00106 //             // out.println("<h3>Params:</h3>");
00107 //             // out.println("<ul>");
00108 //             // out.println("<li>irn  = " + irnStr + "</li>");
00109 //             // out.println("<li>obs  = " + obsStr  + "</li>");
00110 //             // out.println("<li>reac = " + reacStr + "</li>");
00111 //             // out.println("<li>expt = " + exptStr + "</li>");
00112 //             // out.println("</ul>");
00113 
00114 //             //Vector<String> finalstate = new Vector<String>();
00115 //             //finalstate.add("K+");
00116 //             //finalstate.add("PI-");
00117 
00118 //             // Build SQL query
00119 //             String query = new String();
00120 //             query += "SELECT DISTINCT kr.paper_id paperId, kr.ds_id dsId, o.description obsDesc, r.description reacDesc ";
00121 //             query += "FROM (keyword kr JOIN keyword ko USING (paper_id,ds_id)) ";
00122 //             query += "JOIN observable o ON o.observable_id=ko.observable_id ";
00123 //             query += "JOIN reaction r ON r.reaction_id=kr.reaction_id ";
00124 //             query += "JOIN final_particle fp ON fp.reaction_id=r.reaction_id ";
00125 //             query += "JOIN particle p ON p.particle_id=fp.particle_id ";
00126 //             query += "JOIN paper ON paper.paper_id=kr.paper_id ";
00127 //             query += "JOIN paper_experiment pp_ex ON pp_ex.paper_id=kr.paper_id ";
00128 //             query += "JOIN experiment ex ON ex.experiment_id=pp_ex.experiment_id ";
00129 //             query += "JOIN paper_detector pp_det ON pp_det.paper_id=kr.paper_id ";
00130 //             query += "JOIN detector det ON det.detector_id=pp_det.detector_id ";
00131 //             query += "WHERE (ko.observable_id IS NOT NULL and kr.reaction_id IS NOT NULL) ";
00132 //             // Handle conditional bits of the query:
00133 //             // IRN
00134 //             if (irnStr != null && irnStr.length() != 0 && ! irnStr.equalsIgnoreCase("ANY")) {
00135 //                 query += "AND paper.irn=" + irnStr + " ";
00136 //             }
00137 //             // Observable
00138 //             if (obsStr != null && obsStr.length() != 0 && ! obsStr.equalsIgnoreCase("ANY")) {
00139 //                 query += "AND o.description='" + obsStr + "' ";
00140 //             }
00141 //             // Reaction (we may need to be able to do SQL UNION operations on the final states)
00142 //             if (reacStr != null && reacStr.length() != 0 && ! reacStr.equalsIgnoreCase("ANY")) {
00143 //                 query += "AND r.description='" + reacStr + "' ";
00144 //             }
00145 //             // Experiment
00146 //             if (exptStr != null && exptStr.length() != 0 && ! exptStr.equalsIgnoreCase("ANY")) {
00147 //                 query += "AND ex.experiment_id=" + exptStr + " ";
00148 //             }
00149 //             // Detector
00150 //             if (detrStr != null && detrStr.length() != 0 && ! detrStr.equalsIgnoreCase("ANY")) {
00151 //                 query += "AND det.detector_id=" + detrStr + " ";
00152 //             }
00153 //             query += "LIMIT 100;";
00154 
00155 //             // Database searching
00156 //             //Statement stmt = DBConfig.getConnection().createStatement();
00157 //             ResultSet rs = stmt.executeQuery(query);
00158 //             out.println("<h3>Results</h3>");
00159 //             out.println("<p>Click on the paper or dataset link to see the data:</p>");
00160 //             out.println("<ol>");
00161 //             while (rs.next()) {
00162 //                 Integer paperId = new Integer(rs.getString("paperId"));
00163 //                 Integer dsId = new Integer(rs.getString("dsId"));
00164 //                 Paper paper = new Paper((int) paperId);
00165 //                 Integer irn = paper.getIrn();
00166 //                 out.println("<li>");
00167 //                 if (irn != null) { out.println("<a href=\"/server/hepdata-test/xsl?irn=" + irn + "\">"); }
00168 //                 out.println("Paper " + paperId);
00169 //                 if (irn != null) { out.println("</a>"); }
00170 //                 out.println(", ");
00171 //                 if (irn != null) { out.println("<a href=\"/server/hepdata-test/xsl?irn=" + irn + "#dataset" + dsId + "\">"); }
00172 //                 out.println("dataset " + dsId);
00173 //                 if (irn != null) { out.println("</a>"); }
00174 //                 out.print(": " + rs.getString("obsDesc") + " / " + rs.getString("reacDesc"));
00175 //                 Dataset ds = new Dataset(paperId, dsId);
00176 //                 out.println(" " + ds.toString());
00177 //                 out.println("</li>");
00178 //             }
00179 //             out.println("</ol>");
00180 
00181 //             // Close up...
00182 //             rs.close();
00183 //             stmt.close();
00184 
00185 //             // Write out SQL query
00186 //             out.println("<h3>SQL query (for debug)</h3>");
00187 //             out.println("<code style=\"font-size:50%\">" + query + "</code>");
00188 //             out.println("<br/>");
00189 
00190         } catch (Exception e) {
00191             out.println("Exception: " + e.toString());
00192         }
00193 
00194     }
00195 }

Generated on Tue Apr 21 15:55:00 2009 for HepData Web servlets by  doxygen 1.5.5