List of usage examples for org.hibernate SessionFactory getCurrentSession
Session getCurrentSession() throws HibernateException;
From source file:viewpatprof.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w ww .ja v a 2s.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"); PrintWriter out = response.getWriter(); try { SessionFactory sf = HibernateUtil.getSessionFactory(); Session ss1 = sf.getCurrentSession(); Transaction tr1 = ss1.beginTransaction(); HttpSession hs = request.getSession(); if (hs.getAttribute("doctor") != null) { if (request.getParameter("pid") != null) { int p_id = Integer.parseInt(request.getParameter("pid")); Patient p = (Patient) ss1.get(Patient.class, p_id); request.setAttribute("pdata", p); RequestDispatcher rd = request.getRequestDispatcher("viewpatprof.jsp"); rd.forward(request, response); } } } catch (HibernateException he) { he.getMessage(); } finally { out.close(); } }
From source file:changepassword.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from ww w . ja va2s.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"); PrintWriter out = response.getWriter(); String original_password = null; try { SessionFactory sf = HibernateUtil.getSessionFactory(); Session ss = sf.getCurrentSession(); Transaction tr = ss.beginTransaction(); HttpSession hs = request.getSession(); String old_password = request.getParameter("current"); String new_password = request.getParameter("new"); if (hs.getAttribute("patient") != null) { Patient p1 = (Patient) hs.getAttribute("patient"); Login l1 = (Login) ss.get(Login.class, p1.getUsedId().getUserId()); original_password = l1.getPassword(); // out.println(original_password); if (original_password.equals(old_password)) { l1.setPassword(new_password); ss.update(l1); p1.setUsedId(l1); hs.setAttribute("patient", p1); // hs.setAttribute("patient", l1); tr.commit(); request.setAttribute("msg", "Your password is updated.!"); RequestDispatcher rd = request.getRequestDispatcher("changepassword_patient.jsp"); rd.forward(request, response); } else { request.setAttribute("msg1", "enter your current password correctly"); RequestDispatcher rd = request.getRequestDispatcher("changepassword_patient.jsp"); rd.forward(request, response); } } else { tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("login.jsp"); rd.forward(request, response); } } catch (HibernateException he) { out.println(he.getMessage()); } finally { out.close(); } }
From source file:patient_view_labappointment.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from www. j a v a 2 s . 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"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ SessionFactory sf = HibernateUtil.getSessionFactory(); Session ss = sf.getCurrentSession(); Transaction tr = ss.beginTransaction(); HttpSession hs = request.getSession(); if (hs.getAttribute("patient") != null) { Patient p1 = (Patient) hs.getAttribute("patient"); Criteria cr = ss.createCriteria(LabAppointment.class); cr.add(Restrictions.eq("pId", p1)); ArrayList<LabAppointment> la = (ArrayList<LabAppointment>) cr.list(); if (la.size() > 0) { ArrayList<ArrayList<PatienttestDetail>> testarray = new ArrayList<ArrayList<PatienttestDetail>>( la.size()); for (int i = 0; i < la.size(); i++) { LabAppointment la1 = la.get(i); Criteria cr1 = ss.createCriteria(PatienttestDetail.class); cr1.add(Restrictions.eq("laId", la1)); ArrayList<PatienttestDetail> tests = (ArrayList<PatienttestDetail>) cr1.list(); testarray.add(tests); } request.setAttribute("la", la); if (testarray.size() > 0) { request.setAttribute("ptest", testarray); } System.out.println(testarray); } RequestDispatcher rd = request.getRequestDispatcher("patient_view_labappointment.jsp"); rd.forward(request, response); } else { tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("login.jsp"); rd.forward(request, response); } } }
From source file:patient_view_docappointment.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w. j a v a 2 s .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.getCurrentSession(); Transaction tr = ss.beginTransaction(); HttpSession hs = request.getSession(); if (hs.getAttribute("patient") != null) { Patient p1 = (Patient) hs.getAttribute("patient"); Criteria cr = ss.createCriteria(DoctorAppointment.class); cr.add(Restrictions.eq("pId", p1)); ArrayList<DoctorAppointment> la = (ArrayList<DoctorAppointment>) cr.list(); if (la.size() > 0) { ArrayList<DoctorAppointment> docarray = new ArrayList<DoctorAppointment>(la.size()); // for (int i = 0; i < la.size(); i++) { // DoctorAppointment da1 = la.get(i); // Criteria cr1 = ss.createCriteria(DoctorAppointment.class); // cr1.add(Restrictions.eq("daId", da1)); // ArrayList<DoctorAppointment> tests = (ArrayList<DoctorAppointment>) cr1.list(); // docarray.add(tests); // } Criteria cr1 = ss.createCriteria(DoctorAppointment.class); cr1.add(Restrictions.eq("pId", la)); request.setAttribute("la", la); if (docarray.size() > 0) { request.setAttribute("ptest", docarray); } System.out.println(docarray); } RequestDispatcher rd = request.getRequestDispatcher("patient_view_doctorappointment.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:changepassword_lab.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w. ja va 2 s.com*/ * * @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(); String original_password = null; try { SessionFactory sf = HibernateUtil.getSessionFactory(); Session ss = sf.getCurrentSession(); Transaction tr = ss.beginTransaction(); HttpSession hs = request.getSession(); String old_password = request.getParameter("current"); String new_password = request.getParameter("new"); if (hs.getAttribute("lab") != null) { Lab p1 = (Lab) hs.getAttribute("lab"); Login l1 = (Login) ss.get(Login.class, p1.getUserId().getUserId()); original_password = l1.getPassword(); // out.println(original_password); if (original_password.equals(old_password)) { l1.setPassword(new_password); ss.update(l1); p1.setUserId(l1); hs.setAttribute("lab", p1); // hs.setAttribute("patient", l1); tr.commit(); request.setAttribute("msg", "Your password is updated.!"); RequestDispatcher rd = request.getRequestDispatcher("change_password_lab.jsp"); rd.forward(request, response); } else { request.setAttribute("msg1", "enter your current password correctly"); RequestDispatcher rd = request.getRequestDispatcher("change_password_lab.jsp"); rd.forward(request, response); } } else { tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("login.jsp"); rd.forward(request, response); } } catch (HibernateException he) { out.println(he.getMessage()); } finally { out.close(); } }
From source file:lab_profile.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//ww w . jav a 2s . com * * @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.beginTransaction(); // tr1.begin(); HttpSession hs = request.getSession(); if (hs.getAttribute("lab") != null) { Lab li = (Lab) hs.getAttribute("lab"); if (request.getParameter("btn_update") != null) { Addressdetails ad = li.getAddressid(); String line = request.getParameter("line1"); ad.setLine1(line.trim()); ad.setLine2(request.getParameter("line2").trim()); ad.setPincode(request.getParameter("pincode").trim()); ss1.update(ad); li.setLabName(request.getParameter("p_firstname").trim()); li.setWebsite(request.getParameter("p_lastname").trim()); li.setContactNum(request.getParameter("gender").trim()); // pi.setContactnum(request.getParameter("contact_num").trim()); // pi.setEmailId(request.getParameter("email_id").trim()); ss1.update(li); tr1.commit(); hs.setAttribute("lab", li); request.setAttribute("pdata", li); RequestDispatcher rd = request.getRequestDispatcher("Lab_My_profile.jsp"); rd.forward(request, response); } else { request.setAttribute("pdata", li); RequestDispatcher rd = request.getRequestDispatcher("Lab_My_profile.jsp"); rd.forward(request, response); } } else { RequestDispatcher rd = request.getRequestDispatcher("login.jsp"); rd.forward(request, response); } } catch (HibernateException he) { he.getMessage(); } finally { out.close(); } }
From source file:uploadreport.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 ss = sf.getCurrentSession(); 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) { } } } catch (HibernateException he) { out.println(he.getMessage()); } finally { out.close(); } }
From source file:Testing.java
private static void test_juani_connection() { SessionFactory factory = Sesion.init(); Session session = factory.getCurrentSession(); try {/*from w w w.j a va2s . co m*/ session.beginTransaction(); List<Persona> personas = session.createQuery("from Persona").list(); for (Persona p : personas) { System.out.println(p); } session.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); } finally { Sesion.close(); } }
From source file:changepassword_doc.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w . ja va2s.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"); PrintWriter out = response.getWriter(); String original_password = null; try { SessionFactory sf = HibernateUtil.getSessionFactory(); Session ss = sf.getCurrentSession(); Transaction tr = ss.beginTransaction(); HttpSession hs = request.getSession(); String old_password = request.getParameter("current"); String new_password = request.getParameter("new"); if (hs.getAttribute("doctor") != null) { Doctor p1 = (Doctor) hs.getAttribute("doctor"); Login l1 = (Login) ss.get(Login.class, p1.getUserId().getUserId()); original_password = l1.getPassword(); // out.println(original_password); if (original_password.equals(old_password)) { l1.setPassword(new_password); ss.update(l1); p1.setUserId(l1); hs.setAttribute("doctor", p1); // hs.setAttribute("patient", l1); tr.commit(); request.setAttribute("msg", "Your password is updated.!"); RequestDispatcher rd = request.getRequestDispatcher("change_password_doc.jsp"); rd.forward(request, response); } else { request.setAttribute("msg1", "enter your current password correctly"); RequestDispatcher rd = request.getRequestDispatcher("change_password_doc.jsp"); rd.forward(request, response); } } else { tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("login.jsp"); rd.forward(request, response); } } catch (HibernateException he) { out.println(he.getMessage()); } finally { out.close(); } }
From source file:view_docprofile_admin.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* ww w . j a v a 2s . 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"); PrintWriter out = response.getWriter(); try { SessionFactory sf = HibernateUtil.getSessionFactory(); Session ss1 = sf.getCurrentSession(); Transaction tr1 = ss1.beginTransaction(); HttpSession hs = request.getSession(); if (hs.getAttribute("admin") != null) { if (request.getParameter("did") != null) { int d_id = Integer.parseInt(request.getParameter("did")); Doctor d = (Doctor) ss1.get(Doctor.class, d_id); request.setAttribute("ddata", d); RequestDispatcher rd = request.getRequestDispatcher("view_docprofile_admin.jsp"); rd.forward(request, response); } } else { RequestDispatcher rd = request.getRequestDispatcher("login.jsp"); rd.forward(request, response); } } catch (HibernateException he) { he.getMessage(); } finally { out.close(); } }