List of usage examples for org.hibernate Session load
void load(Object object, Serializable id);
From source file:com.certus.actions.updateProReviewStatsAction.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); Review r = (Review) s.load(Review.class, Integer.parseInt(request.getParameter("rid"))); s.beginTransaction();/*w w w. jav a2 s. c o m*/ r.setAvailability(Boolean.valueOf(request.getParameter("avl"))); s.update(r); s.getTransaction().commit(); s.close(); response.getWriter().write("updated"); }
From source file:com.certus.actions.updateProStatAction.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"))); s.beginTransaction();//from w w w . j a va 2 s . c om p.setAvailability(Boolean.valueOf(request.getParameter("stat"))); s.getTransaction().commit(); s.close(); response.getWriter().write("Updated"); }
From source file:com.certus.actions.updateSliderImageAction.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getParameter("pName") != null && request.getParameter("desc") != null && request.getParameter("img") != null && request.getParameter("sid") != null) { Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); String imgName = request.getParameter("img"); Product p = (Product) s.createCriteria(Product.class, "p") .add(Restrictions.eq("p.name", request.getParameter("pName").trim())).uniqueResult(); SliderFacts slf = (SliderFacts) s.load(SliderFacts.class, Integer.parseInt(request.getParameter("sid"))); s.beginTransaction();/*from w w w .j a v a2 s.c o m*/ slf.setDesc(request.getParameter("desc")); slf.setImage(imgName.substring(imgName.lastIndexOf("/"))); slf.setProduct(p); s.update(slf); s.getTransaction().commit(); s.close(); response.getWriter().write("success"); } }
From source file:com.certus.actions.uploadImageAction.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (MultipartFormDataRequest.isMultipartFormData(request)) { UploadBean bean = (UploadBean) request.getSession().getAttribute("upBean"); try {//from w ww. j a v a2s .c o m MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request); String todo = null; String brand = null; String pName = null; int pid = 0; int sid = 0; if (mrequest != null) { todo = mrequest.getParameter("todo"); brand = mrequest.getParameter("brnd"); pName = mrequest.getParameter("pName"); pid = Integer.parseInt(mrequest.getParameter("pid")); sid = Integer.parseInt(mrequest.getParameter("sid")); } if ((todo != null) && (todo.equalsIgnoreCase("upload"))) { Hashtable files = mrequest.getFiles(); if ((files != null) && (!files.isEmpty())) { UploadFile file = (UploadFile) files.get("uploadfile"); String fileType; String result; long fileSize; fileType = file.getContentType(); fileSize = file.getFileSize(); double randomA = Math.random() * 1000000000; int randA = (int) randomA; file.setFileName(brand + "-" + pName + "-" + randA + ".jpg"); if (fileType.equals("image/jpeg") || fileType.equals("image/png")) { if (fileSize <= 700000) { bean.store(mrequest, "uploadfile"); Session s = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); Product p = (Product) s.load(Product.class, pid); s.beginTransaction(); ProImg img = new ProImg(); img.setImage(file.getFileName()); img.setProduct(p); s.save(img); s.getTransaction().commit(); if (p.getImageMain() == null || p.getImageMain().isEmpty()) { s.beginTransaction(); p.setImageMain(file.getFileName()); s.update(p); s.getTransaction().commit(); } result = "File Uploaded with no errors..."; files.clear(); s.close(); response.sendRedirect("edit_product.jsp?pid=" + pid + "&sid=" + sid); } else { result = "Please Upload the file size of less than 700 KB"; } } else { result = "Please upload a filetype of image/jpeg or image/png"; } bean.store(mrequest, "uploadfile"); // response.sendRedirect("edit_product.jsp?pid=" + pid + "&sid=" + sid); } } } catch (UploadException ex) { Logger.getLogger(uploadImageAction.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.certus.actions.viewMsgAction.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("msg_id"))); String html = "<table>" + " <tr>" + " <td><h5>Customer Name : </h5> </td>" + " <td><h6>" + msg.getOrder().getUser().getFName() + " " + msg.getOrder().getUser().getLName() + "</h6></td>" + " </tr>" + " <tr>" + " <td><h5>Message :</h5> </td>" + " <td><h6>" + msg.getMessage() + "</h6></td>" + " </tr>" + " <tr>" + " <td><h5>Date Sent :</h5> </td>" + " <td><h6>" + msg.getDateSent() + "</h6></td>" + " </tr>" + "</table>"; s.close();/*from w w w . j a v a 2 s . c om*/ response.getWriter().write(html); }
From source file:com.certus.mobile.actions.mobileRecentItemsAction.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Session sess = com.certus.connection.HibernateUtil.getSessionFactory().openSession(); FilterRecentItems im = new FilterRecentItems(); String path = ""; try {/*from w ww . ja va 2s . c om*/ Context env1 = (Context) new InitialContext().lookup("java:comp/env"); path += (String) env1.lookup("uploadpathproducts"); } catch (Exception e) { e.printStackTrace(); } JsonArray ary = new JsonArray(); for (Integer i : im.getRecentItems()) { Product pr = (Product) sess.load(Product.class, i); if (pr.isAvailability()) { JsonObject jo = new JsonObject(); jo.add("pid", new JsonPrimitive(pr.getId())); jo.add("p_name", new JsonPrimitive(pr.getName())); jo.add("cat_id", new JsonPrimitive(pr.getSubCategory().getCategory().getId())); jo.add("subcat_id", new JsonPrimitive(pr.getSubCategory().getId())); jo.add("disc_Per", new JsonPrimitive(pr.getDiscountPrice())); jo.add("brand", new JsonPrimitive(pr.getBrand().getBrandName())); jo.add("image", new JsonPrimitive(path + pr.getImageMain())); ary.add(jo); // Product pl = new Gson().fromJson(jo, Product.class); } } String element = new Gson().toJson(ary); sess.close(); response.getWriter().write(element); }
From source file:com.controller.RegisterFacade.java
@Override public Register find(Object id) { Register myObject = null;//from ww w. ja va 2 s . c o m Transaction trs = null; Session session = getSessionFactory().openSession(); try { myObject = (Register) session.load(Register.class, new Integer((int) id)); } catch (RuntimeException e) { if (trs != null) { session.close(); return null; } } finally { session.flush(); session.close(); return myObject; } }
From source file:com.controllers.OrdersFacade.java
@Override public Orders find(Object id) { Orders myObject = null;//w ww . jav a 2 s .com Transaction trs = null; Session session = getSessionFactory().openSession(); try { myObject = (Orders) session.load(Orders.class, new Integer((int) id)); } catch (RuntimeException e) { if (trs != null) { session.close(); return null; } } finally { session.flush(); session.close(); return myObject; } }
From source file:com.cosw.productsmaster.main.Funciones.java
/** * Crea un nuevo pedido//from w ww . jav a 2 s . c o m * @param s La sesion * @param direccion La direccion del pedido * @param fecha La fecha de envio del pedido * @param idProductos Los productos que se van a aregistrar al pedido * @param cantidades Las cantidad de los producto que van a ser registrados * @return El valor total del pedido * @throws Exception En caso de que cantidaddes.length != idProductos */ public static int registroPedido(Session s, String direccion, Date fecha, int[] idProductos, int[] cantidades) throws Exception { if (idProductos.length != cantidades.length) throw new Exception("cantidades no corresponder al numero de productos a pedir"); int valorPedido = 0; Set<DetalleCompra> detallesCompra = new HashSet<>(); Pedido pedido = new Pedido(direccion, fecha, 0); int idPedido = (int) s.save(pedido); for (int i = 0; i < idProductos.length; i++) { int idProducto = idProductos[i]; DetalleCompraId idDetalle = new DetalleCompraId(idPedido, idProducto); Producto producto = (Producto) s.load(Producto.class, idProducto); valorPedido += cantidades[i] * producto.getPrecioLista(); DetalleCompra detalleCompra = new DetalleCompra(idDetalle, producto, cantidades[i], producto.getPrecioLista()); detallesCompra.add(detalleCompra); s.save(detalleCompra); } pedido.setDetalleCompras(detallesCompra); pedido.setValorTotal(valorPedido); s.update(pedido); return valorPedido; }
From source file:com.cosw.productsmaster.main.Funciones.java
/** * Registra un nuevo envio de los pedidos que llegan por parametro * @param s La sesion/*from w ww .j a v a 2 s . co m*/ * @param idPedidos El array de los id de los pedidos que van a ser asociados al pedido * @param idLugar El identificador del lugar donde inicialmente se encuentra el envio * @return El id del envio registrado */ public static int registroEnvio(Session s, int[] idPedidos, int idLugar, Date fechaSalida) { //FALTA VERIFICAR QUE LOS PEDIDOS QUE LLEGUEN POR PARAMETRO NO SE ENCUENTREN ACTUALMENTE EN UN ENVIO Envio e = new Envio(fechaSalida); Lugar l = (Lugar) s.load(Lugar.class, idLugar); EstadoEnvio ev = new EstadoEnvio(e, l, EstadoEnvio.OFICINA, "Este es un envio de prueba", "LATITUD:4248'47\"589_LONGITUD:138'52\"684"); e.getEstadoEnvios().add(ev); for (int i = 0; i < idPedidos.length; i++) { Pedido p = (Pedido) s.load(Pedido.class, idPedidos[i]); e.getPedidos().add(p); } s.save(e); return e.getIdEnvio(); }