00001 package cedar.hepdata.webapp;
00002
00003 import cedar.hepdata.model.*;
00004 import cedar.hepdata.xml.*;
00005 import cedar.hepdata.db.*;
00006 import org.hibernate.Query;
00007
00008 import java.io.*;
00009 import java.util.*;
00010 import javax.servlet.*;
00011 import javax.servlet.http.*;
00012
00018 public class DbDemo extends HttpServlet {
00019
00021 public String getServletInfo() {
00022 return "Demonstrate object model and persistency.";
00023 }
00024
00025
00027 public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
00028 response.setContentType("text/html");
00029 PrintWriter out = response.getWriter();
00030
00031 try {
00032 out.println("<h1>Model-db demo</h1>");
00033 DbUtils.beginTransaction();
00034 String qstr = "select distinct p from Paper as p";
00035 qstr += " left join fetch p._datasets as d";
00036
00037
00038
00039
00040
00041 Query q = DbUtils.createQuery(qstr);
00042 List results = q.list();
00043 if (results != null) {
00044 for (Object result : results) {
00045 Paper p = (Paper) result;
00046 out.println("<div style=\"background:#c6deff; border:#82cafa 1px solid; margin:2em 1em; padding:1em; width:80%;\">");
00047 out.println("<h2>" + p.getSpiresId().toString() + "</h2>");
00048 out.println("<pre style=\"background:#ffc; border:#fc3 1px solid; padding:1em; overflow:hidden; \">" + p.toString() + "</pre>");
00049 out.println("<pre style=\"background:#ffc; border:#fc3 1px solid; padding:1em;\">" + XMLUtils.makeHepMLString(p) + "</pre>");
00050 out.println("</div>");
00051 }
00052 }
00053 DbUtils.endTransaction();
00054
00055 } catch (Exception e) {
00056 out.println("Exception: " + e.toString());
00057 }
00058
00059 }
00060 }