Example usage for org.hibernate.criterion Restrictions eq

List of usage examples for org.hibernate.criterion Restrictions eq

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions eq.

Prototype

public static SimpleExpression eq(String propertyName, Object value) 

Source Link

Document

Apply an "equal" constraint to the named property

Usage

From source file:ConsultaIngrediente.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.// 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 {
    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 ing = request.getParameter("ing");

            Session s = HibernateUtil.getSessionFactory().openSession();

            Criteria criteria = s.createCriteria(Ingrediente.class);
            criteria.add(Restrictions.eq("nome", ing));

            List<Ingrediente> result = criteria.list();

            out.println("ingredientes encontrados (" + result.size() + "): <br>");

            for (Ingrediente i : result) {
                out.println("<br>Ingrediente:" + i.getNome());
                out.println("<br>Qtds :" + i.getQtd());
                out.println("<br>Valor :" + i.getValor());
                out.println("<br>");
            }

            s.close();
        } catch (Exception ex) {
            out.println("Erro na busca: " + ex.getMessage());
        }
    }
}

From source file:lab_view_approved_appointment.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  w ww. j a  v  a2 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 {
    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("lab") != null) {
            Lab a = (Lab) hs.getAttribute("lab");

            if (request.getParameter("status") != null && request.getParameter("appoid") != null) {

                int apid = Integer.parseInt(request.getParameter("appoid"));
                LabAppointment lab1 = (LabAppointment) ss.get(LabAppointment.class, apid);
                if (request.getParameter("status").equals("cancel")) {
                    lab1.setStatus("CANCELLED");
                    ss.update(lab1);
                    request.setAttribute("msg", "Appointment cancelled..!");
                } else if (request.getParameter("status").equals("update")) {
                    //                        doc1.setStatus("CANCELLED");
                    lab1.setDate(request.getParameter("apdate"));
                    lab1.setTime(request.getParameter("aptime"));
                    ss.update(lab1);
                    request.setAttribute("msg", "Appointment Updated..!");
                }

            }

            Criteria cr = ss.createCriteria(LabAppointment.class);
            cr.add(Restrictions.eq("lId", a));
            cr.add(Restrictions.eq("status", "APPROVED"));
            ArrayList<LabAppointment> da = (ArrayList<LabAppointment>) cr.list();
            if (da.size() > 0) {
                request.setAttribute("da", da);
            }

            tr.commit();
            RequestDispatcher rd = request.getRequestDispatcher("Lab_Approved_appointment.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:consultaEstrela.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   w  w  w.java2  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");
    try (PrintWriter out = response.getWriter()) {

        try {

            String Nome = request.getParameter("Nome");

            Session s = HibernateUtil.getSessionFactory().openSession();

            Criteria criteria = s.createCriteria(Estrela.class);
            criteria.add(Restrictions.eq("Nome", Nome));

            List<Estrela> result = criteria.list();

            out.println("Estrelas encontradas (" + result.size() + "): <br>");

            for (Estrela e : result) {
                out.println("<br>Estrela:" + e.getDistancia_da_Terra());
                out.println("<br>cor :" + e.getNome());
                out.println("<br>");
            }

            s.close();
        } catch (Exception ex) {
            out.println("Erro ao buscar estrelas: " + ex.getMessage());
        }
    }
}

From source file:ConsultaOcorrencia.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*w  w  w . j av  a  2s .  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");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet ConsultaOcorrencia</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet ConsultaOcorrencia at " + request.getContextPath() + "</h1>");
        out.println("</body>");
        out.println("</html>");

        Session s = HibernateUtil.getSessionFactory().openSession();

        Criteria criteria = s.createCriteria(Ocorrencia.class);
        criteria.add(Restrictions.eq("nome", "Hugo"));

        List<Ocorrencia> result = criteria.list();

        out.println("Ocorrencias encontradas: <br/>");
        for (Ocorrencia o : result) {
            out.println("Ocorrencia n: " + o.getNome());
        }

        s.close();

    }
}

From source file:doc_view_approved_appointment.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   w  w  w .j av  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("doctor") != null) {
            Doctor a = (Doctor) hs.getAttribute("doctor");

            if (request.getParameter("status") != null && request.getParameter("appoid") != null) {

                int apid = Integer.parseInt(request.getParameter("appoid"));
                DoctorAppointment doc1 = (DoctorAppointment) ss.get(DoctorAppointment.class, apid);
                if (request.getParameter("status").equals("cancel")) {
                    doc1.setStatus("CANCELLED");
                    ss.update(doc1);

                    String subject = "Appointment Canceled.!";
                    String content = "Hi, " + doc1.getPId().getPFirstname() + " "
                            + "Your appointment has been Canceled by Dr." + doc1.getDId().getDFirstname()
                            + " due to some reasons and we are sorry for that kindly take new appointment ASAP."
                            + ".\n ";
                    String mail = doc1.getPId().getEmailId();

                    String[] recipients = new String[] { mail };
                    //String[] bccRecipients = new String[]{"sunilkotadiya777@gmail.com"};  

                    if (new MailUtil().sendMail(recipients, subject, content)) {

                    }
                    request.setAttribute("msg", "Appointment cancelled..!");
                } else if (request.getParameter("status").equals("update")) {
                    //                        doc1.setStatus("CANCELLED");
                    doc1.setDate(request.getParameter("apdate"));
                    doc1.setTime(request.getParameter("aptime"));
                    ss.update(doc1);

                    String subject = "Appointment time changed.!";
                    String content = "Hi, " + doc1.getPId().getPFirstname() + " "
                            + "Your appointment has been rescheduled by Dr." + doc1.getDId().getDFirstname()
                            + " due to some reasons kindly note new time" + "  " + "Date : " + doc1.getDate()
                            + "\n" + "Time : " + doc1.getTime() + "\n";
                    String mail = doc1.getPId().getEmailId();

                    String[] recipients = new String[] { mail };
                    //String[] bccRecipients = new String[]{"sunilkotadiya777@gmail.com"};  

                    if (new MailUtil().sendMail(recipients, subject, content)) {

                    }
                    request.setAttribute("msg", "Appointment Updated..!");
                }

            }

            Criteria cr = ss.createCriteria(DoctorAppointment.class);
            cr.add(Restrictions.eq("dId", a));
            cr.add(Restrictions.eq("status", "APPROVED"));
            ArrayList<DoctorAppointment> da = (ArrayList<DoctorAppointment>) cr.list();
            if (da.size() > 0) {
                request.setAttribute("da", da);
            }

            tr.commit();
            RequestDispatcher rd = request.getRequestDispatcher("doc_approved_appointment.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:searchServ.java

public static SystemUser gameExists(String gameName) {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session session = sf.openSession();/*from   w  w w.j  a v a  2  s  .c  o m*/
    Criteria crit = session.createCriteria(WishListItem.class);
    Criterion cond1 = Restrictions.eq("title", gameName);
    crit.add(Restrictions.and(cond1));
    return (SystemUser) crit.uniqueResult();
}

From source file:lab_mytest.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*  ww w .jav  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");
    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("lab") != null) {
            Lab lb = (Lab) hs.getAttribute("lab");

            if (request.getParameter("price") != null && request.getParameter("ltid") != null) {
                int ltid = Integer.parseInt(request.getParameter("ltid"));
                Double price = Double.parseDouble(request.getParameter("price"));
                Labtest lt = (Labtest) ss.get(Labtest.class, ltid);
                lt.setTestFees(price);
                ss.update(lt);
                request.setAttribute("msg", "Test price updated.!");
            }

            Criteria cr = ss.createCriteria(Labtest.class);
            cr.add(Restrictions.eq("lId", lb));
            ArrayList<Labtest> ltest = (ArrayList<Labtest>) cr.list();
            if (ltest.size() > 0) {
                request.setAttribute("ltest", ltest);
            }
            tr.commit();
            RequestDispatcher rd = request.getRequestDispatcher("lab_mytest.jsp");
            rd.forward(request, response);

        } else {
            tr.commit();
            RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
            rd.forward(request, response);
        }

    }
}

From source file:get_lab_admin.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w  w  w.  j a v a  2 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 {
    response.setContentType("text/html;charset=UTF-8");

    PrintWriter out = response.getWriter();

    try {

        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        Transaction tr = ss.beginTransaction();
        String code = "";

        Criteria cr = ss.createCriteria(Lab.class);
        ArrayList<Lab> all = (ArrayList<Lab>) cr.list();

        Criteria cr1 = ss.createCriteria(Lab.class);
        cr1.add(Restrictions.eq("status", "ACTIVE"));
        if (request.getParameter("sort") != null) {
            String so = request.getParameter("sort");
            if (so.equals("1")) {
                cr1.addOrder(Order.asc("labName"));
            } else if (so.equals("2")) {
                cr1.addOrder(Order.desc("labName"));
            }
            //.add( Restrictions.like("name", "F%")
            //.addOrder( Order.asc("name") )
            //.addOrder( Order.desc("age") )
            //.setMaxResults(50)

            //                cr.add(Restrictions.eq("password", request.getParameter("password")));
        }
        if (request.getParameter("search") != null) {
            String so = request.getParameter("search");
            cr1.add(Restrictions.like("labName", so + "%"));
        }
        ArrayList<Lab> all1 = (ArrayList<Lab>) cr1.list();
        if (all1.size() > 0) {
            for (int i = 0; i < all1.size(); i++) {
                Lab dd = all1.get(i);
                out.println("<li class=\"author-comments\" style=\"margin-top: 36px\">\n"
                        + "                                <div class=\"media\">\n"
                        + "                                    <div class=\"media-left\">    \n"
                        + "                                        <img alt=\"img\" src=\"images/Lab-Icon-245x300.png\" class=\"media-object news-img\">      \n"
                        + "                                    </div>\n"
                        + "                                    <div class=\"media-body\">\n"
                        + "                                        <h4 class=\"author-name\">" + dd.getLabName()
                        + "</h4>\n" + "                                        <a target='_blank' href='http://"
                        + dd.getWebsite() + "'> <span class=\"comments-date\">" + dd.getWebsite()
                        + "</span> </a>\n" + "                                        <p>"
                        + dd.getAddressid().getCityId().getCityName() + "</p>\n"
                        + "                                        <p>" + dd.getStatus() + "</p>\n"
                        + "                                        <div class=\"ui heart rating\" data-rating=\"1\" data-max-rating=\"3\"></div>\n"
                        + "                                        <a class=\"reply-btn\" href=\"view_labprofile_admin?lid="
                        + dd.getLId() + "\">View Profile</a>\n" + "                                    </div>\n"
                        + "                                </div>\n" + "                            </li>");
            }

        }
        request.setAttribute("dlist", all);

    }

    catch (HibernateException he) {
        out.println(he.getMessage());
    } finally {
        out.close();
    }
}

From source file:ProjectList.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//  ww  w. j  a 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");
    String page = "null";
    PrintWriter out = response.getWriter();
    try {
        SessionFactory sf = NewHibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        Transaction tr = ss.beginTransaction();

        page = request.getParameter("page");
        request.getSession().setAttribute("page", page);

        String role = "", path = "ProjectList.jsp";
        Criteria cr = null;
        ArrayList<ProjectDetails> ProjectList = new ArrayList<ProjectDetails>();
        ArrayList<ProjectUserDetails> ProjectUserList = null;

        LoginInfo loginInfo = (LoginInfo) request.getSession().getAttribute("loginInfo");
        int userId = Integer.parseInt(request.getSession().getAttribute("userId").toString());
        role = request.getSession().getAttribute("role").toString();

        HttpServletRequest request1 = (HttpServletRequest) request;
        String uri = request1.getRequestURI();
        switch (role) {
        case "G":
            ProjectDetails pd = new ProjectDetails();
            cr = ss.createCriteria(ProjectDetails.class);
            cr.add(Restrictions.eq("userIdFrom", loginInfo));
            ProjectList = (ArrayList<ProjectDetails>) cr.list();
            //                    System.out.println(ProjectList.size());
            break;

        default:
            ProjectUserDetails pudDRO = new ProjectUserDetails();
            cr = ss.createCriteria(ProjectUserDetails.class);
            cr.add(Restrictions.eq("userIdTo", loginInfo));
            ProjectUserList = (ArrayList<ProjectUserDetails>) cr.list();
            //                    System.out.println(ProjectUserList.size());

            //                    ProjectDetails mineId;
            //                    ProjectDetails pd1;
            //                    for (int i = 1; i <= ProjectUserList.size(); i++) {
            //                         mineId=(ProjectDetails) ProjectUserList.get(i).getMineId();                         
            ////                         pd1 = new ProjectDetails();
            ////                         cr = ss.createCriteria(ProjectDetails.class);
            ////                         cr.add(Restrictions.eq("mineId", mineId));                           
            //                         ProjectList.set(i, mineId);
            //                    }
            for (ProjectUserDetails pud : ProjectUserList) {
                Criteria cr3 = ss.createCriteria(ProjectDetails.class);
                cr3.add(Restrictions.eq("mineId", pud.getMineId().getMineId()));
                ArrayList<ProjectDetails> pList = (ArrayList<ProjectDetails>) cr3.list();

                if (pList.size() != 0) {
                    ProjectList.add(pList.get(0));
                }

            }
            break;
        }

        tr.commit();
        HttpSession hs = request.getSession();
        hs.setAttribute("ProjectList", ProjectList);
        RequestDispatcher rd = request.getRequestDispatcher(path);
        rd.forward(request, response);

    } catch (Exception e) {
        out.println(e.getMessage());
    }
}

From source file:agentrequestlist_serv.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w  w  w .  ja v a  2  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 {
        SessionFactory sf = NewHibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        Transaction tr = ss.beginTransaction();
        String status = "Pending";

        Criteria cr = ss.createCriteria(AgentDetail.class);
        cr.add(Restrictions.eq("aStatus", status));
        ArrayList<AgentDetail> adl = (ArrayList<AgentDetail>) cr.list();

        if (!adl.isEmpty()) {
            request.setAttribute("adl", adl);
            RequestDispatcher rd = request.getRequestDispatcher("agentrequestlist.jsp");
            rd.forward(request, response);
        }

    } catch (HibernateException e) {
        out.print(e.getMessage());
    }
}