List of usage examples for org.hibernate Session load
void load(Object object, Serializable id);
From source file:com.certus.actions.customerEnAction.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); int uid = Integer.parseInt(request.getParameter("uid")); User u = (User) s.load(User.class, uid); s.beginTransaction();//w w w .jav a2s .c o m if (Boolean.valueOf(request.getParameter("enable"))) { u.setAvailability(true); } else { u.setAvailability(false); } s.update(u); s.getTransaction().commit(); s.close(); response.getWriter().write("success"); }
From source file:com.certus.actions.deleteImageAction.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getParameter("imgId") != null && request.getParameter("path") != null) { Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); ProImg img = (ProImg) s.load(ProImg.class, Integer.parseInt(request.getParameter("imgId"))); File file = new File(request.getParameter("path") + "/" + img.getImage()); if (file.delete()) { s.beginTransaction();//from w w w . j a v a2 s .c o m s.delete(img); s.getTransaction().commit(); s.close(); response.getWriter().write("Deleted Successfully !"); } else { response.getWriter().write("Error"); } } }
From source file:com.certus.actions.emailValidateAdminAction.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String emiilOfAdmin = request.getParameter("email"); String resultMessage = ""; Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); if (emiilOfAdmin != null) { Administor admin = (Administor) s.createCriteria(Administor.class, "admin") .add(Restrictions.eq("admin.email", emiilOfAdmin)).uniqueResult(); if (admin != null) { EmailSettings es = (EmailSettings) s.load(EmailSettings.class, 1); try { String adminId = String.valueOf(admin.getId()); BasicPasswordEncryptor encript = new BasicPasswordEncryptor(); EmailUtility.sendEmail(es.getHost(), String.valueOf(es.getPort()), es.getUser(), es.getPassword(), admin.getEmail(), "Reset Password", "http://localhost:8080/ECommerceApp/resetPasswordAdmin.jsp?mdfk=" + encript.encryptPassword(adminId)); resultMessage = "The e-mail was sent successfully to your email account . Please Check it."; s.close();//from ww w. j a v a 2s .c om response.getWriter().write(resultMessage); } catch (MessagingException ex) { //Logger.getLogger(emailValidateAdminAction.class.getName()).log(Level.SEVERE, null, ex); response.setStatus(500); } } else { response.setStatus(500); } } }
From source file:com.certus.actions.getOrderInfoAction.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"))); String proIdArray[] = order.getProductIds().split(","); String qntiesArray[] = order.getQuantities().split(","); String sizeArray[] = order.getSizes().split(","); List<OrderInfo> oi = new ArrayList<>(); for (int i = 0; i < proIdArray.length; i++) { ProductHasSize phs = (ProductHasSize) s.createCriteria(ProductHasSize.class, "phs") .createAlias("phs.product", "product").createAlias("phs.size", "size") .add(Restrictions.eq("product.id", Integer.parseInt(proIdArray[i]))) .add(Restrictions.eq("size.sizeName", sizeArray[i])).uniqueResult(); oi.add(new OrderInfo(phs, Integer.parseInt(qntiesArray[i]))); }/*from w w w . j ava 2s .c o m*/ String html = ""; try { Context env = (Context) new InitialContext().lookup("java:comp/env"); String productsPath = (String) env.lookup("uploadpathproducts"); for (OrderInfo o : oi) { html += "<li class='media'>" + "<a class='pull-left' data-pg-collapsed>" + "<img class='media-object' src='" + productsPath + o.getPhs().getProduct().getImageMain() + "' width='100'>" + "</a>" + "<div class='media-body' data-pg-collapsed>" + "<h4 class='media-heading'>" + o.getPhs().getProduct().getName() + "</h4>" + "<p>Size : " + o.getPhs().getSize().getSizeName() + "</p>" + "<p>Quantity : " + o.getQnty() + "</p>" + "<p>Each Price : Rs. " + o.getPhs().getPrice() + "</p>" + "</div>" + "</li> "; } } catch (Exception e) { } response.getWriter().write(html); }
From source file:com.certus.actions.loadBrandProAction.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getParameter("bid") != null) { try {// ww w.ja v a 2 s .co m Context env = (Context) new InitialContext().lookup("java:comp/env"); String productsPath = (String) env.lookup("uploadpathproducts"); int bid = Integer.parseInt(request.getParameter("bid")); Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); Brand b = (Brand) s.load(Brand.class, bid); Set<Product> products = b.getProducts(); String html = ""; for (Product p : products) { html += "<li class='media'>" + "<a href='#' class='pull-left'>" + "<img class='media-object' src='" + productsPath + p.getImageMain() + "' width='100'>" + "</a>" + "<div class='media-body'>" + "<h4 class='media-heading'>" + p.getName() + " " + "<button id='" + p.getId() + "' class='btn btn-danger'>Edit</button>" + "</h4>" + p.getDescription() + "</div>" + "</li>"; } s.close(); response.getWriter().write(html); } catch (NamingException ex) { Logger.getLogger(loadBrandProAction.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.certus.actions.loadCatSubAction.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getParameter("cid") != null) { try {/*from w w w .j a va2s . co m*/ int cid = Integer.parseInt(request.getParameter("cid")); Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); Category cat = (Category) s.load(Category.class, cid); Set<SubCategory> subCategories = cat.getSubCategories(); String html = ""; for (SubCategory su : subCategories) { html += "<li class='media'>" + "<h4 class='media-heading'>" + su.getSubCategoryName().substring(0, 1).toUpperCase() + su.getSubCategoryName().substring(1) + "</h4>" + "</li>"; } s.close(); response.getWriter().write(html); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:com.certus.actions.loadOrdersDetailAction.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); if (request.getParameter("orders") != null) { List<Order> oList = new ArrayList<>(); char orderIds[] = request.getParameter("orders").toCharArray(); for (int i = 0; i < orderIds.length; i++) { int orderId = Integer.parseInt(String.valueOf(orderIds[i])); Order order = (Order) s.load(Order.class, orderId); oList.add(order);//from www.j a v a2s. c om } String html = ""; for (Order order : oList) { html += " <li class='media cusBoder'>" + " <h4 class='media-heading'>Order Id : " + order.getInvoNum() + "</h4>" + " <div class='media-body'>" + " <div class='row'>" + " <div class='col-md-8'>" + " <table class='spacer'>" + " <tr data-pg-collapsed>" + " <td><h4>Date Added:</h4></td>" + " <td>" + order.getDateOrdered() + "</td>" + " </tr>" + " <tr data-pg-collapsed>" + " <td><h4>Order Status :</h4></td>" + " <td>" + order.getStatus() + "</td>" + " </tr>" + " <tr data-pg-collapsed>" + " <td><h4>Order Total :</h4></td>" + " <td>Rs. " + order.getGrandTot() + "</td>" + " </tr>" + " <tr>" + " <td><h4>Telephone :</h4></td>" + " <td>" + order.getTel() + "</td>" + " </tr>" + " </table>" + " </div>" + " <div class='col-md-4' data-pg-collapsed>" + " <a href='edit_order.jsp?oid=" + order.getId() + "' class='btn btn-danger'>View Order</a>" + " </div>" + " </div>" + " </div>" + " </li>"; } s.close(); response.getWriter().write(html); } }
From source file:com.certus.actions.loadReviewsForProductAction.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); Product p = (Product) s.load(Product.class, Integer.parseInt(request.getParameter("pid"))); String html = ""; Set<Review> reviews = p.getReviews().stream().sorted(Comparator.comparing(d -> d.getDateComnt())) .collect(Collectors.toSet()); if (!reviews.isEmpty()) { for (Review r : reviews) { String aval = r.isAvailability() ? "btn-danger" : "btn-default"; String not_aval = r.isAvailability() ? "btn-default" : "btn-danger"; html += "<li class='list-group-item'>" + "<div class='row'>" + "<div class='col-md-10'>" + "<h4>" + r.getUser().getFName() + " " + r.getUser().getLName() + "</h4><small>" + r.getDateComnt() + "</small>" + "<p>" + r.getComment() + "</p>" + "</div>" + "<div class='col-md-2'>" + "<div class='btn-group btn-toggle'>" + "<button class='btn btn-xs " + aval + "' onclick='oNBtnClicked(" + r.getId() + "," + r.getProduct().getId() + ");' type='button'>Enable </button>" + "<button class='btn btn-xs " + not_aval + "' onclick='offBtnClicked(" + r.getId() + "," + r.getProduct().getId() + ");' type='button'>Disable</button>" + "</div>" + "</div>" + "</li> "; }/*from www . jav a 2 s . c om*/ s.close(); response.getWriter().write(html); } else { html = "<li class='list-group-item'>" + "<div class='row'>" + "<div class='col-md-12'>" + "<h3>No Reviews available for this product.</h3>" + "</div>" + "</div>" + "</li> "; response.getWriter().write(html); } }
From source file:com.certus.actions.loadSiteTermsAndConditionsAction.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String html = ""; Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); TermsConditions conditions = (TermsConditions) s.load(TermsConditions.class, 1); html += "<tr>" + " <td>Main Section : </td>" + " <td>" + " <textarea id=\"mainSec\" class=\"form-control\" rows=\"5\" cols='90'>" + conditions.getMainSec() + "</textarea>" + " </td>" + "</tr>" + "<tr>" + " <td>User Account, Password, and Security : </td>" + " <td>\n" + " <textarea id=\"securedSec\" class=\"form-control\" rows=\"5\" cols='90'>" + conditions.getSecuritySec() + "</textarea>" + " </td>" + "</tr>" + "<tr>" + " <td>Services Offered : </td>" + " <td>" + " <textarea id=\"serviceOff\" class=\"form-control\" rows=\"5\" cols='90'>" + conditions.getServiceOffered() + "</textarea>" + " </td>" + "</tr>" + "<tr>" + " <td>Privacy Policy : </td>" + " <td>" + " <textarea id=\"privcyPol\" class=\"form-control\" rows=\"5\" cols='90'>" + conditions.getPrivacyPolicy() + "</textarea>" + " </td>" + "</tr>" + "<tr>" + " <td>User Conduct and Rules : </td>" + " <td>" + " <textarea id=\"condRuls\" class=\"form-control\" rows=\"5\" cols='90'>" + conditions.getUsrCnductRules() + "</textarea>" + " </td>" + "</tr>" + "<tr>" + " <td>No Compensation Policy : </td>\n" + " <td>" + " <textarea id=\"comPolyT\" class=\"form-control\" rows=\"5\" cols='90'>" + conditions.getCompensationPolicy() + "</textarea>" + " </td>" + "</tr>" + "<tr>" + " <td>Exactness Not Guaranteed : </td>" + " <td>" + " <textarea id=\"extNotGurntT\" class=\"form-control\" rows=\"5\" cols='90'>" + conditions.getExtnessGrnteed() + "</textarea>" + " </td>" + "</tr>" + "<tr>" + " <td>Disclaimer Of Warranties/Limitation Of Liability : </td>" + " <td>" + " <textarea id=\"limitationT\" class=\"form-control\" rows=\"5\" cols='90'>" + conditions.getLimitationOfLiability() + "</textarea>" + " </td>" + "</tr>" + "<tr>" + " <td>Pricing : </td>" + " <td>" + " <textarea id=\"pricingT\" class=\"form-control\" rows=\"5\" cols='90'>" + conditions.getPricing() + "</textarea>" + " </td>" + "</tr>" + "<tr>" + " <td>Service Fees : </td>" + " <td>" + " <textarea id=\"serviceFeesT\" class=\"form-control\" rows=\"5\" cols='90'>" + conditions.getServiceFees() + "</textarea>" + " </td>" + "</tr>" + "<tr>" + " <td>Delivery : </td>" + " <td>" + " <textarea id=\"delivryT\" class=\"form-control\" rows=\"5\" cols='90'>" + conditions.getDelivery() + "</textarea>" + " </td>" + "</tr>"; s.close();//from w ww . j ava 2 s. c om response.getWriter().write(html); }
From source file:com.certus.actions.notificationViewAction.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getParameter("notId") != null && !request.getParameter("notId").isEmpty()) { int notId = Integer.parseInt(request.getParameter("notId")); Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); AdminNotifications notifications = (AdminNotifications) s.load(AdminNotifications.class, notId); s.beginTransaction();//w ww . j av a 2s. c o m notifications.setNotified(true); s.update(notifications); s.getTransaction().commit(); String html = ""; html += notifications.getMessage() + "<br/>" + notifications.getDate(); s.close(); response.getWriter().write(html); } }