List of usage examples for org.hibernate Session getNamedQuery
org.hibernate.Query getNamedQuery(String queryName);
From source file:br.com.sigcopex.dao.TermoAutorizacaoExtensaoDAO.java
public TermoAutorizacaoExtensao buscarPorCodigo(Long codigo) { Session sessao = HibernateUtil.getSessionFactory().openSession(); TermoAutorizacaoExtensao termoAutorizacaoExtensao = null; try {/*from w w w .j a va 2 s.com*/ Query consulta = sessao.getNamedQuery("TermoAutorizacaoExtensao.buscarPorCodigo"); consulta.setLong("codigo", codigo); termoAutorizacaoExtensao = (TermoAutorizacaoExtensao) consulta.uniqueResult(); } catch (RuntimeException ex) { throw ex; } finally { sessao.close(); } return termoAutorizacaoExtensao; }
From source file:cdp.InicializarAgente.java
public static InicializarAgente obterIA(int idIni) { Session sessao = HibernateUtility.getSession(); //Abrindo uma sessao Transaction transacao = sessao.beginTransaction(); //Iniciando uma transacao Query select = sessao.getNamedQuery("BuscarIA"); select.setInteger("idIni", idIni); InicializarAgente ia = new InicializarAgente(); ia = (InicializarAgente) select.uniqueResult(); transacao.commit(); //Finalizando a transacao sessao.close(); //Fechando a sessao return ia;// w w w .j a va 2 s. c om }
From source file:cdp.InicializarAgente.java
public static List obterIAM(int idModelo) { Session sessao = HibernateUtility.getSession(); //Abrindo uma sessao Transaction transacao = sessao.beginTransaction(); //Iniciando uma transacao Query select = sessao.getNamedQuery("BuscarIAM"); select.setInteger("idModelo", idModelo); List ia = select.list();//from w w w . j a v a 2s . c o m transacao.commit(); //Finalizando a transacao sessao.close(); //Fechando a sessao return ia; }
From source file:cdp.InicializarAgente.java
public static List obterIAA(int idAgente) { Session sessao = HibernateUtility.getSession(); //Abrindo uma sessao Transaction transacao = sessao.beginTransaction(); //Iniciando uma transacao Query select = sessao.getNamedQuery("BuscarIAA"); select.setInteger("idAgente", idAgente); List ia = select.list();//from ww w.j a va2 s. c o m transacao.commit(); //Finalizando a transacao sessao.close(); //Fechando a sessao return ia; }
From source file:cdp.InicializarAgenteVariaveis.java
public static InicializarAgenteVariaveis obterIAV(int idIni, int idVar) { Session sessao = HibernateUtility.getSession(); //Abrindo uma sessao Transaction transacao = sessao.beginTransaction(); //Iniciando uma transacao Query select = sessao.getNamedQuery("BuscarIAV"); select.setInteger("idIni", idIni); select.setInteger("idVar", idVar); InicializarAgenteVariaveis iav = new InicializarAgenteVariaveis(); iav = (InicializarAgenteVariaveis) select.uniqueResult(); transacao.commit(); //Finalizando a transacao sessao.close(); //Fechando a sessao return iav;/* w w w . ja va 2 s. co m*/ }
From source file:ch.algotrader.dao.AbstractDao.java
License:Open Source License
private Query createQuery(final String queryString, final QueryType type) { Session currentSession = getCurrentSession(); switch (type) { case HQL:/*from w w w . ja v a2 s. c om*/ return currentSession.createQuery(queryString); case SQL: return currentSession.createSQLQuery(queryString); case BY_NAME: return currentSession.getNamedQuery(queryString); default: throw new IllegalStateException("Unexpected query type: " + type); } }
From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.DataCenterDAOHibernate.java
License:Open Source License
@Override public Long getNumberVirtualDatacentersByDatacenter(final Integer idDatacenter) { Long numberOfVirtualDatacenters; final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession(); final Query pmQuery = session.getNamedQuery(DATACENTER_GET_NUMBER_OF_VIRTUAL_DATACENTERS); pmQuery.setInteger("idDatacenter", idDatacenter); numberOfVirtualDatacenters = (Long) pmQuery.uniqueResult(); return numberOfVirtualDatacenters; }
From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.DataCenterDAOHibernate.java
License:Open Source License
@Override public DatacenterHB getDatacenterWhereThePrivateNetworkStays(final Integer networkId) throws PersistenceException { DatacenterHB datacenter;//from ww w . j av a 2 s .c om try { final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession(); final Query query = session.getNamedQuery(DATACENTER_GET_BY_PRIVATE_NETWORK_ID); query.setInteger("networkId", networkId); datacenter = (DatacenterHB) query.uniqueResult(); } catch (final HibernateException he) { throw new PersistenceException(he.getMessage(), he); } return datacenter; }
From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.DataCenterDAOHibernate.java
License:Open Source License
@Override public DatacenterHB getDatacenterWhereThePublicNetworkStays(final Integer idNetwork) throws PersistenceException { DatacenterHB datacenter;/*w w w . j ava 2 s . c om*/ try { final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession(); final Query query = session.getNamedQuery(DATACENTER_GET_BY_PUBLIC_NETWORK_ID); query.setInteger("networkId", idNetwork); datacenter = (DatacenterHB) query.uniqueResult(); } catch (final HibernateException he) { throw new PersistenceException(he.getMessage(), he); } return datacenter; }
From source file:com.abiquo.abiserver.persistence.dao.infrastructure.hibernate.DataCenterDAOHibernate.java
License:Open Source License
@Override public DatacenterHB findByName(final String name) throws PersistenceException { DatacenterHB datacenter;// w w w . j ava 2 s . c o m try { final Session session = HibernateDAOFactory.getSessionFactory().getCurrentSession(); final Query query = session.getNamedQuery(GET_DATACENTER_BY_NAME); query.setString("name", name); datacenter = (DatacenterHB) query.uniqueResult(); } catch (final NonUniqueResultException e) { // No datacenter found return null; } catch (final HibernateException he) { throw new PersistenceException(he.getMessage(), he); } return datacenter; }