Example usage for org.hibernate Session getNamedQuery

List of usage examples for org.hibernate Session getNamedQuery

Introduction

In this page you can find the example usage for org.hibernate Session getNamedQuery.

Prototype

org.hibernate.Query getNamedQuery(String queryName);

Source Link

Document

Create a Query instance for the named query.

Usage

From source file:at.gv.egovernment.moa.id.storage.DBExceptionStoreImpl.java

License:EUPL

public void clean(long now, long exceptionTimeOut) {
    Date expioredate = new Date(now - exceptionTimeOut);

    List<ExceptionStore> results;
    Session session = MOASessionDBUtils.getCurrentSession();

    synchronized (session) {
        session.beginTransaction();//from  w  ww.  ja va2s. c o m
        Query query = session.getNamedQuery("getExceptionWithTimeOut");
        query.setTimestamp("timeout", expioredate);
        results = query.list();
        session.getTransaction().commit();
    }

    if (results.size() != 0) {
        for (ExceptionStore result : results) {
            try {
                MOASessionDBUtils.delete(result);
                Logger.info("Remove Exception with ID=" + result.getExid() + " after timeout.");

            } catch (HibernateException e) {
                Logger.warn("Exception with ID=" + result.getExid()
                        + " not removed after timeout! (Error during Database communication)", e);
            }

        }
    }
}

From source file:at.gv.egovernment.moa.id.storage.DBExceptionStoreImpl.java

License:EUPL

@SuppressWarnings("rawtypes")
private ExceptionStore searchInDatabase(String id) throws MOADatabaseException {
    MiscUtil.assertNotNull(id, "exceptionID");
    Logger.trace("Getting Exception with ID " + id + " from database.");
    Session session = MOASessionDBUtils.getCurrentSession();
    List result;/*from  w  w  w .  j a  v  a2s.c  om*/

    synchronized (session) {
        session.beginTransaction();
        Query query = session.getNamedQuery("getExceptionWithID");
        query.setParameter("id", id);
        result = query.list();

        //send transaction
        session.getTransaction().commit();
    }

    Logger.trace("Found entries: " + result.size());

    //Assertion requires an unique artifact
    if (result.size() != 1) {
        Logger.trace("No entries found.");
        throw new MOADatabaseException("No Exception found with ID " + id);
    }

    return (ExceptionStore) result.get(0);
}

From source file:baza.Broker.java

public List<PregledWeb> vratiPregledePacijenta(String jmbg) {
    Session session = Test.getSessionFactory().openSession();
    ArrayList<Pregled> pregledi = null;
    try {/*  www . jav a  2 s .  c  om*/
        session.beginTransaction();
        Query q = session.getNamedQuery("Pregled.findByPacijent").setString("pacijent", jmbg);
        List result = q.list();

        pregledi = (ArrayList<Pregled>) result;
        session.getTransaction().commit();
    } catch (Exception e) {
        session.getTransaction().rollback();
    }
    //        for (Pregled pregledi1 : pregledi) {
    //        Query qu = session.getNamedQuery("Nalaz.findByPregled").setInteger("pregled", pregledi1.getPregledPK().getBrojPregleda());
    //        List result1 = qu.list();
    //        ArrayList<Nalaz> nalazi=(ArrayList<Nalaz>) result1;
    //        pregledi1.setNalazList(nalazi);

    //        }
    //      

    finally {
        session.close();
    }
    List<PregledWeb> preglediweb = new ArrayList<PregledWeb>();
    for (Pregled pregled : pregledi) {
        PregledWeb prw = new PregledWeb();
        prw.setLekar(pregled.getLekar1());
        prw.setPacijent(pregled.getPacijent1());
        PregledPKWeb prwpk = new PregledPKWeb();
        prwpk.setBrojPregleda(pregled.getPregledPK().getBrojPregleda());
        prwpk.setLekar(pregled.getPregledPK().getLekar());
        prwpk.setPacijent(pregled.getPregledPK().getPacijent());
        prw.setBrojPregleda(pregled.getPregledPK().getBrojPregleda());
        prw.setDatum(pregled.getDatum());
        prw.setPregledpk(prwpk);
        prw.setTippregleda(pregled.getTipPregleda());
        preglediweb.add(prw);
    }
    return preglediweb;

}

From source file:baza.Broker.java

public List<NalazWeb> vratiNalaze(int pregled) {
    Session session = Test.getSessionFactory().openSession();
    ArrayList<Nalaz> nalazi = null;
    try {// w  w w .  j a  va  2s  .c o m
        session.beginTransaction();

        Query q = session.getNamedQuery("Nalaz.findByPregled").setInteger("pregled", pregled);
        List result = q.list();
        nalazi = (ArrayList<Nalaz>) result;
        session.getTransaction().commit();
    } catch (Exception e) {
        session.getTransaction().rollback();

    } finally {
        session.close();
    }
    List<NalazWeb> lista = new ArrayList<NalazWeb>();
    for (Nalaz nalaz : nalazi) {
        NalazWeb n = new NalazWeb();
        NalazPKWeb npk = new NalazPKWeb();
        npk.setBrojPregleda(nalaz.getNalazPK().getPregled());
        npk.setRedniBroj(nalaz.getNalazPK().getRedniBroj());
        npk.setLekar(nalaz.getNalazPK().getLekar());
        n.setNalazpk(npk);
        n.setTegobe(nalaz.getTegobe());
        n.setPredlozenaTerapija(nalaz.getPredlozenaTerapija());
        n.setRedniBroj(nalaz.getNalazPK().getRedniBroj());
        lista.add(n);
    }

    return lista;
}

From source file:baza.Broker.java

public Pregled vratiPregled(int pregled) {
    Session session = Test.getSessionFactory().openSession();
    Pregled p = null;/*  ww w . j av  a2s.co  m*/
    try {
        session.beginTransaction();

        Query q = session.getNamedQuery("Pregled.findByBrojPregleda").setInteger("brojPregleda", pregled);
        p = (Pregled) q.list().get(0);
    } catch (Exception e) {
        session.getTransaction().rollback();
    } finally {
        session.close();

    }
    return p;
}

From source file:br.com.bibliotecasj.DAO.FrequenciaDAO.java

@Override
public Frequencia buscar(String cpf) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Frequencia fre = null;/*from  w w w  .  j a  va2s .  c om*/
    try {

        Query consulta = sessao.getNamedQuery("frequencia.BuscarCpf");
        consulta.setString("cpf", cpf);
        fre = (Frequencia) consulta.uniqueResult();
    } catch (RuntimeException ex) {
        throw ex;

    } finally {
        sessao.close();
    }
    return fre;
}

From source file:br.com.bibliotecasj.DAO.FrequenciaDAO.java

@Override
public List<Frequencia> listarTodos() {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    List<Frequencia> fre = null;
    try {//from  www .  j a  v a 2s  . co  m
        sessao.beginTransaction();
        Query consulta = sessao.getNamedQuery("Frequencia.listar");
        fre = consulta.list();
    } catch (RuntimeException ex) {
        sessao.getTransaction().commit();

    } finally {
        sessao.close();
    }
    return fre;
}

From source file:br.com.bibliotecasj.DAO.LoginDAO.java

@Override
public Login buscar(String login) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Login log = null;//from ww  w  .  jav  a 2s.  c  om
    try {

        Query consulta = sessao.getNamedQuery("Login.Buscarlog");
        consulta.setString("login", login);
        log = (Login) consulta.uniqueResult();
    } catch (RuntimeException ex) {
        throw ex;

    } finally {
        sessao.close();
    }
    return log;
}

From source file:br.com.bibliotecasj.DAO.LoginDAO.java

@Override
public List<Login> listarTodos() {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    List<Login> log = null;
    try {/*from w  w  w . j av  a 2 s  . co m*/
        sessao.beginTransaction();
        Query consulta = sessao.getNamedQuery("Login.listar");
        log = consulta.list();
    } catch (RuntimeException ex) {
        sessao.getTransaction().commit();

    } finally {
        sessao.close();
    }
    return log;
}

From source file:br.com.bibliotecasj.DAO.UsuarioDAO.java

@Override
public Usuario buscar(String cpf) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Usuario usu = null;/*from  w  w w .  j a  v a2  s . c o m*/
    try {

        Query consulta = sessao.getNamedQuery("Usuario.BuscarCpf");
        consulta.setString("cpf", cpf);
        usu = (Usuario) consulta.uniqueResult();
    } catch (RuntimeException ex) {
        throw ex;

    } finally {
        sessao.close();
    }
    return usu;
}