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

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

    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("approve")) {

                    lab1.setStatus("APPROVED");
                    lab1.setDate(request.getParameter("apdate"));
                    lab1.setTime(request.getParameter("aptime"));
                    ss.update(lab1);

                    String subject = "Your Appointment is Approved.!";
                    PatienttestDetail pp = new PatienttestDetail();
                    String content = "Hi, " + lab1.getPId().getPFirstname() + "\n"
                            + "Your appointment has been approved by " + lab1.getLId().getLabName() + ".\n"
                            + "Date : " + lab1.getDate() + "\n" + "Time : " + lab1.getTime() + "\n";

                    String mail = lab1.getPId().getEmailId();

                    String[] recipients = new String[] { mail };

                    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 Appointment is Rejected.!";
                    String content = "Hi, " + lab1.getPId().getPFirstname() + " "
                            + "Your appointment has been rejected by " + lab1.getLId().getLabName()
                            + ".\n anil ";
                    String mail = lab1.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 rejected..!");

                }

            }

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

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

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*w  w  w . j av  a2s  .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("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("approve")) {

                    doc1.setStatus("APPROVED");
                    doc1.setDate(request.getParameter("apdate"));
                    doc1.setTime(request.getParameter("aptime"));
                    ss.update(doc1);

                    String subject = "Your Appointment is Approved.!";
                    String content = "Hi, " + doc1.getPId().getPFirstname() + "\n"
                            + "Your appointment has been approved by Dr." + doc1.getDId().getDFirstname()
                            + ".\n" + "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 accepted..!");

                } else if (request.getParameter("status").equals("reject")) {
                    doc1.setStatus("REJECTED");
                    ss.update(doc1);
                    String subject = "Your Appointment is Rejected.!";
                    String content = "Hi, " + doc1.getPId().getPFirstname() + " "
                            + "Your appointment has been rejected by Dr." + doc1.getDId().getDFirstname()
                            + ".\n anil ";
                    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 rejected..!");
                }

            }

            Criteria cr = ss.createCriteria(DoctorAppointment.class);
            cr.add(Restrictions.eq("dId", 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("doc_appointment_list.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:calculatefactorrisk.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  w w  w  .jav 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. */
        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");
            int metervalue = 0;
            double rmetervalue = 0;
            int facindex = 0;
            int points = 0;
            String[] chartdata = new String[4];
            chartdata[0] = "5";
            chartdata[1] = "12";
            chartdata[2] = "25";
            chartdata[3] = "60";
            ArrayList<PatientfactorAnswer> finalans = new ArrayList<PatientfactorAnswer>();

            if (request.getParameter("facindex") != null && request.getParameter("ans") != null) {

                if (hs.getAttribute("metervalue") != null) {
                    metervalue = (Integer) hs.getAttribute("metervalue");
                }
                if (hs.getAttribute("finalans") != null) {
                    finalans = (ArrayList<PatientfactorAnswer>) hs.getAttribute("finalans");
                }
                if (request.getParameter("ans").equals("15")) {
                    hs.setAttribute("gender", "MALE");
                    hs.setAttribute("agefactor", null);
                }
                if (request.getParameter("ans").equals("16")) {
                    hs.setAttribute("gender", "FEMALE");
                    hs.setAttribute("agefactor", null);
                }

                facindex = Integer.parseInt(request.getParameter("facindex"));
                if (request.getParameter("next") != null) {

                    int ansid = Integer.parseInt(request.getParameter("ans"));
                    FactorOption ansfo = (FactorOption) ss.get(FactorOption.class, ansid);
                    if (ansfo.getFactorId().equals(new FactorDetails(2))) {
                        hs.setAttribute("agefactor", ansfo);
                    }

                    PatientfactorAnswer currentans = new PatientfactorAnswer();
                    currentans.setFactorId(ansfo.getFactorId());
                    currentans.setFactorOptionId(ansfo);
                    currentans.setPId(p1);

                    if (finalans.size() > 0) {
                        ArrayList<PatientfactorAnswer> finalans1 = finalans;
                        for (int i1 = 0; i1 < finalans1.size(); i1++) {
                            PatientfactorAnswer c1 = finalans.get(i1);
                            if (c1.getFactorId().equals(currentans.getFactorId())) {
                                finalans.remove(i1);
                            }
                        }
                    }
                    finalans.add(facindex, currentans);

                    //                        System.out.println(finalans.get(0).getFactorOptionId());
                    //                        System.out.println(finalans.get(1).getFactorOptionId());
                    //                        System.out.println(finalans.get(2).getFactorOptionId());
                    System.out.println("size : " + finalans.size());
                    facindex = facindex + 1;
                } else if (request.getParameter("prev") != null) {
                    if (facindex > 0) {
                        facindex = facindex - 1;
                    }
                }

                if (finalans.size() > 0) {
                    String gender = "MALE";
                    if (hs.getAttribute("gender") != null) {
                        gender = (String) hs.getAttribute("gender");
                    }
                    if (gender.equals("MALE") && hs.getAttribute("agefactor") != null) {

                        FactorOption agefac = (FactorOption) hs.getAttribute("agefactor");

                        for (PatientfactorAnswer c1 : finalans) {
                            points = points + c1.getFactorOptionId().getMen();
                        }
                        if (points < 0) {
                            points = 0;
                        }
                        if (points > 14) {
                            points = 14;
                        }
                        //                Count risk on point
                        Criteria cr2 = ss.createCriteria(AbsulateRiskMale.class);
                        cr2.add(Restrictions.eq("foptionid", agefac));
                        cr2.add(Restrictions.eq("point", points));
                        ArrayList<AbsulateRiskMale> riskdata = (ArrayList<AbsulateRiskMale>) cr2.list();
                        if (riskdata.size() > 0) {
                            AbsulateRiskMale risk = riskdata.get(0);
                            if (risk.getGreen() != null) {
                                metervalue = risk.getGreen();
                            } else if (risk.getViolet() != null) {
                                metervalue = risk.getViolet();
                            } else if (risk.getYellow() != null) {
                                metervalue = risk.getYellow();
                            } else if (risk.getRed() != null) {
                                metervalue = risk.getRed();
                            }
                            if (risk.getRGreen() != null) {
                                rmetervalue = risk.getRGreen();
                            } else if (risk.getRViolet() != null) {
                                rmetervalue = risk.getRViolet();
                            } else if (risk.getRYellow() != null) {
                                rmetervalue = risk.getRYellow();
                            } else if (risk.getRRed() != null) {
                                rmetervalue = risk.getRRed();
                            }
                            //                                System.out.println("Risk data : " + risk);
                        }
                        System.out.println("Meter value : " + metervalue);
                        System.out.println("RMeter value : " + rmetervalue);
                        //                        Set Chart Data    
                        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();
                        }
                        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();
                        }
                        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();
                        }
                        chartdata[3] = "54";
                    }
                    if (gender.equals("FEMALE") && hs.getAttribute("agefactor") != null) {

                        FactorOption agefac = (FactorOption) hs.getAttribute("agefactor");

                        for (PatientfactorAnswer c1 : finalans) {
                            points = points + c1.getFactorOptionId().getWomen();
                        }
                        if (points < 0) {
                            points = 0;
                        }
                        if (points > 17) {
                            points = 17;
                        }
                        //                Count risk on point
                        Criteria cr2 = ss.createCriteria(AbsoluteRiskFemale.class);
                        cr2.add(Restrictions.eq("foptionid", agefac));
                        cr2.add(Restrictions.eq("point", points));
                        ArrayList<AbsoluteRiskFemale> riskdata = (ArrayList<AbsoluteRiskFemale>) cr2.list();
                        if (riskdata.size() > 0) {
                            AbsoluteRiskFemale risk = riskdata.get(0);
                            if (risk.getGreen() != null) {
                                metervalue = risk.getGreen();
                            } else if (risk.getViolet() != null) {
                                metervalue = risk.getViolet();
                            } else if (risk.getYellow() != null) {
                                metervalue = risk.getYellow();
                            } else if (risk.getRed() != null) {
                                metervalue = risk.getRed();
                            }
                            if (risk.getRGreen() != null) {
                                rmetervalue = risk.getRGreen();
                            } else if (risk.getRViolet() != null) {
                                rmetervalue = risk.getRViolet();
                            } else if (risk.getRYellow() != null) {
                                rmetervalue = risk.getRYellow();
                            } else if (risk.getRRed() != null) {
                                rmetervalue = risk.getRRed();
                            }
                            //                                System.out.println("Risk data : " + risk);
                        }
                        //                            System.out.println("Meter value : " + metervalue);
                        //                        Set Chart Data    
                        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();
                        }
                        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();
                        }
                        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();
                        }
                        chartdata[3] = "30";
                    }
                }

            }
            System.out.println("sssss : " + hs.getAttribute("agefactor"));
            Criteria cr = ss.createCriteria(FactorDetails.class);
            ArrayList<FactorDetails> fdlist = (ArrayList<FactorDetails>) cr.list();
            if (fdlist.size() > facindex) {
                FactorDetails factor = fdlist.get(facindex);

                Criteria cr1 = ss.createCriteria(FactorOption.class);
                cr1.add(Restrictions.eq("factorId", factor));
                ArrayList<FactorOption> folist = (ArrayList<FactorOption>) cr1.list();
                if (folist.size() > 0) {
                    request.setAttribute("folist", folist);
                }

                //                    metervalue = metervalue + 3;
                hs.setAttribute("metervalue", metervalue);
                hs.setAttribute("rmetervalue", rmetervalue);
                hs.setAttribute("points", points);
                hs.setAttribute("finalans", finalans);
                hs.setAttribute("chartdata", chartdata);
                request.setAttribute("factor", factor);
                request.setAttribute("facindex", facindex);

            } else {
                //                    Save In database final ans
                ArrayList<PatientfactorAnswer> save = (ArrayList<PatientfactorAnswer>) hs
                        .getAttribute("finalans");
                Calculationmeteredata cm = new Calculationmeteredata();

                cm.setFinalpoints((Integer) hs.getAttribute("points"));
                cm.setMetervalue((Integer) hs.getAttribute("metervalue"));
                cm.setRmetervalue((Double) hs.getAttribute("rmetervalue"));
                cm.setDate(new Date().toString());
                cm.setPId(p1);

                ss.save(cm);
                if (cm.getCalculationmeteredataId() != null) {
                    for (PatientfactorAnswer pans : save) {
                        pans.setCalculationmeteredataId(cm);
                        ss.save(pans);
                    }
                }
                tr.commit();
                RequestDispatcher rd = request.getRequestDispatcher(
                        "systemgeneratedreport?calcid=" + cm.getCalculationmeteredataId());
                rd.forward(request, response);
            }

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

    }
}

From source file:addnewtest.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//  w ww.  jav  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");
    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("tid") != null) {
                int tid = Integer.parseInt(request.getParameter("tid"));
                Double price = Double.parseDouble(request.getParameter("price"));
                Labtest lt = new Labtest();
                lt.setLId(lb);
                lt.setTId(new Test(tid));
                lt.setTestFees(price);
                ss.save(lt);
                request.setAttribute("msg", "Test added to your test list.!");
            }

            Criteria cr = ss.createCriteria(Test.class);
            ArrayList<Test> alltest = (ArrayList<Test>) cr.list();
            ArrayList<Test> alltest1 = alltest;
            if (alltest.size() > 0) {
                Criteria cr1 = ss.createCriteria(Labtest.class);
                cr1.add(Restrictions.eq("lId", lb));
                ArrayList<Labtest> ltest = (ArrayList<Labtest>) cr1.list();
                if (ltest.size() > 0) {
                    for (int i = 0; i < ltest.size(); i++) {
                        for (int j = 0; j < alltest.size(); j++) {
                            if (ltest.get(i).getTId().equals(alltest.get(j))) {
                                alltest1.remove(j);
                            }
                        }
                    }
                }
                request.setAttribute("alltest", alltest1);
            }
            tr.commit();
            RequestDispatcher rd = request.getRequestDispatcher("lab_addnewtest.jsp");
            rd.forward(request, response);

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

    }
}

From source file:LogServ.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   ww w.ja 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 {

        String path = "";

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

        Criteria cr = ss.createCriteria(Login.class);
        cr.add(Restrictions.eq("username", request.getParameter("username")));
        cr.add(Restrictions.eq("password", request.getParameter("password")));

        ArrayList<Login> all = (ArrayList<Login>) cr.list();
        Login l = all.get(0);
        String role = l.getRole();

        HttpSession hs = request.getSession();
        hs.setAttribute("l2", l);

        tr.commit();
        //                Login l1 = (Login)hs.getAttribute("l2");

        if (all.size() == 0) {

            path = "login.jsp";
            out.println("failed");

        } else {
            if (role.equals("patient")) {

                path = "patienthomepage.jsp";

            } else if (role.equals("doctor")) {

                Criteria cr1 = ss.createCriteria(Doctor.class);
                cr1.add(Restrictions.eq("userId", l));
                ArrayList<Doctor> dList = (ArrayList<Doctor>) cr1.list();
                Doctor d = dList.get(0);
                hs.setAttribute("doctor", d);
                path = "doctorhomepage.jsp";

            } else {
                Criteria cr1 = ss.createCriteria(Lab.class);
                cr1.add(Restrictions.eq("userId", l));
                ArrayList<Lab> lList = (ArrayList<Lab>) cr1.list();
                Lab L = lList.get(0);
                hs.setAttribute("lab", L);
                path = "Labhomepage.jsp";

            }

        }
        // out.println(role);
        // out.print(path);

        RequestDispatcher rd = request.getRequestDispatcher(path);
        rd.forward(request, response);

    }

    catch (HibernateException ex) {
        out.println(ex.getMessage());

    }

    finally {
        out.close();
    }
}

From source file:GetAgentDetailServ.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        SessionFactory sf = util.NewHibernateUtil.getSessionFactory();
        Session ss = sf.openSession();//  w w  w  . ja  v  a2 s.c  om

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

        Criteria cr = ss.createCriteria(AgentDetail.class);
        cr.add(Restrictions.eq("aId", aid));
        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);
        }

        System.out.println("the aid is " + ad.getAId());
        System.out.println("the uid is " + ad.getUId().getUId());

        Criteria cr2 = ss.createCriteria(PropDetail.class);
        cr2.add(Restrictions.eq("uId", ad.getUId()));
        ArrayList<PropDetail> pdl = (ArrayList<PropDetail>) cr2.list();

        if (!pdl.isEmpty()) {
            request.setAttribute("pdl", pdl);
        }
        System.out.println("the size of proplist is " + pdl.size());

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

    }
}

From source file:ConsultaPincel.java

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

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

            Criteria criteria = s.createCriteria(Pincel.class);
            criteria.add(Restrictions.eq("cor", cor));

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

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

            for (Pincel p : result) {
                out.println("<br>Pincel num:" + p.getNum_serie());
                out.println("<br>cor :" + p.getCor());
                out.println("<br>");
            }

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

From source file:writeblog.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from  w w w  .ja  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 = HibernateUtil.getSessionFactory();
        Session ss1 = sf.getCurrentSession();
        Transaction tr1 = ss1.getTransaction();
        tr1.begin();
        HttpSession hs = request.getSession();
        if (hs.getAttribute("doctor") != null) {

            Doctor pi = (Doctor) hs.getAttribute("doctor");

            if (request.getParameter("subject") != null && request.getParameter("content") != null) {

                String sub = request.getParameter("subject");
                String con = request.getParameter("content");
                request.setAttribute("msg", "Blog Created..!");
                Blog b = new Blog();
                if (request.getParameter("updateblogid") != null) {
                    b.setBlogId(Integer.parseInt(request.getParameter("updateblogid")));
                    request.setAttribute("msg", "Blog Updated..!");
                }
                b.setBlogname(sub);
                b.setBlogdescription(con);
                b.setDId(pi);
                b.setBlogView(20);
                b.setImageUrl("abc.jpg");
                b.setBlogDate(new Date().toString());
                ss1.saveOrUpdate(b);
            }

            if (request.getParameter("blogid") != null) {

                Blog b = (Blog) ss1.get(Blog.class, Integer.parseInt(request.getParameter("blogid")));
                request.setAttribute("editblog", b);
            }

            Criteria cr1 = ss1.createCriteria(Blog.class);
            cr1.add(Restrictions.eq("dId", pi));
            ArrayList<Blog> dblog = (ArrayList<Blog>) cr1.list();
            if (dblog.size() > 0) {
                request.setAttribute("dblog", dblog);
            }

            tr1.commit();
            RequestDispatcher rd = request.getRequestDispatcher("doctor_write_blog1.jsp");
            rd.forward(request, response);

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

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

From source file:TestClientWithTimestamps.java

License:BSD License

/**
 * This example demonstrates the use of Hibernate detached criteria objects
 * to formulate and perform more sophisticated searches. for more
 * information, please consult the Hibernate documentation at
 * http://www.hibernate.org/hib_docs/v3/api/org/hibernate/criterion/DetachedCriteria.html
 *///w ww.  ja v a 2s  . c  o  m
@SuppressWarnings("unused")
private static void searchSNPAnnoation() {
    DetachedCriteria criteria = DetachedCriteria.forClass(SNPAnnotation.class);
    criteria.add(Restrictions.ge("chromosomeLocation", new Integer(4000000)));
    criteria.add(Restrictions.le("chromosomeLocation", new Integer(4200000)));
    criteria.add(Restrictions.eq("chromosomeName", "1"));
    try {
        System.out.println("______________________________________________________________________");
        System.out.println("Retrieving all SNPAnnotations for Chr 1,4000000 - 4200000");
        ApplicationService appService = ApplicationServiceProvider.getApplicationService();

        List resultList = appService.query(criteria, SNPAnnotation.class.getName());
        if (resultList != null) {
            System.out.println("Number of results returned: " + resultList.size());
            System.out.println("DbsnpId" + "\t" + "ChromosomeName" + "\t" + "ChromosomeLocation" + "\t"
                    + "GenomeBuild" + "\t" + "ReferenceSequence" + "\t" + "ReferenceStrand" + "\t"
                    + "GeneBiomarker(s)" + "\n");
            for (Iterator resultsIterator = resultList.iterator(); resultsIterator.hasNext();) {
                SNPAnnotation returnedObj = (SNPAnnotation) resultsIterator.next();
                System.out.println(returnedObj.getDbsnpId() + "\t" + returnedObj.getChromosomeName() + "\t"
                        + returnedObj.getChromosomeLocation() + "\t" + returnedObj.getGenomeBuild() + "\t"
                        + returnedObj.getReferenceSequence() + "\t" + returnedObj.getReferenceStrand() + "\t"
                        + pipeGeneBiomarkers(returnedObj.getGeneBiomarkerCollection()) + "\n");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:TestClientWithTimestamps.java

License:BSD License

@SuppressWarnings({ "unused", "unchecked" })
private static void searchGeneBiomarker() {
    /*/*from  w  w w . j  av  a  2s . c o m*/
     * This example demonstrates the use of Hibernate detached criteria
     * objects to formulate and perform more sophisticated searches. A
     * detailed description of detached criteria is beyond the scope of this
     * example; for more information, please consult the Hibernate
     * documentation at
     * http://www.hibernate.org/hib_docs/v3/api/org/hibernate/criterion/DetachedCriteria.html
     */

    DetachedCriteria criteria = DetachedCriteria.forClass(GeneBiomarker.class);
    criteria.add(Restrictions.gt("startPhyscialLocation", new Long(6000000)));
    criteria.add(Restrictions.lt("endPhysicalLocation", new Long(6300000)));
    criteria.add(Restrictions.eq("chromosome", "19"));

    try {
        System.out.println("______________________________________________________________________");
        System.out.println("Retrieving all GeneBiomarker objects for Chr 19,6000000 - 6300000");
        ApplicationService appService = ApplicationServiceProvider.getApplicationService();

        List resultList = appService.query(criteria, GeneBiomarker.class.getName());
        if (resultList != null) {
            System.out.println("Number of results returned: " + resultList.size());
            System.out.println("ChromosomeName" + "\t" + "StartPhyscialLocation" + "\t" + "EndPhysicalLocation"
                    + "\t" + "HugoGeneSymbol" + "\n");
            for (Iterator resultsIterator = resultList.iterator(); resultsIterator.hasNext();) {
                GeneBiomarker returnedObj = (GeneBiomarker) resultsIterator.next();
                System.out.println(returnedObj.getChromosome() + "\t" + returnedObj.getStartPhyscialLocation()
                        + "\t" + returnedObj.getEndPhysicalLocation() + "\t" + returnedObj.getHugoGeneSymbol()
                        + "\n");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}