@Override public List<SmsProveedor> filtrarProveedor(String dato) { Session session = null; List<SmsProveedor> Proveedores = new ArrayList<>(); try { session = NewHibernateUtil.getSessionFactory().openSession(); Query query = session.createQuery( "from SmsProveedor as proveedor left join fetch proveedor.smsUsuario as usuario left join fetch usuario.smsCiudad as ciudad " + "where proveedor.proveedorValorGanancia LIKE '%" + dato + "%' OR usuario.usuarioNombre LIKE '%" + dato + "%' OR usuario.usuarioEmail LIKE '" + dato + "' OR usuario.usuarioNit LIKE '" + dato + "' OR " + "ciudad.ciudadNombre LIKE '" + dato + "'"); Proveedores = (List<SmsProveedor>) query.list(); } catch (HibernateException e) { e.getMessage(); } finally { if (session != null) { session.close(); } } return Proveedores; }
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * * @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 { String su = request.getParameter("subid"); int i = 1; Session s = NewHibernateUtil.getSessionFactory().openSession(); Transaction t = s.beginTransaction(); Criteria cr = s.createCriteria(Subject.class); cr.add(Restrictions.eq("idsubject", Integer.parseInt(su))); Subject sab = (Subject) cr.uniqueResult(); Subject subt = (Subject) s.load(Subject.class, sab.getIdsubject()); Criteria c = s.createCriteria(School.class); c.add(Restrictions.eq("subject", subt)); JSONArray json = new JSONArray(); Map m = new HashMap(); List<School> list = c.list(); for (School school : list) { m.put("schoolName", school.getSchoolName()); m.put("grade11", school.getGrade11()); m.put("grade10", school.getGrade10()); m.put("grade9", school.getGrade9()); m.put("subject", school.getSubject().getSubjectName()); json.add(m); m = null; m = new HashMap(); out.write(json.toJSONString()); // out.write("<tr>" + school.getSchoolName() + "</tr>"); // out.write("<tr>" + school.getGrade11() + "</tr>"); // out.write("<tr>" + school.getGrade10() + "</tr>"); // out.write("<tr>" + school.getGrade9() + "</tr>"); // out.write("<tr>" + school.getSubject().getSubjectName() + "</tr>"); } } catch (Exception e) { throw new ServletException(e); } }
@Override public void eliminarProveedor(SmsProveedor proveedor) { Session session = null; try { session = NewHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); session.delete(proveedor); session.getTransaction().commit(); } catch (HibernateException e) { e.getMessage(); session.getTransaction().rollback(); } finally { if (session != null) { session.close(); } } }
@Override public List<SmsProveedor> mostrarProveedores() { Session session = null; List<SmsProveedor> Proveedores = new ArrayList<>(); try { session = NewHibernateUtil.getSessionFactory().openSession(); Query query = session.createQuery( "from SmsProveedor as proveedor left join fetch proveedor.smsUsuario as usuario" + " left join fetch usuario.smsCiudad as ciudad left join fetch usuario.smsRols as roles"); Proveedores = (List<SmsProveedor>) query.list(); } catch (HibernateException e) { e.getMessage(); } finally { if (session != null) { session.close(); } } return Proveedores; }
@Override public List<SmsProveedor> consultarProveedorUsuario(SmsUsuario usuario) { Session session = null; List<SmsProveedor> Proveedores = new ArrayList<>(); try { session = NewHibernateUtil.getSessionFactory().openSession(); Query query = session.createQuery( "from SmsProveedor as proveedor left join fetch proveedor.smsUsuario as usuario where usuario.idUsuario = '" + usuario.getIdUsuario() + "'"); Proveedores = (List<SmsProveedor>) query.list(); } catch (HibernateException e) { e.getMessage(); } finally { if (session != null) { session.close(); } } return Proveedores; }
/** @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Session session = NewHibernateUtil.getSessionFactory().openSession(); }
public GenreHelper() { this.session = NewHibernateUtil.getSessionFactory().openSession(); }