List of usage examples for org.hibernate Criteria list
public List list() throws HibernateException;
From source file:get_asset_records.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w . j av a2 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 { // this file is currently used no where. It is just for the purpose of // getting assetrecords with the help of id // SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); String id = "10"; Criteria cr = ss.createCriteria(AssetRecords.class); cr.add(Restrictions.eq("assetId", id)); ArrayList<AssetRecords> ar = (ArrayList<AssetRecords>) cr.list(); // Query q = ss.createQuery("From AssetRecords"); // List<AssetRecords> ar = q.list(); if (!ar.isEmpty()) { for (int i = 0; i < ar.size(); i++) { out.println(i + 1); out.println("year:" + ar.get(i).getYear()); out.println("price:" + ar.get(i).getPrice()); out.println(); } } else { out.print("empty"); } } catch (HibernateException e) { out.print(e.getMessage()); } }
From source file:getuser_bycity.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w ww.ja 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 { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); String city = ""; HttpSession hs = request.getSession(); Login ln = (Login) hs.getAttribute("user"); System.out.println(ln.getUName() + "is a " + ln.getURole()); switch (ln.getURole()) { case "agent": Criteria cr = ss.createCriteria(AgentDetail.class); cr.add(Restrictions.eq("uId", ln)); // / cr.add(Restrictions.ne(city, ln)) ArrayList<AgentDetail> ad = (ArrayList<AgentDetail>) cr.list(); city = ad.get(0).getACity(); break; case "customer": Criteria cr1 = ss.createCriteria(CustomerDetail.class); cr1.add(Restrictions.eq("uId", ln)); ArrayList<CustomerDetail> cd = (ArrayList<CustomerDetail>) cr1.list(); city = cd.get(0).getCCity(); break; default: System.out.println("No city"); } System.out.println(city + " is the city"); Criteria cr = ss.createCriteria(AgentDetail.class); cr.add(Restrictions.eq("aCity", city)); cr.add(Restrictions.ne("uId", ln)); ArrayList<AgentDetail> adl = (ArrayList<AgentDetail>) cr.list(); System.out.println("the size of agent aray is " + adl.size()); Criteria cr1 = ss.createCriteria(CustomerDetail.class); cr1.add(Restrictions.ne("uId", ln)); cr1.add(Restrictions.eq("cCity", city)); ArrayList<CustomerDetail> cdl = (ArrayList<CustomerDetail>) cr1.list(); System.out.println("the size of cust aray is " + cdl.size()); if (!adl.isEmpty() && !cdl.isEmpty()) { request.setAttribute("adl", adl); request.setAttribute("cdl", cdl); RequestDispatcher rd = request.getRequestDispatcher("creategroup.jsp"); rd.forward(request, response); } else if (!adl.isEmpty()) { request.setAttribute("adl", adl); RequestDispatcher rd = request.getRequestDispatcher("creategroup.jsp"); rd.forward(request, response); } else if (!cdl.isEmpty()) { request.setAttribute("cdl", cdl); RequestDispatcher rd = request.getRequestDispatcher("creategroup.jsp"); rd.forward(request, response); } else { String msg = "Sorry, there are no users from your city."; request.setAttribute("msg", msg); RequestDispatcher rd = request.getRequestDispatcher("creategroup.jsp"); rd.forward(request, response); } } catch (HibernateException e) { out.print(e.getMessage()); } }
From source file:past_systemreport.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* ww w . ja 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 { 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("patient") != null) { Patient a = (Patient) hs.getAttribute("patient"); int pid = a.getPId(); Calculationmeteredata cal = (Calculationmeteredata) ss.get(Calculationmeteredata.class, pid); Criteria cr = ss.createCriteria(Calculationmeteredata.class); cr.add(Restrictions.eq("pId", 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("patient_my_system_report.jsp"); rd.forward(request, response); } else { tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("login.jsp"); rd.forward(request, response); } } catch (HibernateException he) { out.println(he.getMessage()); } finally { out.close(); } }
From source file:ConsultaVinho.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w .j av a2s . 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"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ try { String vinho = request.getParameter("vinho"); Session s = HibernateUtil.getSessionFactory().openSession(); Criteria criteria = s.createCriteria(Vinho.class); criteria.add(Restrictions.eq("nome", vinho)); List<Vinho> result = criteria.list(); for (Vinho v : result) { out.println("<br>Vinho: " + v.getNome()); out.println("<br>Uva: " + v.getUva()); out.println("<br>Ano: " + v.getAno_safra()); out.println("<br>"); } s.close(); } catch (Exception e) { out.println("Erro na Busca " + e.getMessage()); } } }
From source file:take_test.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w ww .jav 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("patient") != null) { if (request.getParameter("labid") != null) { Patient p = (Patient) hs.getAttribute("patient"); int labid = Integer.parseInt(request.getParameter("labid")); Lab la = new Lab(labid); Criteria cr = ss.createCriteria(Labtest.class); cr.add(Restrictions.eq("lId", la)); ArrayList<Labtest> ltlist = (ArrayList<Labtest>) cr.list(); if (ltlist.size() > 0) { request.setAttribute("ltlist", ltlist); } tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("patient_labtest_takeappointment.jsp"); rd.forward(request, response); } else { tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("consult_lab.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:searchagent_byarea.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww .j a v a 2s . 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"); PrintWriter out = response.getWriter(); try { SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); String stateid = request.getParameter("state"); String cityid = request.getParameter("city"); String areaid = request.getParameter("area"); String aname = request.getParameter("aname"); String state = ""; Criteria cr = ss.createCriteria(StateMaster.class); cr.add(Restrictions.eq("sId", Integer.parseInt(stateid))); ArrayList<StateMaster> ar = (ArrayList<StateMaster>) cr.list(); System.out.println("----------" + ar.size()); if (ar.isEmpty()) { } else { state = ar.get(0).getSName(); System.out.println("-------" + state); } String city = ""; Criteria cr2 = ss.createCriteria(CityMaster.class); cr2.add(Restrictions.eq("cityId", Integer.parseInt(cityid))); ArrayList<CityMaster> ar2 = (ArrayList<CityMaster>) cr2.list(); System.out.println("----------" + ar2.size()); if (ar2.isEmpty()) { } else { city = ar2.get(0).getCityName(); System.out.println("-------" + city); } String area = ""; Criteria cr3 = ss.createCriteria(AreaMaster.class); cr3.add(Restrictions.eq("areaId", Integer.parseInt(areaid))); ArrayList<AreaMaster> ar3 = (ArrayList<AreaMaster>) cr3.list(); System.out.println("----------" + ar3.size()); if (ar3.isEmpty()) { } else { area = ar3.get(0).getAreaName(); System.out.println("-------" + area); } Criteria cr4 = ss.createCriteria(AgentDetail.class); cr4.add(Restrictions.eq("aState", state)); cr4.add(Restrictions.eq("aCity", city)); cr4.add(Restrictions.eq("aArea", area)); ArrayList<AgentDetail> ar4 = (ArrayList<AgentDetail>) cr4.list(); System.out.println("-------AgentList Size---" + ar4.size()); if (ar4.isEmpty()) { out.print("no such agent"); String msg = "Sorry, No results found."; request.setAttribute("error", msg); } else { request.setAttribute("agent_array", ar4); } RequestDispatcher rd = request.getRequestDispatcher("getstate?id=4"); rd.forward(request, response); tr.commit(); } catch (HibernateException e) { out.print(e.getMessage()); } }
From source file:login_serv.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww. j a v a2 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 { // Login li=new Login(); SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); Criteria cr = ss.createCriteria(Login.class); String uname = request.getParameter("username"); String pass = request.getParameter("psswd"); cr.add(Restrictions.eq("uName", uname)); cr.add(Restrictions.eq("pwd", pass)); ArrayList<Login> alli = (ArrayList<Login>) cr.list(); // out.println("jgfghfgh"); if (alli.isEmpty()) { String msg = "Invalid Username or Password."; request.setAttribute("error", msg); RequestDispatcher rd = request.getRequestDispatcher("/login.jsp"); rd.forward(request, response); } else { Login l = alli.get(0); HttpSession session = request.getSession(); session.setAttribute("user", l); //request.setAttribute("usname",uname); switch (l.getURole()) { case "customer": { RequestDispatcher rd = request.getRequestDispatcher("index.jsp"); rd.include(request, response); break; } case "agent": { Criteria cr1 = ss.createCriteria(AgentDetail.class); cr1.add(Restrictions.eq("uId", l)); ArrayList<AgentDetail> adl = (ArrayList<AgentDetail>) cr1.list(); AgentDetail ad = adl.get(0); if (ad.getAStatus().equals("Accepted")) { RequestDispatcher rd = request.getRequestDispatcher("index.jsp"); rd.include(request, response); } else if (ad.getAStatus().equals("Pending")) { String msg = "Your details are still being verified. Please try later."; request.setAttribute("error", msg); RequestDispatcher rd = request.getRequestDispatcher("/login.jsp"); rd.forward(request, response); } break; } case "admin": { RequestDispatcher rd = request.getRequestDispatcher("adminhome.jsp"); rd.include(request, response); break; } default: { RequestDispatcher rd = request.getRequestDispatcher("login.jsp"); rd.include(request, response); break; } } } // li=alli.get(0); tr.commit(); } catch (Exception e) { System.out.print(e.getMessage()); } }
From source file:getarea.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* ww w. ja v a 2s . 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 = NewHibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); int cityid = Integer.parseInt(request.getParameter("city")); //out.print(cityid); CityMaster cm = new CityMaster(); cm.setCityId(cityid); Criteria cr = ss.createCriteria(AreaMaster.class); cr.add(Restrictions.eq("cityId", cm)); // cr.add(Restrictions.eq("sId",sm)); ArrayList<AreaMaster> ctlist = (ArrayList<AreaMaster>) cr.list(); for (int i = 0; i < ctlist.size(); i++) { AreaMaster am = ctlist.get(i); String arname = am.getAreaName(); System.out.println("-------------getarea" + arname); System.out.println("------------- " + am.getAreaId()); out.print("<option value=" + am.getAreaId() + ">" + arname + "</option>"); } tr.commit(); ; } catch (HibernateException e) { out.print(e.getMessage()); } }
From source file:getgroups.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* ww w. j av a 2 s. 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"); PrintWriter out = response.getWriter(); HttpSession hs = request.getSession(); try { SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); Login ln = (Login) hs.getAttribute("user"); System.out.println(ln.getUName() + "is the user"); int id = Integer.parseInt(request.getParameter("id")); Criteria cr = ss.createCriteria(GmemberDetail.class); cr.add(Restrictions.eq("uId", ln)); ArrayList<GmemberDetail> gmdl = (ArrayList<GmemberDetail>) cr.list(); // ArrayList<GroupDetail> gdl1 = new ArrayList<>(); // for (GmemberDetail g : gmdl) { // // System.out.println(g.getGId()); // Criteria cr1 = ss.createCriteria(GroupDetail.class); // cr1.add(Restrictions.eq("gId", g.getGId().getGId())); // // GroupDetail gd = (GroupDetail) cr1.uniqueResult(); // gdl1.add(gd); // // } System.out.println("=====glist size=====" + gmdl.size()); request.setAttribute("grouplist", gmdl); if (id == 0) { RequestDispatcher rd = request.getRequestDispatcher("group_home.jsp"); rd.forward(request, response); } else if (id == 1) { int uid = Integer.parseInt(request.getParameter("uid")); request.setAttribute("uid", uid); RequestDispatcher rd = request.getRequestDispatcher("groupsofuser.jsp"); rd.forward(request, response); } } catch (HibernateException he) { out.print(he.getMessage()); } }
From source file:go_to_user.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w . j a va2 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 { PrintWriter out = response.getWriter(); try { String id = request.getParameter("id"); SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); Login l = (Login) ss.get(Login.class, Integer.parseInt(id)); System.out.println("uid is " + l.getUId()); switch (l.getURole()) { case "customer": { Criteria cr = ss.createCriteria(CustomerDetail.class); cr.add(Restrictions.eq("uId", l)); CustomerDetail cd = (CustomerDetail) cr.uniqueResult(); request.setAttribute("fname", cd.getCFname()); request.setAttribute("lname", cd.getCLname()); request.setAttribute("email", cd.getCEmail()); request.setAttribute("mobile", cd.getCNum()); RequestDispatcher rd = request.getRequestDispatcher("contact_customer.jsp"); rd.forward(request, response); break; } case "agent": { Criteria cr = ss.createCriteria(AgentDetail.class); cr.add(Restrictions.eq("uId", l)); AgentDetail ad = (AgentDetail) cr.uniqueResult(); Criteria cr1 = ss.createCriteria(AgentFeedback.class); cr1.add(Restrictions.eq("aId", ad)); ArrayList<AgentFeedback> afl = (ArrayList<AgentFeedback>) cr1.list(); request.setAttribute("ad", ad); if (!afl.isEmpty()) { request.setAttribute("afl", afl); } RequestDispatcher rd = request.getRequestDispatcher("agentdescription.jsp"); rd.forward(request, response); break; } } } catch (HibernateException he) { System.out.println(he.getMessage()); } }