Example usage for org.hibernate Query list

List of usage examples for org.hibernate Query list

Introduction

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

Prototype

List<R> list();

Source Link

Document

Return the query results as a List.

Usage

From source file:beans.NastavniciControler.java

public void dohvSveKurseve() {
    session = dbFactory.getFactory().openSession();
    Query q = session.createQuery("FROM Kurs");
    kurseviSvi = q.list();
    session.close();/*from   w  ww .j a va2s . com*/
}

From source file:Beans.PeliculaBeans.java

public void Ver() {

    Transaction t = null;//from   www.  ja v a 2s.  c o m

    try {
        t = session.beginTransaction();
        String consulta = "from Pelicula";
        Query query = session.createQuery(consulta);
        lista = query.list();

    } catch (HibernateException ex) {
        if (t != null) {
            t.rollback();
        }
    } finally {
        session.flush();
        session.close();
    }
}

From source file:beans.PredmetControler.java

public String ucitajPredmet(String nazivPredmeta) {
    session = dbFactory.getFactory().openSession();
    Query q = session.createQuery("FROM Kurs WHERE nazivKursa=:naz");
    q.setParameter("naz", nazivPredmeta);
    List<Kurs> result = q.list();
    session.close();/*  w  ww . j  av a  2  s. co  m*/
    if (result.size() > 0) {
        kurs = result.get(0);
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("kurs", kurs);

    } else {
        poruka = "Stranica predmeta je u izradi";
        return "informacijeKurs.xhtml";
    }

    session = dbFactory.getFactory().openSession();
    q = session.createQuery("FROM Obavestenje_kurs WHERE kurs=:k");
    q.setParameter("k", kurs.getIDKurs());
    listaObavestenja = q.list();
    session.close();

    List<Integer> idObavestenja = new ArrayList<Integer>();
    for (int i = 0; i < listaObavestenja.size(); i++) {
        idObavestenja.add(listaObavestenja.get(i).getObavestenje());
    }

    List<Obavestenje> obavestenjaSva = new ArrayList<Obavestenje>();
    session = dbFactory.getFactory().openSession();
    q = session.createQuery("FROM Obavestenje WHERE arhivirano=0");
    obavestenjaSva = q.list();
    session.close();

    for (int i = 0; i < idObavestenja.size(); i++) {
        for (int j = 0; j < obavestenjaSva.size(); j++) {
            if (idObavestenja.get(i) == obavestenjaSva.get(j).getIDObavestenja()) {
                obavestenja.add(obavestenjaSva.get(j));
            }
        }
    }

    FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("obavestenjaKurs", obavestenja);
    FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("kurs", kurs);

    petObavestenja.clear();
    ukupnoStrana = obavestenja.size() / 5;
    strana = 1;
    if (obavestenja.size() % 5 > 0) {
        ukupnoStrana++;
    }
    if (obavestenja.size() >= 5) {
        for (int i = 0; i < 5; i++) {
            petObavestenja.add(obavestenja.get(i));
        }
    } else {
        for (int i = 0; i < obavestenja.size(); i++) {
            petObavestenja.add(obavestenja.get(i));
        }
    }

    session = dbFactory.getFactory().openSession();
    q = session.createQuery("FROM Kurs_stavke WHERE kurs=:id");
    q.setParameter("id", kurs.getIDKurs());
    stavkeMenija = q.list();
    session.close();

    Korisnik kor = (Korisnik) FacesContext.getCurrentInstance().getExternalContext().getSessionMap()
            .get("korisnik");
    session = dbFactory.getFactory().openSession();
    q = session.createQuery("FROM Predavac_kurs WHERE predavac=:p");
    q.setParameter("p", kor.getIDKor());
    List<Predavac_kurs> pk = q.list();
    session.close();

    if (pk.size() > 0) {
        for (int i = 0; i < pk.size(); i++) {
            if (pk.get(i).getKurs() == kurs.getIDKurs()) {
                flagPredaje = true;
                break;
            }
        }
    }

    return "kurs_index.xhtml";
}

From source file:beans.PredmetControler.java

public void pretraziObavestenja(ValueChangeEvent e) {

    if (e.getNewValue() != null) {
        List<Obavestenje> obavestenjaKurs = new ArrayList<Obavestenje>();
        if (e.getNewValue().equals("sve")) {
            petObavestenja.clear();//from  w  w  w . ja v  a2 s . c o m
            obavestenjaKurs = (List<Obavestenje>) FacesContext.getCurrentInstance().getExternalContext()
                    .getSessionMap().get("obavestenjaKurs");
        } else {
            petObavestenja.clear();
            List<Obavestenje> obavestenjaTemp = (List<Obavestenje>) FacesContext.getCurrentInstance()
                    .getExternalContext().getSessionMap().get("obavestenjaKurs");
            for (int i = 0; i < obavestenjaTemp.size(); i++) {
                if (obavestenjaTemp.get(i).getTip().equals(e.getNewValue())) {
                    obavestenjaKurs.add(obavestenjaTemp.get(i));
                }
            }
        }
        if (obavestenjaKurs.size() > 0) {
            ukupnoStrana = obavestenjaKurs.size() / 5;
        } else {
            ukupnoStrana = 1;
        }
        strana = 1;
        if (obavestenjaKurs.size() % 5 > 0) {
            ukupnoStrana++;
        }
        if (obavestenjaKurs.size() >= 5) {
            for (int i = 0; i < 5; i++) {
                petObavestenja.add(obavestenjaKurs.get(i));
            }
        } else {
            for (int i = 0; i < obavestenjaKurs.size(); i++) {
                petObavestenja.add(obavestenjaKurs.get(i));
            }
        }

        Kurs k = (Kurs) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("kurs");

        session = dbFactory.getFactory().openSession();
        Query q = session.createQuery("FROM Kurs_stavke WHERE kurs=:id");
        q.setParameter("id", k.getIDKurs());
        stavkeMenija = q.list();
        session.close();

    }
}

From source file:beans.PredmetControler.java

public void promeniStranu(ValueChangeEvent e) {
    List<Obavestenje> obavestenjaKurs = new ArrayList<Obavestenje>();
    if (tipObavestenja == null || tipObavestenja.equals("") || tipObavestenja.equals("sve")) {
        obavestenjaKurs = (List<Obavestenje>) FacesContext.getCurrentInstance().getExternalContext()
                .getSessionMap().get("obavestenjaKurs");
    } else {//from  w  ww  . j ava 2  s  .c  om
        List<Obavestenje> obavestenjaTemp = (List<Obavestenje>) FacesContext.getCurrentInstance()
                .getExternalContext().getSessionMap().get("obavestenjaKurs");
        for (int i = 0; i < obavestenjaTemp.size(); i++) {
            if (obavestenjaTemp.get(i).getTip().equals(e.getNewValue())) {
                obavestenjaKurs.add(obavestenjaTemp.get(i));
            }
        }
    }
    petObavestenja.clear();
    strana = (int) e.getNewValue();
    if (strana < ukupnoStrana) {
        for (int i = (strana * 5) - 5; i < (strana * 5); i++) {
            petObavestenja.add(obavestenjaKurs.get(i));
        }
    } else {
        for (int i = (strana * 5) - 5; i < obavestenjaKurs.size(); i++) {
            petObavestenja.add(obavestenjaKurs.get(i));
        }
    }

    Kurs k = (Kurs) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("kurs");
    session = dbFactory.getFactory().openSession();
    Query q = session.createQuery("FROM Kurs_stavke WHERE kurs=:id");
    q.setParameter("id", k.getIDKurs());
    stavkeMenija = q.list();
    session.close();

}

From source file:beans.PredmetControler.java

public String materijali() {
    Kurs k = (Kurs) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("kurs");
    session = dbFactory.getFactory().openSession();
    Query q = session.createQuery("FROM Materijal WHERE kurs=:id");
    q.setParameter("id", k.getIDKurs());
    materijali = q.list();
    session.close();//from w  w w  .  j  a v a2s  .  co m

    for (int i = 0; i < materijali.size(); i++) {
        if (materijali.get(i).getTip().equals("predavanja")) {
            materijaliPredavanja.add(materijali.get(i));
        } else {
            materijaliVezbe.add(materijali.get(i));
        }
    }

    return "kurs_materijali.xhtml";
}

From source file:beans.PredmetControler.java

public void ucitajMaterijale() {
    Kurs k = (Kurs) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("kurs");
    session = dbFactory.getFactory().openSession();
    Query q = session.createQuery("FROM Materijal WHERE kurs=:id");
    q.setParameter("id", k.getIDKurs());
    materijali = q.list();
    session.close();/*  ww w  .ja v a  2  s  . com*/

    for (int i = 0; i < materijali.size(); i++) {
        if (materijali.get(i).getTip().equals("predavanja")) {
            materijaliPredavanja.add(materijali.get(i));
        } else {
            materijaliVezbe.add(materijali.get(i));
        }
    }
}

From source file:beans.PredmetControler.java

public void dodajObavestenje() {

    Korisnik kor = (Korisnik) FacesContext.getCurrentInstance().getExternalContext().getSessionMap()
            .get("korisnik");
    Kurs kursTekuci = (Kurs) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("kurs");
    session = dbFactory.getFactory().openSession();

    Query q = session.createQuery("SELECT naziv FROM Obavestenje WHERE naziv=:naz");
    q.setParameter("naz", obavestenjeNovo.getNaziv());
    List results = q.list();

    long vreme = System.currentTimeMillis();

    Calendar datum = Calendar.getInstance();
    datum.setTimeInMillis(vreme);/*from   www .j a v a2  s .  c  om*/

    if (results.size() > 0) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,
                "Obavetenje sa istim nazivom ve postoji", ""));
        session.close();
        return;
    } else {
        session.beginTransaction();
        obavestenjeNovo.setDatum(datum);
        session.save(obavestenjeNovo);
        session.getTransaction().commit();
        session.close();

        session = dbFactory.getFactory().openSession();
        q = session.createQuery("FROM Obavestenje");
        List<Obavestenje> temp = q.list();
        session.close();
        int idObavestenje;
        if (temp.size() > 0) {
            idObavestenje = temp.get(temp.size() - 1).getIDObavestenja();
            Obavestenje_kurs ok = new Obavestenje_kurs();

            //                session = dbFactory.getFactory().openSession();
            //                q = session.createQuery("FROM Kurs WHERE nazivKursa=:naz");
            //                q.setParameter("naz", kurs.getNazivKursa());
            //                List<Kurs> tempKurs = q.list();
            //                Kurs k = new Kurs();
            //                if (tempKurs.size() > 0) {
            //                    k = tempKurs.get(0);
            //                }
            //                session.close();
            ok.setKurs(kursTekuci.getIDKurs());
            ok.setObavestenje(idObavestenje);
            session = dbFactory.getFactory().openSession();
            session.beginTransaction();
            session.save(ok);
            session.getTransaction().commit();
            session.close();
        }
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,
                "Obavetenje je uspeno dodato, moete ga videti na stranici predmeta", ""));

    }
}

From source file:benchmark.BenchmarkHnP.java

License:Apache License

/** Create database and using SELECT */
@SuppressWarnings("unchecked")
public void useSingleSelect() {

    long time1 = System.currentTimeMillis();
    Transaction tr = session.beginTransaction();

    String hql = "from HbmOrderItem where deleted = :deleted and order.deleted = :deleted";
    Query query = session.createQuery(hql);
    query.setParameter("deleted", false);
    List<HbmOrderItem> items = (List<HbmOrderItem>) query.list();

    int i = 0;//  w  w w .  j  av  a 2  s.  co m
    for (HbmOrderItem item : items) {
        ++i;
        Long id = item.getId();
        BigDecimal price = item.getPrice();
        if (false) {
            System.out.println(">>> Item.id: " + id + " " + price);
        }
    }

    tr.commit();
    printTime("SINGLE SELECT " + i, time1, System.currentTimeMillis());
}

From source file:benchmark.BenchmarkHnP.java

License:Apache License

/** Create database and using SELECT */
@SuppressWarnings("unchecked")
public void useEmptySelect() {

    long time1 = System.currentTimeMillis();
    Transaction tr = session.beginTransaction();

    for (int i = -ORDER_COUNT; i < 0; i++) {
        String hql = "from HbmOrder where id = :id and deleted = :deleted";
        Query query = session.createQuery(hql);
        query.setParameter("id", new Long(i));
        query.setParameter("deleted", true);
        List<HbmOrder> items = (List<HbmOrder>) query.list();
    }//from  w w  w .  j a  v a2  s .com

    tr.commit();
    printTime("EMPTY SELECT " + ORDER_COUNT, time1, System.currentTimeMillis());
    ;

}