List of usage examples for org.hibernate Session load
void load(Object object, Serializable id);
From source file:com.certus.actions.setAsViewedUserAction.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); Messages msg = (Messages) s.load(Messages.class, Integer.parseInt(request.getParameter("mid"))); s.beginTransaction();//from ww w .ja v a 2 s .co m msg.setUserViewed(true); s.update(msg); s.getTransaction().commit(); s.close(); response.getWriter().write("success"); }
From source file:com.certus.actions.setDiscountAction.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getParameter("discPre") != null) { int pid = Integer.parseInt(request.getParameter("pid")); int sid = Integer.parseInt(request.getParameter("sid")); Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); Product p = (Product) s.load(Product.class, pid); s.beginTransaction();// w w w .ja va 2 s.c o m p.setDiscountPrice(Integer.parseInt(request.getParameter("discPre"))); s.getTransaction().commit(); s.close(); response.sendRedirect("edit_product.jsp?pid=" + pid + "&sid=" + sid); } }
From source file:com.certus.actions.siteGeneralLoadAction.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String html = ""; Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); SiteGeneral general = (SiteGeneral) s.load(SiteGeneral.class, 1); html += "<tr>" + " <td>Site Address : </td>" + " <td>" + " <div class=\"input-group\">" + " <input type=\"text\" id=\"addrsG\" value=\"" + general.getSiteAddress() + "\" class=\"form-control\" >" + " <span class=\"input-group-addon\" style='color:red;'>*</span>" + " </div>" + " </td>" + " </tr>" + " <tr>" + " <td>Telephone Number : </td>" + " <td>" + " <div class=\"input-group\">" + " <input type=\"text\" id=\"telG\" value=\"" + general.getTel() + "\" class=\"form-control\" >" + " <span class=\"input-group-addon\" style='color:red;'>*</span>" + " </div>" + " </td>" + " </tr>" + " <tr>" + " <td>Email Address : </td>" + " <td>" + " <div class=\"input-group\">" + " <input type=\"text\" id=\"mailG\" value=\"" + general.getSiteMail() + "\" class=\"form-control\" >" + " <span class=\"input-group-addon\" style='color:red;'>*</span>" + " </div>" + " </td>" + " </tr>" + " <tr>" + " <td>About Us Description Footer :</td>" + " <td>" + " <textarea class=\"form-control\" id=\"footerG\" rows=\"7\" cols='70'>" + general.getAboutUsFooter() + "</textarea>" + " </td>" + " </tr>" + " <tr>" + " <td>About Us Description Main :</td>" + " <td>" + " <textarea class=\"form-control\" id=\"mainG\" rows=\"10\" cols='70'>" + general.getAboutUsMain() + "</textarea>" + " </td>" + " </tr>" + " <tr>" + " <td>Your Account Description : </td>" + " <td>" + " <textarea class=\"form-control\" id=\"usrDescG\" rows=\"7\" cols='70'>" + general.getUsrAcntDesc() + "</textarea>" + " </td>" + " </tr>"; s.close();/* ww w .ja va 2 s .com*/ response.getWriter().write(html); }
From source file:com.certus.actions.updateAccountAction.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { User u = (User) request.getSession(false).getAttribute("user"); if (u != null) { String name = request.getParameter("name1"); String email = request.getParameter("email1"); String tel = request.getParameter("telephone"); String address = request.getParameter("address"); String user_name = request.getParameter("username2"); String pass = request.getParameter("password2"); String agreed = request.getParameter("agreed"); BasicPasswordEncryptor encriptor = new BasicPasswordEncryptor(); Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); if (name != null && email != null && tel != null && address != null && user_name != null && pass != null && agreed != null) { response.getWriter().write("Worked"); String[] nameAry = name.split(" "); User usr = (User) s.load(User.class, u.getId()); s.beginTransaction();// w w w. j a va2 s .co m usr.setAddress(address); usr.setEmail(email); usr.setPassword(encriptor.encryptPassword(pass)); usr.setUserName(user_name); usr.setTelephone(tel); usr.setFName(nameAry[0]); usr.setLName(nameAry[1]); s.getTransaction().commit(); s.close(); response.sendRedirect("index.jsp"); } } }
From source file:com.certus.actions.updateBrndStatAction.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); s.beginTransaction();/* w w w. j a va2s .c om*/ Brand b = (Brand) s.load(Brand.class, Integer.parseInt(request.getParameter("bid"))); b.setAvailability(Boolean.valueOf(request.getParameter("stat"))); s.getTransaction().commit(); s.close(); response.getWriter().write("Updated"); }
From source file:com.certus.actions.updateCustomerByAdminAction.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); int uid = Integer.parseInt(request.getParameter("uid")); String uName = request.getParameter("uName"); String fName = request.getParameter("fName"); String lname = request.getParameter("lName"); String email = request.getParameter("email"); String tel = request.getParameter("tel"); String pass = request.getParameter("pass"); User usr = (User) s.load(User.class, uid); s.beginTransaction();//from w w w . j a v a2 s .com if (uName != null && fName != null && lname != null && email != null && tel != null && pass != null && !pass.isEmpty()) { usr.setUserName(uName); usr.setFName(fName); usr.setLName(lname); usr.setEmail(email); usr.setTelephone(tel); usr.setPassword(pass); s.update(usr); s.getTransaction().commit(); s.close(); response.getWriter().write("success"); } else if (uName != null && fName != null && lname != null && email != null && tel != null) { usr.setUserName(uName); usr.setFName(fName); usr.setLName(lname); usr.setEmail(email); usr.setTelephone(tel); s.update(usr); s.getTransaction().commit(); s.close(); response.getWriter().write("success"); } }
From source file:com.certus.actions.updateGenaralProAction.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getParameter("saveGen") != null) { int phs_id = Integer.parseInt(request.getParameter("phs_id")); int sid = Integer.parseInt(request.getParameter("sid")); boolean dis_o_en = Boolean.parseBoolean(request.getParameter("dis_o_en")); String pName = request.getParameter("pName"); String disc_short = request.getParameter("disc_short"); String disc_long = request.getParameter("disc_long"); int cat_sel_id = Integer.parseInt(request.getParameter("cat_sel")); int sub_cat_sel_id = Integer.parseInt(request.getParameter("sub_cat_sel")); int brnd_sel_id = Integer.parseInt(request.getParameter("brnd_sel")); double price = Double.parseDouble(request.getParameter("price")); Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); Brand b = (Brand) s.load(Brand.class, brnd_sel_id); SubCategory sub_category = (SubCategory) s.load(SubCategory.class, sub_cat_sel_id); Size size = (Size) s.load(Size.class, sid); Category category = (Category) s.load(Category.class, cat_sel_id); s.beginTransaction();/*www. j a va 2 s .c o m*/ ProductHasSize phs = (ProductHasSize) s.load(ProductHasSize.class, phs_id); phs.getProduct().setBrand(b); phs.getProduct().setSubCategory(sub_category); phs.setPrice(price); phs.setSize(size); phs.getProduct().getSubCategory().setCategory(category); phs.getProduct().setName(pName); phs.getProduct().setAvailability(dis_o_en); phs.getProduct().setDescription("<h5>" + disc_short + "</h5><p>" + disc_long + "</p>"); s.update(phs); s.getTransaction().commit(); int pid = phs.getProduct().getId(); s.close(); response.sendRedirect("edit_product.jsp?pid=" + pid + "&sid=" + sid); } }
From source file:com.certus.actions.updateOrderStatusAction.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); Order order = (Order) s.load(Order.class, Integer.parseInt(request.getParameter("oid"))); s.beginTransaction();//from ww w . j a va 2 s. c o m order.setStatus(request.getParameter("status")); s.update(order); s.getTransaction().commit(); if (request.getParameter("status").equals("Completed")) { s.beginTransaction(); Sales sale = new Sales(); sale.setDateDone(new Date(new java.util.Date().getTime())); sale.setDescription("Successfully Completed the order."); sale.setOrder(order); sale.setStatus("Completed"); sale.setGrandTotal(order.getGrandTot()); s.save(sale); s.getTransaction().commit(); s.close(); } response.getWriter().write("success"); }
From source file:com.certus.actions.updatePromotion.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String promoDes = request.getParameter("promoupdateDes"); String promoEnd = request.getParameter("promoupdateEnd"); int promoPlace = Integer.parseInt(request.getParameter("promoupdatePlace")); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); int pid = Integer.parseInt(request.getParameter("pid")); int sid = Integer.parseInt(request.getParameter("sid")); Date parsed = null;/*from w w w. ja v a 2 s .c o m*/ try { parsed = format.parse(promoEnd); } catch (ParseException ex) { Logger.getLogger(savePromotion.class.getName()).log(Level.SEVERE, null, ex); } Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); Promotions promo = (Promotions) s.load(Promotions.class, promoPlace); s.beginTransaction(); promo.setDateEnded(new java.sql.Date(parsed.getTime())); promo.setDescription(promoDes); s.update(promo); s.getTransaction().commit(); s.close(); response.sendRedirect("edit_product.jsp?pid=" + pid + "&sid=" + sid); }
From source file:com.certus.actions.updatePropertyAction.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getParameter("prop") != null && request.getParameter("desc") != null) { String propNew = request.getParameter("prop"); String descNew = request.getParameter("desc"); String propPre = request.getParameter("pre_prop"); String descPre = request.getParameter("pre_desc"); int pid = Integer.parseInt(request.getParameter("pid")); int sid = Integer.parseInt(request.getParameter("sid")); if (request.getParameter("updateBtn") != null) { Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); s.beginTransaction();//from w w w . ja va 2s . c o m Product p = (Product) s.load(Product.class, pid); String html = "<table>" + p.getSpecs() + "</table>"; Document doc = Jsoup.parse(html); Elements e = doc.select("td > strong:contains(" + propPre + ")"); e.html(e.html().replaceAll(propPre, propNew)); Elements e1 = doc.select("td:contains(" + descPre.replace("`", "\"") + ")"); e1.html(e1.html().replaceAll(descPre.replace("`", "\""), descNew.replace("`", "\""))); p.setSpecs(doc.body().select("table").html()); s.update(p); s.getTransaction().commit(); s.close(); response.sendRedirect("edit_product.jsp?pid=" + pid + "&sid=" + sid); } else if (request.getParameter("removeBtn") != null) { Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); s.beginTransaction(); Product p = (Product) s.load(Product.class, pid); String html = "<table>" + p.getSpecs() + "</table>"; Document doc = Jsoup.parse(html); Elements e = doc.select("td:contains(" + descPre.replace("`", "\"") + ")"); e.parents().first().remove(); p.setSpecs(doc.body().select("table").html()); s.update(p); s.getTransaction().commit(); s.close(); response.sendRedirect("edit_product.jsp?pid=" + pid + "&sid=" + sid); } } }