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:getdoctor.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from  ww  w. j  a  v  a2s.  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();
        String code = "";

        Criteria cr = ss.createCriteria(Doctor.class);

        ArrayList<Doctor> all = (ArrayList<Doctor>) cr.list();

        Criteria cr1 = ss.createCriteria(Doctor.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("dFirstname"));
            } else if (so.equals("2")) {
                cr1.addOrder(Order.desc("dFirstname"));
            }
            //.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("dFirstname", so + "%"));
        }
        ArrayList<Doctor> all1 = (ArrayList<Doctor>) cr1.list();
        if (all1.size() > 0) {
            for (int i = 0; i < all1.size(); i++) {
                Doctor 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/doctor-2.jpg\" class=\"media-object news-img\">      \n"
                        + "                                    </div>\n"
                        + "                                    <div class=\"media-body\">\n"
                        + "                                        <h4 class=\"author-name\">Dr. "
                        + dd.getDFirstname() + " " + dd.getDLastname() + "</h4>\n"
                        + "                                        <span class=\"comments-date\"> "
                        + dd.getQualificationId().getQualificationName() + "</span>\n"
                        + "                                        <p>"
                        + dd.getAddressid().getCityId().getCityName().toString() + "</p>\n"
                        + "                                        <p class=\"fa fa-check-circle\" style=\"color: green\">"
                        + dd.getStatus() + "</p>\n"
                        + "                                        <div class=\"ui heart rating\" data-rating=\"1\" data-max-rating=\"3\"></div>\n"
                        + "                                        <a class=\"reply-btn\" href=\"take_doc_app?docid="
                        + dd.getDId() + "\">Take Appointment</a>\n"
                        + "                                    </div>\n"
                        + "                                </div>\n" + "                            </li>");
            }
        }
        //   request.setAttribute("dlist", all);

    } catch (HibernateException he) {

        he.getMessage();

    } finally {

        out.close();
    }
}

From source file:patient_view_labappointment.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w w w .  ja  va  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");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */
        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session ss = sf.getCurrentSession();
        Transaction tr = ss.beginTransaction();
        HttpSession hs = request.getSession();

        if (hs.getAttribute("patient") != null) {

            Patient p1 = (Patient) hs.getAttribute("patient");

            Criteria cr = ss.createCriteria(LabAppointment.class);
            cr.add(Restrictions.eq("pId", p1));
            ArrayList<LabAppointment> la = (ArrayList<LabAppointment>) cr.list();
            if (la.size() > 0) {
                ArrayList<ArrayList<PatienttestDetail>> testarray = new ArrayList<ArrayList<PatienttestDetail>>(
                        la.size());
                for (int i = 0; i < la.size(); i++) {
                    LabAppointment la1 = la.get(i);
                    Criteria cr1 = ss.createCriteria(PatienttestDetail.class);
                    cr1.add(Restrictions.eq("laId", la1));
                    ArrayList<PatienttestDetail> tests = (ArrayList<PatienttestDetail>) cr1.list();
                    testarray.add(tests);
                }
                request.setAttribute("la", la);
                if (testarray.size() > 0) {
                    request.setAttribute("ptest", testarray);
                }

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

From source file:TestGson.java

public static void main(String[] args) throws RemoteException {
    StaffDCO dco = new StaffDCO();
    Gson gson = new Gson();
    Session ses = utils.HibernateUtils.getSessionFactory().getCurrentSession();
    try {/* ww w.  j  a va 2 s.c  om*/
        ses.beginTransaction();
        Criteria crit = ses.createCriteria(Staff.class);
        crit.add(Restrictions.eq("id", 1));
        Staff s = (Staff) crit.uniqueResult();
        ses.getTransaction().commit();
        StaffBean bean = dco.toStaffBean(s);
        String v = gson.toJson(bean, StaffBean.class);
        System.out.println(v);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:admin_add_lab.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 {
        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("lId") != null) {

                int apid = Integer.parseInt(request.getParameter("lId"));
                Lab lab1 = (Lab) ss.get(Lab.class, apid);
                if (request.getParameter("status").equals("approve")) {

                    lab1.setStatus("ACTIVE");

                    ss.update(lab1);

                    String subject = "Your Appointment is Approved.!";
                    String content = "Hi," + lab1.getLabName() + " " + "\n"
                            + "Your Request has been approved by Admin" + ".\n";
                    String mail = lab1.getWebsite();

                    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")) {
                    lab1.setStatus("REJECTED");
                    ss.update(lab1);
                    String subject = "Your Request is Rejected.!";
                    String content = "Hi, " + lab1.getLabName() + " "
                            + "Your Request to join Cardiac Countermeasure has been rejected by admin"
                            + ".\n  ";
                    String mail = lab1.getWebsite();

                    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(Lab.class);
            //cr.add(Restrictions.eq("dId", a));
            cr.add(Restrictions.eq("status", "not Active"));
            ArrayList<Lab> da = (ArrayList<Lab>) cr.list();
            if (da.size() > 0) {
                request.setAttribute("da", da);
            }

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

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//  w  w w .  j  a  va2  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.getCurrentSession();
        Transaction tr = ss.beginTransaction();
        HttpSession hs = request.getSession();

        if (hs.getAttribute("patient") != null) {

            Patient p1 = (Patient) hs.getAttribute("patient");

            Criteria cr = ss.createCriteria(DoctorAppointment.class);
            cr.add(Restrictions.eq("pId", p1));
            ArrayList<DoctorAppointment> la = (ArrayList<DoctorAppointment>) cr.list();

            if (la.size() > 0) {

                ArrayList<DoctorAppointment> docarray = new ArrayList<DoctorAppointment>(la.size());

                // for (int i = 0; i < la.size(); i++) {
                //       DoctorAppointment da1 = la.get(i);
                //     Criteria cr1 = ss.createCriteria(DoctorAppointment.class);
                //   cr1.add(Restrictions.eq("daId", da1));
                // ArrayList<DoctorAppointment> tests = (ArrayList<DoctorAppointment>) cr1.list();
                // docarray.add(tests);

                //    }

                Criteria cr1 = ss.createCriteria(DoctorAppointment.class);
                cr1.add(Restrictions.eq("pId", la));

                request.setAttribute("la", la);
                if (docarray.size() > 0) {
                    request.setAttribute("ptest", docarray);
                }

                System.out.println(docarray);
            }
            RequestDispatcher rd = request.getRequestDispatcher("patient_view_doctorappointment.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:GetGroupChatServ.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   www .  j  a v a2 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();

        int gid = Integer.parseInt(request.getParameter("gid"));

        GroupDetail gd = (GroupDetail) ss.get(GroupDetail.class, gid);

        System.out.println("Group id is :" + gd.getGId());

        Criteria cr = ss.createCriteria(ChatMsg.class);
        cr.add(Restrictions.eq("gId", gd));
        cr.addOrder(Order.desc("cmid"));
        cr.setMaxResults(25);
        ArrayList<ChatMsg> cm = (ArrayList<ChatMsg>) cr.list();
        Collections.reverse(cm);

        System.out.println("size of the msg array :" + cm.size());
        request.setAttribute("msgs", cm);
        request.setAttribute("gobj", gd);

        RequestDispatcher rd = request.getRequestDispatcher("groupchat.jsp");
        rd.forward(request, response);

    } catch (HibernateException he) {
        System.out.print(he.getMessage());
    }
}

From source file:BuscarClientePorNome.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from  ww  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");
    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 BuscarClientePorNome</title>");
        out.println("</head>");
        out.println("<body>");

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

        Criteria criteria = sessao.createCriteria(Cliente.class);

        criteria.add(Restrictions.eq("nome", request.getParameter("nome")));

        List<Cliente> resultado = criteria.list();

        out.println("Cliente encontrado: ");
        for (Cliente c : resultado) {
            out.println("<br/>Nome: " + c.getNome());
            out.println("<br/>Cpf: " + c.getCpf());
            out.println("<br/>Endereco: " + c.getEndereco());
            out.println("<br/>");
        }

        out.println("</body>");
        out.println("</html>");
    }
}

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 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 {

        //            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.//from  ww  w . j a  v  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");
    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./*w ww . j a va 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();
        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();
    }
}