List of usage examples for org.hibernate Criteria list
public List list() throws HibernateException;
From source file:ConsultaPincel.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//w ww. ja va 2 s . c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { try { String cor = request.getParameter("cor"); Session s = HibernateUtil.getSessionFactory().openSession(); Criteria criteria = s.createCriteria(Pincel.class); criteria.add(Restrictions.eq("cor", cor)); List<Pincel> result = criteria.list(); out.println("Pinceis encontrados (" + result.size() + "): <br>"); for (Pincel p : result) { out.println("<br>Pincel num:" + p.getNum_serie()); out.println("<br>cor :" + p.getCor()); out.println("<br>"); } s.close(); } catch (Exception ex) { out.println("Erro ao buscar pinceis: " + ex.getMessage()); } } }
From source file:writeblog.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w w w . j a v a 2 s. co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { SessionFactory sf = HibernateUtil.getSessionFactory(); Session ss1 = sf.getCurrentSession(); Transaction tr1 = ss1.getTransaction(); tr1.begin(); HttpSession hs = request.getSession(); if (hs.getAttribute("doctor") != null) { Doctor pi = (Doctor) hs.getAttribute("doctor"); if (request.getParameter("subject") != null && request.getParameter("content") != null) { String sub = request.getParameter("subject"); String con = request.getParameter("content"); request.setAttribute("msg", "Blog Created..!"); Blog b = new Blog(); if (request.getParameter("updateblogid") != null) { b.setBlogId(Integer.parseInt(request.getParameter("updateblogid"))); request.setAttribute("msg", "Blog Updated..!"); } b.setBlogname(sub); b.setBlogdescription(con); b.setDId(pi); b.setBlogView(20); b.setImageUrl("abc.jpg"); b.setBlogDate(new Date().toString()); ss1.saveOrUpdate(b); } if (request.getParameter("blogid") != null) { Blog b = (Blog) ss1.get(Blog.class, Integer.parseInt(request.getParameter("blogid"))); request.setAttribute("editblog", b); } Criteria cr1 = ss1.createCriteria(Blog.class); cr1.add(Restrictions.eq("dId", pi)); ArrayList<Blog> dblog = (ArrayList<Blog>) cr1.list(); if (dblog.size() > 0) { request.setAttribute("dblog", dblog); } tr1.commit(); RequestDispatcher rd = request.getRequestDispatcher("doctor_write_blog1.jsp"); rd.forward(request, response); } else { tr1.commit(); RequestDispatcher rd = request.getRequestDispatcher("login.jsp"); rd.forward(request, response); } } catch (HibernateException he) { out.println(he.getMessage()); } finally { out.close(); } }
From source file:ConsultaIngrediente.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w .ja v a2 s.co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ try { String ing = request.getParameter("ing"); Session s = HibernateUtil.getSessionFactory().openSession(); Criteria criteria = s.createCriteria(Ingrediente.class); criteria.add(Restrictions.eq("nome", ing)); List<Ingrediente> result = criteria.list(); out.println("ingredientes encontrados (" + result.size() + "): <br>"); for (Ingrediente i : result) { out.println("<br>Ingrediente:" + i.getNome()); out.println("<br>Qtds :" + i.getQtd()); out.println("<br>Valor :" + i.getValor()); out.println("<br>"); } s.close(); } catch (Exception ex) { out.println("Erro na busca: " + ex.getMessage()); } } }
From source file:lab_view_approved_appointment.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from www. j a v a 2s . c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { SessionFactory sf = HibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); HttpSession hs = request.getSession(); if (hs.getAttribute("lab") != null) { Lab a = (Lab) hs.getAttribute("lab"); if (request.getParameter("status") != null && request.getParameter("appoid") != null) { int apid = Integer.parseInt(request.getParameter("appoid")); LabAppointment lab1 = (LabAppointment) ss.get(LabAppointment.class, apid); if (request.getParameter("status").equals("cancel")) { lab1.setStatus("CANCELLED"); ss.update(lab1); request.setAttribute("msg", "Appointment cancelled..!"); } else if (request.getParameter("status").equals("update")) { // doc1.setStatus("CANCELLED"); lab1.setDate(request.getParameter("apdate")); lab1.setTime(request.getParameter("aptime")); ss.update(lab1); request.setAttribute("msg", "Appointment Updated..!"); } } Criteria cr = ss.createCriteria(LabAppointment.class); cr.add(Restrictions.eq("lId", a)); cr.add(Restrictions.eq("status", "APPROVED")); ArrayList<LabAppointment> da = (ArrayList<LabAppointment>) cr.list(); if (da.size() > 0) { request.setAttribute("da", da); } tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("Lab_Approved_appointment.jsp"); rd.forward(request, response); } else { tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("login.jsp"); rd.forward(request, response); } } catch (HibernateException he) { he.getMessage(); } finally { out.close(); } }
From source file:consultaEstrela.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w .j ava2s .c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { try { String Nome = request.getParameter("Nome"); Session s = HibernateUtil.getSessionFactory().openSession(); Criteria criteria = s.createCriteria(Estrela.class); criteria.add(Restrictions.eq("Nome", Nome)); List<Estrela> result = criteria.list(); out.println("Estrelas encontradas (" + result.size() + "): <br>"); for (Estrela e : result) { out.println("<br>Estrela:" + e.getDistancia_da_Terra()); out.println("<br>cor :" + e.getNome()); out.println("<br>"); } s.close(); } catch (Exception ex) { out.println("Erro ao buscar estrelas: " + ex.getMessage()); } } }
From source file:agentfeedbacklist_serv.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w ww. j a v a 2 s.c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); try { SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); Criteria cr = ss.createCriteria(AgentFeedback.class); ArrayList<AgentFeedback> afl = (ArrayList<AgentFeedback>) cr.list(); if (!afl.isEmpty()) { request.setAttribute("afl", afl); RequestDispatcher rd = request.getRequestDispatcher("agentfeedbacklist.jsp"); rd.forward(request, response); } } catch (HibernateException e) { out.print(e.getMessage()); } }
From source file:ConsultaOcorrencia.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w . j ava2s . co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet ConsultaOcorrencia</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet ConsultaOcorrencia at " + request.getContextPath() + "</h1>"); out.println("</body>"); out.println("</html>"); Session s = HibernateUtil.getSessionFactory().openSession(); Criteria criteria = s.createCriteria(Ocorrencia.class); criteria.add(Restrictions.eq("nome", "Hugo")); List<Ocorrencia> result = criteria.list(); out.println("Ocorrencias encontradas: <br/>"); for (Ocorrencia o : result) { out.println("Ocorrencia n: " + o.getNome()); } s.close(); } }
From source file:doc_view_approved_appointment.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w ww . java2 s. co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { SessionFactory sf = HibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); HttpSession hs = request.getSession(); if (hs.getAttribute("doctor") != null) { Doctor a = (Doctor) hs.getAttribute("doctor"); if (request.getParameter("status") != null && request.getParameter("appoid") != null) { int apid = Integer.parseInt(request.getParameter("appoid")); DoctorAppointment doc1 = (DoctorAppointment) ss.get(DoctorAppointment.class, apid); if (request.getParameter("status").equals("cancel")) { doc1.setStatus("CANCELLED"); ss.update(doc1); String subject = "Appointment Canceled.!"; String content = "Hi, " + doc1.getPId().getPFirstname() + " " + "Your appointment has been Canceled by Dr." + doc1.getDId().getDFirstname() + " due to some reasons and we are sorry for that kindly take new appointment ASAP." + ".\n "; String mail = doc1.getPId().getEmailId(); String[] recipients = new String[] { mail }; //String[] bccRecipients = new String[]{"sunilkotadiya777@gmail.com"}; if (new MailUtil().sendMail(recipients, subject, content)) { } request.setAttribute("msg", "Appointment cancelled..!"); } else if (request.getParameter("status").equals("update")) { // doc1.setStatus("CANCELLED"); doc1.setDate(request.getParameter("apdate")); doc1.setTime(request.getParameter("aptime")); ss.update(doc1); String subject = "Appointment time changed.!"; String content = "Hi, " + doc1.getPId().getPFirstname() + " " + "Your appointment has been rescheduled by Dr." + doc1.getDId().getDFirstname() + " due to some reasons kindly note new time" + " " + "Date : " + doc1.getDate() + "\n" + "Time : " + doc1.getTime() + "\n"; String mail = doc1.getPId().getEmailId(); String[] recipients = new String[] { mail }; //String[] bccRecipients = new String[]{"sunilkotadiya777@gmail.com"}; if (new MailUtil().sendMail(recipients, subject, content)) { } request.setAttribute("msg", "Appointment Updated..!"); } } Criteria cr = ss.createCriteria(DoctorAppointment.class); cr.add(Restrictions.eq("dId", a)); cr.add(Restrictions.eq("status", "APPROVED")); ArrayList<DoctorAppointment> da = (ArrayList<DoctorAppointment>) cr.list(); if (da.size() > 0) { request.setAttribute("da", da); } tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("doc_approved_appointment.jsp"); rd.forward(request, response); } else { tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("login.jsp"); rd.forward(request, response); } } catch (HibernateException he) { he.getMessage(); } finally { out.close(); } }
From source file:agentlist_serv.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww . ja v a 2 s . co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); Criteria cr = ss.createCriteria(AgentDetail.class); ArrayList<AgentDetail> adl = (ArrayList<AgentDetail>) cr.list(); if (!adl.isEmpty()) { request.setAttribute("adl", adl); RequestDispatcher rd = request.getRequestDispatcher("agentlist.jsp"); rd.forward(request, response); } } catch (HibernateException e) { out.print(e.getMessage()); } }
From source file:lab_mytest.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*ww w. j ava2 s. co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ SessionFactory sf = HibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); HttpSession hs = request.getSession(); if (hs.getAttribute("lab") != null) { Lab lb = (Lab) hs.getAttribute("lab"); if (request.getParameter("price") != null && request.getParameter("ltid") != null) { int ltid = Integer.parseInt(request.getParameter("ltid")); Double price = Double.parseDouble(request.getParameter("price")); Labtest lt = (Labtest) ss.get(Labtest.class, ltid); lt.setTestFees(price); ss.update(lt); request.setAttribute("msg", "Test price updated.!"); } Criteria cr = ss.createCriteria(Labtest.class); cr.add(Restrictions.eq("lId", lb)); ArrayList<Labtest> ltest = (ArrayList<Labtest>) cr.list(); if (ltest.size() > 0) { request.setAttribute("ltest", ltest); } tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("lab_mytest.jsp"); rd.forward(request, response); } else { tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("login.jsp"); rd.forward(request, response); } } }