List of usage examples for org.hibernate Criteria list
public List list() throws HibernateException;
From source file:viewTask.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* www. 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(); String path = ""; try { HttpSession hs = request.getSession(); SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); int userId = Integer.parseInt(hs.getAttribute("userId").toString()); String page = request.getParameter("page").toString(); LoginInfo user_id_to = new LoginInfo(); user_id_to.setUserId(userId); Criteria cr = ss.createCriteria(TaskDetails.class); cr.add(Restrictions.eq("userIdTo", user_id_to)); ArrayList<TaskDetails> TaskList = (ArrayList<TaskDetails>) cr.list(); System.out.println(TaskList.size()); int i = 0; UserInfo ui = null; Criteria cr1 = ss.createCriteria(UserInfo.class); ArrayList<UserInfo> uiList = new ArrayList<UserInfo>(); for (i = 0; i < TaskList.size(); i++) { cr1.add(Restrictions.eq("userId", TaskList.get(i).getUserIdFrom())); System.out.println("criteria " + i); ui = (UserInfo) cr1.list().get(0); uiList.add(ui); } request.setAttribute("TaskList", TaskList); request.setAttribute("uiList", uiList); request.setAttribute("page", page); path = "TaskList.jsp"; RequestDispatcher rd = request.getRequestDispatcher(path); rd.forward(request, response); } catch (Exception e) { path = "FailureDRO.jsp"; System.out.println(e.getMessage()); RequestDispatcher rd = request.getRequestDispatcher(path); rd.forward(request, response); } }
From source file:admin_add_doctors.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from www. j a va2s.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 = HibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); HttpSession hs = request.getSession(); if (hs.getAttribute("admin") != null) { Admin a = (Admin) hs.getAttribute("admin"); if (request.getParameter("status") != null && request.getParameter("dId") != null) { int apid = Integer.parseInt(request.getParameter("dId")); Doctor doc1 = (Doctor) ss.get(Doctor.class, apid); if (request.getParameter("status").equals("approve")) { doc1.setStatus("ACTIVE"); ss.update(doc1); String subject = "Your Appointment is Approved.!"; String content = "Hi, Dr." + doc1.getDFirstname() + " " + doc1.getDLastname() + "\n" + "Your Request has been approved by Admin" + ".\n"; String mail = doc1.getEmailId(); String[] recipients = new String[] { mail }; //String[] bccRecipients = new String[]{"sunilkotadiya777@gmail.com"}; if (new MailUtil().sendMail(recipients, subject, content)) { } request.setAttribute("msg", "Appointment accepted..!"); } else if (request.getParameter("status").equals("reject")) { doc1.setStatus("REJECTED"); ss.update(doc1); String subject = "Your Request is Rejected.!"; String content = "Hi, " + doc1.getDFirstname() + " " + doc1.getDLastname() + "Your Request to join Cardiac Countermeasure has been rejected by admin" + ".\n anil "; String mail = doc1.getEmailId(); String[] recipients = new String[] { mail }; //String[] bccRecipients = new String[]{"sunilkotadiya777@gmail.com"}; if (new MailUtil().sendMail(recipients, subject, content)) { } request.setAttribute("msg", "Appointment rejected..!"); } } Criteria cr = ss.createCriteria(Doctor.class); //cr.add(Restrictions.eq("dId", a)); cr.add(Restrictions.eq("status", "not_active")); ArrayList<Doctor> da = (ArrayList<Doctor>) cr.list(); if (da.size() > 0) { request.setAttribute("da", da); } tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("admin_add_doctors.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:consultarProfessor.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w. ja va2 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"); try (PrintWriter out = response.getWriter()) { Session sessao = HibernateUtil.getSessionFactory().openSession(); String nome = request.getParameter("nome"); String sobrenome = request.getParameter("sobrenome"); String disciplina = request.getParameter("disciplina"); Criteria c = sessao.createCriteria(Professor.class); if (nome != null && !nome.trim().equals("")) { c.add(Restrictions.eq("nome", nome)); } if (sobrenome != null && !sobrenome.trim().equals("")) { c.add(Restrictions.eq("sobrenome", sobrenome)); } if (disciplina != null && !disciplina.trim().equals("")) { c.add(Restrictions.eq("disciplina", disciplina)); } List<Professor> result = c.list(); if (result != null && result.size() > 0) { for (Professor prof : result) { out.println("<br><a href=\"formEditar?nome=" + prof.getNome() + "\">editar</a> : " + prof.getNome() + " " + prof.getSobrenome()); } } else { out.println("Nenhum resultado encontrado para esse criterio de busca: " + nome + "|" + sobrenome + "|" + disciplina); } } }
From source file:systemgeneratedreport.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w ww . ja v a2 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"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ SessionFactory sf = HibernateUtil.getSessionFactory(); Session ss = sf.openSession(); Transaction tr = ss.beginTransaction(); HttpSession hs = request.getSession(); if (hs.getAttribute("patient") != null) { Patient p1 = (Patient) hs.getAttribute("patient"); if (request.getParameter("calcid") != null) { int calcid = Integer.parseInt(request.getParameter("calcid")); Calculationmeteredata cm1 = (Calculationmeteredata) ss.get(Calculationmeteredata.class, calcid); String color = "red"; if (cm1.getCalculationmeteredataId() != null) { String gender = "MALE"; Criteria optcr = ss.createCriteria(PatientfactorAnswer.class); optcr.add(Restrictions.eq("calculationmeteredataId", cm1)); ArrayList<PatientfactorAnswer> anslist = (ArrayList<PatientfactorAnswer>) optcr.list(); if (anslist.size() > 0) { FactorOption agefac = new FactorOption(); for (PatientfactorAnswer opp : anslist) { if (opp.getFactorId().equals(new FactorDetails(1))) { if (opp.getFactorOptionId().getFoptionId().equals(16)) { gender = "FEMALE"; } System.out.println("Gender is :" + gender + opp.getFactorOptionId()); } if (opp.getFactorId().equals(new FactorDetails(2))) { agefac = opp.getFactorOptionId(); System.out.println("Age is :" + agefac.getFactorOption()); } } if (gender.equals("MALE")) { // Set Chart Data String[] chartdata = new String[4]; String[] rchartdata = new String[4]; Criteria cr01 = ss.createCriteria(AbsulateRiskMale.class); cr01.add(Restrictions.eq("foptionid", agefac)); cr01.setProjection(Projections.max("green")); if (cr01.uniqueResult() != null) { chartdata[0] = cr01.uniqueResult().toString(); int cdata = Integer.parseInt(chartdata[0]); if (cdata >= cm1.getMetervalue()) { color = "green"; } } Criteria cr02 = ss.createCriteria(AbsulateRiskMale.class); cr02.add(Restrictions.eq("foptionid", agefac)); cr02.setProjection(Projections.max("violet")); if (cr02.uniqueResult() != null) { chartdata[1] = cr02.uniqueResult().toString(); int cdata = Integer.parseInt(chartdata[1]); if (cdata >= cm1.getMetervalue()) { color = "violet"; } } System.out.println(chartdata[1]); System.out.println(color); Criteria cr03 = ss.createCriteria(AbsulateRiskMale.class); cr03.add(Restrictions.eq("foptionid", agefac)); cr03.setProjection(Projections.max("yellow")); if (cr03.uniqueResult() != null) { chartdata[2] = cr03.uniqueResult().toString(); int cdata = Integer.parseInt(chartdata[2]); if (cdata >= cm1.getMetervalue()) { color = "yellow"; } } chartdata[3] = "54"; // RchartData create Criteria cr010 = ss.createCriteria(AbsulateRiskMale.class); cr010.add(Restrictions.eq("foptionid", agefac)); cr010.setProjection(Projections.max("rGreen")); if (cr010.uniqueResult() != null) { rchartdata[0] = cr010.uniqueResult().toString(); } Criteria cr020 = ss.createCriteria(AbsulateRiskMale.class); cr020.add(Restrictions.eq("foptionid", agefac)); cr020.setProjection(Projections.max("rViolet")); if (cr020.uniqueResult() != null) { rchartdata[1] = cr020.uniqueResult().toString(); } System.out.println(chartdata[1]); System.out.println(color); Criteria cr030 = ss.createCriteria(AbsulateRiskMale.class); cr030.add(Restrictions.eq("foptionid", agefac)); cr030.setProjection(Projections.max("rYellow")); if (cr030.uniqueResult() != null) { rchartdata[2] = cr030.uniqueResult().toString(); } rchartdata[3] = "30"; request.setAttribute("rchartdata", rchartdata); request.setAttribute("chartdata", chartdata); } else if (gender.equals("FEMALE")) { // Set Chart Data String[] chartdata = new String[4]; String[] rchartdata = new String[4]; Criteria cr01 = ss.createCriteria(AbsoluteRiskFemale.class); cr01.add(Restrictions.eq("foptionid", agefac)); cr01.setProjection(Projections.max("green")); if (cr01.uniqueResult() != null) { chartdata[0] = cr01.uniqueResult().toString(); int cdata = Integer.parseInt(chartdata[0]); if (cdata >= cm1.getMetervalue()) { color = "green"; } } Criteria cr02 = ss.createCriteria(AbsoluteRiskFemale.class); cr02.add(Restrictions.eq("foptionid", agefac)); cr02.setProjection(Projections.max("violet")); if (cr02.uniqueResult() != null) { chartdata[1] = cr02.uniqueResult().toString(); int cdata = Integer.parseInt(chartdata[1]); if (cdata >= cm1.getMetervalue()) { color = "violet"; } } Criteria cr03 = ss.createCriteria(AbsoluteRiskFemale.class); cr03.add(Restrictions.eq("foptionid", agefac)); cr03.setProjection(Projections.max("yellow")); if (cr03.uniqueResult() != null) { chartdata[2] = cr03.uniqueResult().toString(); int cdata = Integer.parseInt(chartdata[2]); if (cdata >= cm1.getMetervalue()) { color = "yellow"; } } chartdata[3] = "30"; // RchartData create Criteria cr010 = ss.createCriteria(AbsoluteRiskFemale.class); cr010.add(Restrictions.eq("foptionid", agefac)); cr010.setProjection(Projections.max("rGreen")); if (cr010.uniqueResult() != null) { rchartdata[0] = cr010.uniqueResult().toString(); } Criteria cr020 = ss.createCriteria(AbsoluteRiskFemale.class); cr020.add(Restrictions.eq("foptionid", agefac)); cr020.setProjection(Projections.max("rViolet")); if (cr020.uniqueResult() != null) { rchartdata[1] = cr020.uniqueResult().toString(); } System.out.println(chartdata[1]); System.out.println(color); Criteria cr030 = ss.createCriteria(AbsoluteRiskFemale.class); cr030.add(Restrictions.eq("foptionid", agefac)); cr030.setProjection(Projections.max("rYellow")); if (cr030.uniqueResult() != null) { rchartdata[2] = cr030.uniqueResult().toString(); } rchartdata[3] = "20"; request.setAttribute("rchartdata", rchartdata); request.setAttribute("chartdata", chartdata); } Criteria testcr = ss.createCriteria(TestRecommend.class); testcr.add(Restrictions.eq("color", color)); ArrayList<TestRecommend> tlist = (ArrayList<TestRecommend>) testcr.list(); if (tlist.size() > 0) { request.setAttribute("testlist", tlist); } request.setAttribute("calcdata", cm1); request.setAttribute("anslist", anslist); } } tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("system_generated_report1.jsp"); rd.forward(request, response); } } else { tr.commit(); RequestDispatcher rd = request.getRequestDispatcher("login.jsp"); rd.forward(request, response); } } }
From source file:searchprop_byname.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* ww w .j a va 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(); String searchedprop = request.getParameter("propname"); Criteria cr = ss.createCriteria(PropDetail.class); cr.add(Restrictions.like("pName", "%" + searchedprop + "%")); ArrayList<PropDetail> pd = (ArrayList<PropDetail>) cr.list(); /* for(PropDetail p: pd) { out.print(p.getPId()+" type:"+p.getPType()+" bhk:"+p.getPBhk()); out.println(" "); } */ if (pd.isEmpty()) { out.print("no such property"); String msg = "Sorry, No results found."; request.setAttribute("error", msg); } else { request.setAttribute("proplist", pd); } RequestDispatcher rd = request.getRequestDispatcher("getstate?id=9"); rd.forward(request, response); } catch (Exception e) { out.println(e.getMessage()); } }
From source file:aa.PersonDog.dao.AbstractDao.java
protected List queryByExample(Object obj) { List objects = null;/* w ww . j av a 2 s .c om*/ try { startOperation(); // https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querycriteria.html // http://blog.caelum.com.br/simplifique-suas-consultas-com-o-query-by-example-do-hibernate/ Example ex = Example.create(obj).excludeZeroes() //exclude zero valued properties .ignoreCase() //perform case insensitive string comparisons .enableLike(MatchMode.ANYWHERE); //use like for string comparisons Criteria criteria = session.createCriteria(obj.getClass()).add(ex); objects = criteria.list(); commit(); } catch (HibernateException e) { handleException(e); } finally { HibernateFactory.close(session); } return objects; }
From source file:abid.password.springmvc.dao.UserDaoHibernateImpl.java
License:Apache License
@SuppressWarnings("unchecked") @Transactional(readOnly = true)/* ww w .jav a 2 s. c om*/ public List<User> getUsers() { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(User.class); List<User> userList = (List<User>) criteria.list(); return userList; }
From source file:abid.password.swing.dao.hibernate.AbstractHibernateDao.java
License:Apache License
@SuppressWarnings("unchecked") public List<T> getAll() { Session session = sessionFactory.openSession(); try {//from w w w . j a v a 2 s.c om Criteria criteria = session.createCriteria(persistentClass); List<T> list = (List<T>) criteria.list(); return list; } finally { session.close(); } }
From source file:abid.password.swing.dao.hibernate.AbstractHibernateDao.java
License:Apache License
@SuppressWarnings("unchecked") public List<T> get(int first, int fetchSize) { Session session = sessionFactory.openSession(); try {//w w w . j av a2 s. c om Criteria criteria = session.createCriteria(persistentClass); criteria.setFirstResult(first); criteria.setMaxResults(fetchSize); criteria.setFetchSize(fetchSize); criteria.setCacheable(true); List<T> dataList = (List<T>) criteria.list(); return dataList; } finally { session.close(); } }
From source file:abid.password.swing.dao.hibernate.AbstractHibernateDao.java
License:Apache License
@SuppressWarnings("unchecked") public List<T> getSorted(int first, int fetchSize, String propertyName, boolean ascending) { Session session = sessionFactory.openSession(); try {//from w w w. j a va 2 s . c o m Criteria criteria = session.createCriteria(persistentClass); criteria.setFirstResult(first); criteria.setMaxResults(fetchSize); criteria.setFetchSize(fetchSize); criteria.setCacheable(true); if (ascending) { criteria.addOrder(Order.asc(propertyName)); } else { criteria.addOrder(Order.desc(propertyName)); } List<T> dataList = (List<T>) criteria.list(); return dataList; } finally { session.close(); } }