Example usage for org.hibernate Criteria setProjection

List of usage examples for org.hibernate Criteria setProjection

Introduction

In this page you can find the example usage for org.hibernate Criteria setProjection.

Prototype

public Criteria setProjection(Projection projection);

Source Link

Document

Used to specify that the query results will be a projection (scalar in nature).

Usage

From source file:calculatefactorrisk.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* w ww . ja  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");
    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:systemgen_report_doc.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*w  w w .  jav  a  2 s.  c  o m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    PrintWriter out = response.getWriter();
    try {
        /* 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("doctor") != 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("doctor_view_systemreport_full.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:systemgeneratedreport.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//  w w  w  .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");
    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:abid.password.swing.dao.hibernate.AbstractHibernateDao.java

License:Apache License

@SuppressWarnings("rawtypes")
public int countAll() {
    Session session = sessionFactory.openSession();
    try {//from  w  w w . j a v  a  2s .co m
        Criteria criteria = session.createCriteria(persistentClass);
        criteria.setProjection(Projections.rowCount());

        List result = criteria.list();
        Long rowCount = (Long) result.get(0);
        int count = rowCount.intValue();
        // return ( Long ) criteria.uniqueResult( );
        return count;
    } finally {
        session.close();
    }
}

From source file:abid.password.wicket.dao.AbstractHibernateDao.java

License:Apache License

@Transactional(type = TransactionType.READ_ONLY)
@SuppressWarnings("rawtypes")
public int countAll() {
    Criteria criteria = session.get().createCriteria(persistentClass);
    criteria.setProjection(Projections.rowCount());

    List result = criteria.list();
    Long rowCount = (Long) result.get(0);
    int count = rowCount.intValue();
    // return ( Long ) criteria.uniqueResult( );
    return count;

}

From source file:analysers.MarketValueAnalyser.java

License:Open Source License

public static void main(String[] args) throws ParseException {

    HibernateSupport.beginTransaction();
    Criteria cr = HibernateSupport.getCurrentSession().createCriteria(News.class);
    cr.createAlias("news_details", "details");
    cr.add(Restrictions.ge("details.total_objectivity", 0.5));
    cr.add(Restrictions.le("details.total_objectivity", 1.0));
    cr.setProjection(Projections.rowCount());
    long size = (long) cr.uniqueResult();
    HibernateSupport.commitTransaction();

    System.out.println("size = " + size);

    MarketValueAnalyser mva = new MarketValueAnalyser();
    //mva.createDistributionTable(40, 1, MarketValueAnalyser.Analyse.AFTER, false);
    mva.createDistributionTable(40, 3, MarketValueAnalyser.Analyse.AFTER, false);
    mva.createDistributionTable(40, 5, MarketValueAnalyser.Analyse.AFTER, false);
    mva.createDistributionTable(40, 7, MarketValueAnalyser.Analyse.AFTER, false);

    mva.createDistributionTable(40, 1, MarketValueAnalyser.Analyse.BEFORE, false);
    mva.createDistributionTable(40, 3, MarketValueAnalyser.Analyse.BEFORE, false);
    mva.createDistributionTable(40, 5, MarketValueAnalyser.Analyse.BEFORE, false);
    mva.createDistributionTable(40, 7, MarketValueAnalyser.Analyse.BEFORE, false);

}

From source file:apm.common.core.DaoImpl.java

License:Open Source License

/**
 * /*from   w  w w  .j  a  v a2  s .c o  m*/
 * @param detachedCriteria
 * @return
 */
@SuppressWarnings("rawtypes")
public long count(DetachedCriteria detachedCriteria) {
    Criteria criteria = detachedCriteria.getExecutableCriteria(getSession());
    long totalCount = 0;
    try {
        // Get orders
        Field field = CriteriaImpl.class.getDeclaredField("orderEntries");
        field.setAccessible(true);
        List orderEntrys = (List) field.get(criteria);
        // Remove orders
        field.set(criteria, new ArrayList());
        // Get count
        criteria.setProjection(Projections.rowCount());
        totalCount = Long.valueOf(criteria.uniqueResult().toString());
        // Clean count
        criteria.setProjection(null);
        // Restore orders
        field.set(criteria, orderEntrys);
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return totalCount;
}

From source file:au.edu.archer.dimsim.buffer.pool.impl.HibernateBuffer.java

License:Open Source License

public int getSize() {

    if (this.sessionFactory == null)
        return -1;

    Criteria criteria = this.sessionFactory.getCurrentSession().createCriteria(DimsimORMStore.class);
    criteria.setProjection(Projections.rowCount());

    return ((Integer) criteria.list().get(0)).intValue();
}

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

public long getArkModuleCount(ArkModule arkModuleCriteria) {
    Criteria criteria = buildArkModuleCriteria(arkModuleCriteria);
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    return totalCount;
}

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

public long getArkFunctionCount(ArkFunction arkFunctionCriteria) {
    Criteria criteria = buildArkFunctionCriteria(arkFunctionCriteria);
    criteria.setProjection(Projections.rowCount());
    Long totalCount = (Long) criteria.uniqueResult();
    return totalCount;
}