Example usage for org.hibernate Criteria list

List of usage examples for org.hibernate Criteria list

Introduction

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

Prototype

public List list() throws HibernateException;

Source Link

Document

Get the results.

Usage

From source file:getstate.java

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

    PrintWriter out = response.getWriter();

    try {
        SessionFactory sf = NewHibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        //            Transaction tr=ss.beginTransaction();

        Criteria cr = ss.createCriteria(StateMaster.class);
        ArrayList<StateMaster> stlist = (ArrayList<StateMaster>) cr.list();
        System.out.println("Size of State" + stlist.size());
        request.setAttribute("state", stlist);

        String id = request.getParameter("id");
        int i = Integer.parseInt(id);

        if (i == 1) {
            RequestDispatcher rd = request.getRequestDispatcher("customerregistration.jsp");
            rd.forward(request, response);
        } else if (i == 2) {

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

        else if (i == 3) {
            RequestDispatcher rd = request.getRequestDispatcher("property_add.jsp");
            rd.forward(request, response);
        }

        else if (i == 4) {

            Criteria cr2 = ss.createCriteria(AgentDetail.class);

            ArrayList<AgentDetail> adl = (ArrayList<AgentDetail>) cr2.list();

            if (!adl.isEmpty()) {
                request.setAttribute("adl", adl);

            }
            RequestDispatcher rd = request.getRequestDispatcher("agents.jsp");
            rd.forward(request, response);
        } else if (i == 5) {
            RequestDispatcher rd = request.getRequestDispatcher("customerprofile.jsp");
            rd.forward(request, response);
        } else if (i == 6) {
            RequestDispatcher rd = request.getRequestDispatcher("agentprofile.jsp");
            rd.forward(request, response);
        } else if (i == 7) {
            RequestDispatcher rd = request.getRequestDispatcher("trial_area.jsp");
            rd.forward(request, response);

        } else if (i == 8) {
            RequestDispatcher rd = request.getRequestDispatcher("analysis_search.jsp");
            rd.forward(request, response);
        } else if (i == 9) {
            Criteria cr3 = ss.createCriteria(PropDetail.class);

            ArrayList<PropDetail> pdl = (ArrayList<PropDetail>) cr3.list();

            if (!pdl.isEmpty()) {
                request.setAttribute("pdl", pdl);

            }

            RequestDispatcher rd = request.getRequestDispatcher("property_search_1.jsp");
            rd.forward(request, response);
        } else if (i == 10) {
            int pid = Integer.parseInt(request.getParameter("pid"));
            PropDetail pd = (PropDetail) ss.get(PropDetail.class, pid);
            request.setAttribute("pd", pd);
            RequestDispatcher rd = request.getRequestDispatcher("prop_update.jsp");
            rd.forward(request, response);
        }
    }

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

From source file:pruebitas.java

/**
 * @param args the command line arguments
 *//*  w  w w.  j  a v  a2  s  .  c  om*/
public static void main(String[] args) {

    Session session = HibernateUtil.getSessionFactory().openSession();
    Criteria crit = session.createCriteria(Asesinos.class);
    List<Asesinos> asesinosList = crit.list();
    for (Asesinos a : asesinosList)
        System.out.println(a.getTipoasesinato().getTipoasesinato());

}

From source file:analysis_criteria.java

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

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

        String prstate = request.getParameter("state");
        String prcity = request.getParameter("city");
        String prarea = request.getParameter("area");
        String ptype = request.getParameter("type");
        String pbhk = request.getParameter("bhk");
        String przip = "";

        System.out.println("bhk is" + pbhk);
        System.out.println("type is" + ptype);

        String state = "";
        Criteria cr = ss.createCriteria(StateMaster.class);
        cr.add(Restrictions.eq("sId", Integer.parseInt(prstate)));
        ArrayList<StateMaster> ar = (ArrayList<StateMaster>) cr.list();
        if (ar.isEmpty()) {

        } else {
            StateMaster sm = ar.get(0);
            state = sm.getSName();

        }

        String city = "";
        Criteria cr2 = ss.createCriteria(CityMaster.class);
        cr2.add(Restrictions.eq("cityId", Integer.parseInt(prcity)));
        ArrayList<CityMaster> ar2 = (ArrayList<CityMaster>) cr2.list();
        System.out.println("----------" + ar2.size());
        if (ar2.isEmpty()) {

        } else {
            city = ar2.get(0).getCityName();
            System.out.println("-------" + city);
        }

        String area = "";
        Criteria cr3 = ss.createCriteria(AreaMaster.class);
        cr3.add(Restrictions.eq("areaId", Integer.parseInt(prarea)));
        ArrayList<AreaMaster> ar3 = (ArrayList<AreaMaster>) cr3.list();
        System.out.println("----------" + ar3.size());
        if (ar3.isEmpty()) {

        } else {
            area = ar3.get(0).getAreaName();
            System.out.println("-------" + area);
        }

        Criteria cr4 = ss.createCriteria(AreaMaster.class);
        cr4.add(Restrictions.eq("areaId", Integer.parseInt(prarea)));
        ArrayList<AreaMaster> ar4 = (ArrayList<AreaMaster>) cr4.list();
        System.out.println("----------" + ar4.size());
        if (ar4.isEmpty()) {

        } else {
            przip = ar4.get(0).getZip();
            System.out.println("-------" + przip);
        }

        out.print("after object 0");

        //            
        //            String s="select * from the_asset_consultancy.Filter_criteria;";
        //            
        //            SQLQuery query=ss.createSQLQuery(s);
        //            List<Filtercriteria> l=query.list();
        //          
        Criteria cr5 = ss.createCriteria(Filtercriteria.class);

        ArrayList<Filtercriteria> l = (ArrayList<Filtercriteria>) cr5.list();

        Filtercriteria old = l.get(0);
        System.out.println("this is old cr id:" + old.getCrId());

        Filtercriteria f = new Filtercriteria();

        f.setCrId(old.getCrId());

        f.setArea(area);

        out.print("after object 1");

        f.setBhk(pbhk);
        f.setType(ptype);
        f.setZip(przip);

        ss.evict(old);
        ss.update(f);

        out.print("after object 2");
        tr.commit();
        out.print("after object 3");

        out.print("after object 4");

        //for trial 
        HadoopProcessingClass.Do_Process();
        RequestDispatcher rd = request.getRequestDispatcher("show_growthrate");
        rd.forward(request, response);

        //Original code
        //            RequestDispatcher rd = request.getRequestDispatcher("analysis_search.jsp");
        //            rd.forward(request, response);

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

From source file:BuscarPorNome.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//  w  w w  . java  2s  .co  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */

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

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

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

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

        for (Cliente c : resultado) {
            out.println("Cliente encontrado: ");
            out.println("nome: " + c.getNome());
            out.println("cpf: " + c.getCpf());
            out.println("");
        }

        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet BuscarPorNome</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet BuscarPorNome at " + request.getContextPath() + "</h1>");
        out.println("</body>");
        out.println("</html>");
    }
}

From source file:reg_serv_cust.java

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

        //out.println("1");
        String fn = request.getParameter("fname");
        String ln = request.getParameter("lname");
        String un = request.getParameter("uname");
        String stateid = request.getParameter("state");

        String cityid = request.getParameter("city");
        String areaid = request.getParameter("area");
        String e = request.getParameter("email");
        String num = request.getParameter("number");
        String p = request.getParameter("pwd");

        //out.print("2");
        //  out.print("ijhdi");
        SessionFactory sf = NewHibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        Transaction tr = ss.beginTransaction();

        //out.print("111");
        Login li = new Login();
        li.setUName(un);
        li.setPwd(p);
        li.setURole("customer");

        //    out.print("22");
        ss.save(li);

        // out.println("3");

        String state = "";
        Criteria cr = ss.createCriteria(StateMaster.class);
        cr.add(Restrictions.eq("sId", Integer.parseInt(stateid)));
        ArrayList<StateMaster> ar = (ArrayList<StateMaster>) cr.list();
        System.out.println("----------" + ar.size());
        if (ar.isEmpty()) {

        } else {
            state = ar.get(0).getSName();
            System.out.println("-------" + ar.get(0));
        }

        String city = "";
        Criteria cr2 = ss.createCriteria(CityMaster.class);
        cr2.add(Restrictions.eq("cityId", Integer.parseInt(cityid)));
        ArrayList<CityMaster> ar2 = (ArrayList<CityMaster>) cr2.list();
        System.out.println("----------" + ar2.size());
        if (ar2.isEmpty()) {

        } else {
            city = ar2.get(0).getCityName();
            System.out.println("-------" + city);
        }

        String area = "";
        Criteria cr3 = ss.createCriteria(AreaMaster.class);
        cr3.add(Restrictions.eq("areaId", Integer.parseInt(areaid)));
        ArrayList<AreaMaster> ar3 = (ArrayList<AreaMaster>) cr3.list();
        System.out.println("----------" + ar3.size());
        if (ar3.isEmpty()) {

        } else {
            area = ar3.get(0).getAreaName();
            System.out.println("-------" + area);
        }

        CustomerDetail cd = new CustomerDetail();
        cd.setUId(li);
        cd.setCFname(fn);
        cd.setCLname(ln);

        cd.setCState(state);
        cd.setCCity(city);
        cd.setCArea(area);

        cd.setCNum(num);
        cd.setCEmail(e);

        ss.save(cd);

        //  out.println("Customer Registered");

        /*
            else if(r.equals(strg2))
            {
                
        AgentDetail ad=new AgentDetail();
        ad.setUId(li);
        ad.setAFname(fn);
        ad.setALname(ln);
        ad.setANo(null);
        ad.setARating(null);
        ad.setAAddress(null);
        ad.setAEmail(e);
                
        ss.save(ad);
        out.println("Agent Registered");
                             
                          
            }
          */

        tr.commit();

        HttpSession session = request.getSession();
        session.setAttribute("user", li);

        RequestDispatcher rd = request.getRequestDispatcher("agent_home.jsp");
        rd.include(request, response);

        // out.println("Registration Complete");

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

From source file:ConsultaProduto.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//  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 ConsultaProduto</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet ConsultaProduto at " + request.getContextPath() + "</h1>");
        out.println("</body>");
        out.println("</html>");

        Session s = HibernateUtil.getSessionFactory().openSession();//conectar com o banco

        Criteria criterio = s.createCriteria(Produto.class);
        criterio.add(Restrictions.eq("nome", "azul")); //==> where nome_produ = azul

        List<Produto> resul = criterio.list();

        out.println("Produtos encontrado: <br>");

        for (Produto p : resul) {
            out.println("<br>Produto num: " + p.getIdentificador());
            out.println("<br>Cor: " + p.getNome());
            out.println("<br>Tipo: " + p.getFabricante());
        }
        s.close();

    }
}

From source file:show_growthrate.java

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

        double yeardiff = 0;
        double starty = 0;
        double finaly = 0;
        double startp = 0;
        double finalp = 0;
        double ratesum = 0;
        double agr = 0;

        get_growth g = new get_growth();
        SessionFactory sf = NewHibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        Transaction tr = ss.beginTransaction();

        Criteria cr = ss.createCriteria(AssetData.class);
        ArrayList<AssetData> list = (ArrayList<AssetData>) cr.list();
        System.out.println("list size" + list.size());
        double[] rate = new double[list.size()];
        AssetData[] adata = new AssetData[list.size()];

        for (int i = 0; i < list.size(); i++) {
            adata[i] = list.get(i);
            starty = Double.parseDouble(adata[i].getStartYear());
            System.out.println("start year:" + starty);

            finaly = Double.parseDouble(adata[i].getFinalYear());
            System.out.println("final year:" + finaly);
            yeardiff = finaly - starty;
            System.out.println("The year diff is" + yeardiff);

            startp = Double.parseDouble(adata[i].getStartPrice());
            System.out.println("The start price is" + startp);

            finalp = Double.parseDouble(adata[i].getFinalPrice());
            System.out.println("The end price is" + finalp);

            rate[i] = g.get_growthrate(startp, finalp, yeardiff);

            System.out.println("rate " + i + " is" + rate[i]);

            ratesum = ratesum + rate[i];

            System.out.println("The rate sum " + i + " is" + ratesum);

        }

        agr = ratesum / list.size();
        out.print("The average annual growth is " + agr + "%.");

        request.setAttribute("percent", agr);

        //recently done
        RequestDispatcher rd = request.getRequestDispatcher("percentage_js.jsp");
        //RequestDispatcher rd = request.getRequestDispatcher("analysis_search.jsp");

        rd.forward(request, response);

        tr.commit();
    } catch (HibernateException he) {
        System.out.println(he.getMessage());
    }
}

From source file:fetch_agentfeedback.java

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

    PrintWriter out = response.getWriter();
    HttpSession hs = request.getSession();
    try {

        AgentDetail ad = (AgentDetail) hs.getAttribute("agentobj");
        System.out.print("agent id is" + ad.getAId());
        SessionFactory sf = util.NewHibernateUtil.getSessionFactory();
        Session ss = sf.openSession();

        Criteria cr1 = ss.createCriteria(AgentFeedback.class);
        cr1.add(Restrictions.eq("aId", ad));
        ArrayList<AgentFeedback> afl = (ArrayList<AgentFeedback>) cr1.list();

        if (!afl.isEmpty()) {

            // HttpSession hs1=request.getSession();
            System.out.println(afl.size());
            System.out.println("inside the servlet else");
            System.out.println("inside the servlet else11");

            hs.setAttribute("afl", afl);
            System.out.println("inside the servlet else222");

        }

        else {
            System.out.println("no agent feedback found");
            ;
        }

        RequestDispatcher rd = request.getRequestDispatcher("agentdescription.jsp");
        System.out.println("forwarding");
        rd.forward(request, response);

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

From source file:prediction_sample.java

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

        System.out.println("before criteria");

        Criteria cr = ss.createCriteria(AssetData.class);
        System.out.println("before list");

        List<AssetData> asd = (List<AssetData>) cr.list();

        System.out.println("after list");

        double ip = Double.parseDouble(asd.get(0).getFinalPrice());
        double n = 2017 - (Double.parseDouble(asd.get(0).getFinalYear()));
        double r = 10;
        double x;
        x = 1 + (r / 100);

        double b;
        b = Math.pow(x, n);

        double fp = ip * b;
        out.printf("%.2f", fp);

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

From source file:view_pastsystemreport_bydoc.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from  www .  j ava2  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("docotr") != 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();
    }

}