List of usage examples for org.hibernate Session update
void update(Object object);
From source file:doc_view_appointment.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from ww w .j ava 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"); 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("approve")) { doc1.setStatus("APPROVED"); doc1.setDate(request.getParameter("apdate")); doc1.setTime(request.getParameter("aptime")); ss.update(doc1); String subject = "Your Appointment is Approved.!"; String content = "Hi, " + doc1.getPId().getPFirstname() + "\n" + "Your appointment has been approved by Dr." + doc1.getDId().getDFirstname() + ".\n" + "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 accepted..!"); } else if (request.getParameter("status").equals("reject")) { doc1.setStatus("REJECTED"); ss.update(doc1); String subject = "Your Appointment is Rejected.!"; String content = "Hi, " + doc1.getPId().getPFirstname() + " " + "Your appointment has been rejected by Dr." + doc1.getDId().getDFirstname() + ".\n anil "; 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 rejected..!"); } } Criteria cr = ss.createCriteria(DoctorAppointment.class); cr.add(Restrictions.eq("dId", a)); cr.add(Restrictions.eq("status", "PENDING")); ArrayList<DoctorAppointment> da = (ArrayList<DoctorAppointment>) cr.list(); if (da.size() > 0) { request.setAttribute("da", da); } tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("doc_appointment_list.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:myprofile.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from www .j a v a 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(); try { /* TODO output your page here. You may use following sample code. */ SessionFactory sf = HibernateUtil.getSessionFactory(); Session ss1 = sf.getCurrentSession(); Transaction tr1 = ss1.getTransaction(); tr1.begin(); HttpSession hs = request.getSession(); if (hs.getAttribute("patient") != null) { Patient pi = (Patient) hs.getAttribute("patient"); if (request.getParameter("btn_update") != null) { Addressdetails ad = pi.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); pi.setPFirstname(request.getParameter("p_firstname").trim()); pi.setPLastname(request.getParameter("p_lastname").trim()); pi.setGender(request.getParameter("gender").trim()); pi.setBirthDate(request.getParameter("birth_date").trim()); pi.setContactNum(request.getParameter("contact_num").trim()); pi.setEmailId(request.getParameter("email_id").trim()); ss1.update(pi); tr1.commit(); hs.setAttribute("patient", pi); request.setAttribute("pdata", pi); RequestDispatcher rd = request.getRequestDispatcher("patient_myprofile.jsp"); rd.forward(request, response); } else { request.setAttribute("pdata", pi); RequestDispatcher rd = request.getRequestDispatcher("patient_myprofile.jsp"); rd.forward(request, response); } } else { RequestDispatcher rd = request.getRequestDispatcher("login.jsp"); rd.forward(request, response); } } catch (HibernateException he) { out.println(he.getMessage()); } finally { out.close(); } }
From source file:lab_view_approved_appointment.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.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:doc_view_approved_appointment.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w. j av 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 { 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:lab_mytest.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w .java2s. 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); } } }
From source file:cust_update.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 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, FileUploadException { response.setContentType("text/html;charset=UTF-8"); HttpSession hs = request.getSession(); PrintWriter out = response.getWriter(); try { if (hs.getAttribute("user") != null) { Login ln = (Login) hs.getAttribute("user"); System.out.println(ln.getUId()); String firstn = ""; String lastn = ""; String un = ""; String state = ""; String city = ""; int id = 0; String e = ""; String num = ""; String p = ""; String custphoto = ""; String custname = ""; String area = ""; // creates FileItem instances which keep their content in a temporary file on disk FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); //get the list of all fields from request List<FileItem> fields = upload.parseRequest(request); // iterates the object of list Iterator<FileItem> it = fields.iterator(); //getting objects one by one while (it.hasNext()) { //assigning coming object if list to object of FileItem FileItem fileItem = it.next(); //check whether field is form field or not boolean isFormField = fileItem.isFormField(); if (isFormField) { //get the filed name String fieldName = fileItem.getFieldName(); if (fieldName.equals("fname")) { firstn = fileItem.getString(); System.out.println(firstn); } else if (fieldName.equals("id")) { id = Integer.parseInt(fileItem.getString()); } else if (fieldName.equals("lname")) { lastn = fileItem.getString(); System.out.println(lastn); } else if (fieldName.equals("uname")) { un = fileItem.getString(); System.out.println(un); } else if (fieldName.equals("state")) { state = fileItem.getString(); System.out.println(state); } else if (fieldName.equals("city")) { city = fileItem.getString(); System.out.println(city); } else if (fieldName.equals("area")) { area = fileItem.getString(); } else if (fieldName.equals("email")) { e = fileItem.getString(); System.out.println(e); } else if (fieldName.equals("number")) { num = fileItem.getString(); System.out.println(num); } else if (fieldName.equals("pwd")) { p = fileItem.getString(); System.out.println(p); } } else { //getting name of file custphoto = new File(fileItem.getName()).getName(); //get the extension of file by diving name into substring // String extension=custphoto.substring(custphoto.indexOf(".")+1,custphoto.length());; //rename file...concate name and extension // custphoto=ln.getUId()+"."+extension; System.out.println(custphoto); try { // FOR UBUNTU add GETRESOURCE and GETPATH String fp = "/home/rushin/NetBeansProjects/The_Asset_Consultancy/web/images/profilepic/"; // String filePath= this.getServletContext().getResource("/images/profilepic").getPath()+"\\"; System.out.println("====" + fp); fileItem.write(new File(fp + custphoto)); } catch (Exception ex) { out.println(ex.toString()); } } } SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); // // String op=""; // cr.add(Restrictions.eq("sId", Integer.parseInt(state))); // ArrayList<StateMaster> ar = (ArrayList<StateMaster>)cr.list(); // if(ar.isEmpty()){ // // }else{ // StateMaster sm = ar.get(0); // op=sm.getSName(); // // } CustomerDetail cd1 = (CustomerDetail) ss.get(CustomerDetail.class, id); System.out.println("cid is " + cd1.getCId()); CustomerDetail cd = new CustomerDetail(); cd.setUId(cd1.getUId()); cd.setCId(cd1.getCId()); cd.setCFname(firstn); cd.setCLname(lastn); cd.setCNum(num); cd.setCEmail(e); cd.setCState(state); cd.setCCity(city); cd.setCArea(area); cd.setCImg(custphoto); ss.evict(cd1); ss.update(cd); tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("customerprofile.jsp"); rd.forward(request, response); } } catch (HibernateException e) { out.println(e.getMessage()); } }
From source file:SortedMapJUnitTest.java
@Test public void updateCar() { /*zakadamy e w bazie isntnieje samochd o id 1 */ final Integer carIDToTest = 2; int random_year_production = (new Random()).nextInt(100) + 1900; Session session = sessionFctry.openSession(); Transaction tx = null;/*www. j a v a2 s . c o m*/ try { tx = session.beginTransaction(); Car car = (Car) session.get(Car.class, carIDToTest); assertNotNull(car); //do aktualizacji musi istnie w bazie obiekt o id 1 car.setProduction_year(random_year_production); session.update(car); tx.commit(); } catch (HibernateException e) { if (tx != null) tx.rollback(); e.printStackTrace(); } finally { session.close(); } /* sprawdzenie czy obiekt si zaktualizowa */ session = sessionFctry.openSession(); int readed_production_year = 0; try { tx = session.beginTransaction(); Car car = (Car) session.get(Car.class, carIDToTest); assertNotNull(car); //do aktualizacji musi istnie w bazie obiekt o id 1 readed_production_year = car.getProduction_year(); tx.commit(); } catch (HibernateException e) { if (tx != null) tx.rollback(); e.printStackTrace(); } finally { session.close(); } assertEquals(random_year_production, readed_production_year); }
From source file:SortedMapJUnitTest.java
@Test(expected = StaleStateException.class) public void testUpdateCarException01() { /*zakadamy e w bazie isntnieje samochd o id 1 */ final Integer carIDToTest = 2; int random_year_production = (new Random()).nextInt(100) + 1900; Session session = sessionFctry.openSession(); Transaction tx = null;/*from w w w . jav a2 s. c o m*/ tx = session.beginTransaction(); Car car = new Car("Opel", "Corsa Mk2", 1998, 3700, "Diesel 2.0", new TreeMap()); session.update(car); tx.commit(); session.close(); /* sprawdzenie czy obiekt si zaktualizowa */ session = sessionFctry.openSession(); int readed_production_year = 0; tx = session.beginTransaction(); car = (Car) session.get(Car.class, carIDToTest); assertNotNull(car); //do aktualizacji musi istnie w bazie obiekt o id 1 readed_production_year = car.getProduction_year(); tx.commit(); session.close(); assertEquals(random_year_production, readed_production_year); }
From source file:SortedMapJUnitTest.java
@Test(expected = IllegalArgumentException.class) public void testUpdateCarException02() { /*zakadamy e w bazie isntnieje samochd o id 1 */ final Integer carIDToTest = 2; int random_year_production = (new Random()).nextInt(100) + 1900; Session session = sessionFctry.openSession(); Transaction tx = null;/*w w w . ja va 2 s . c om*/ tx = session.beginTransaction(); Car car = (Car) session.get(Car.class, carIDToTest); assertNotNull(car); //do aktualizacji musi istnie w bazie obiekt o id 1 car.setProduction_year(random_year_production); session.update(null); tx.commit(); session.close(); /* sprawdzenie czy obiekt si zaktualizowa */ session = sessionFctry.openSession(); int readed_production_year = 0; tx = session.beginTransaction(); car = (Car) session.get(Car.class, carIDToTest); assertNotNull(car); //do aktualizacji musi istnie w bazie obiekt o id 1 readed_production_year = car.getProduction_year(); tx.commit(); session.close(); assertEquals(random_year_production, readed_production_year); }
From source file:TestUpdate.java
public static void main(String[] args) { Supplier entity = new Supplier(); entity.setId(9);/* w ww . j a v a 2s . co m*/ entity.setName("Test"); entity.setNote("bbbbb"); Session ses = utils.HibernateUtils.getSessionFactory().getCurrentSession(); try { ses.beginTransaction(); ses.update(entity); ses.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); ses.getTransaction().rollback(); } }