List of usage examples for org.hibernate Query uniqueResult
R uniqueResult();
From source file:celepsa.rrcc.da.ClimaDA.java
public int InfluenciaPersonasDocumento(Tmzona objSistema) throws Exception { String sQuery = "Select tmDocumento.id as DocID " + "from tmDocumento, tmStakePersona " + "where " + "tmDocumento.tmStakePersona_id=tmStakePersona.id and " + "tmStakePersona.tmZona_id='" + objSistema.getId() + "'"; try {//from w w w . j av a2 s . c o m org.hibernate.Transaction tx = session.beginTransaction(); Query query = session.createSQLQuery(sQuery); Integer res = (Integer) query.uniqueResult(); SumInfxDoc = SumInfxDoc + this.PersonasDocumento(res + ""); tx.commit(); return getSumInfxDoc(); } catch (NumberFormatException | HibernateException e) { logger.error(e.getMessage()); throw e; } }
From source file:celepsa.rrcc.da.ClimaDA.java
public int PersonasDocumento(String IdDOC) throws Exception { String sQuery = "Select " + " Sum(tmStakePersona.tmNivelInfluencia_id) as Ninf, tmDocumento.id as nrodoc " + "from PersonaDocumento, tmStakePersona, tmDocumento " + "where " + "PersonaDocumento.tmStakePersona_id=tmStakePersona.id and " + "PersonaDocumento.tmDocumento_id=tmDocumento.id and " + "PersonaDocumento.tmDocumento_id='" + IdDOC + "'"; try {/*from w w w .j av a 2s .com*/ org.hibernate.Transaction tx = session.beginTransaction(); Query query = session.createSQLQuery(sQuery); Integer res = (Integer) query.uniqueResult(); SumPerDoc = SumPerDoc + ((Integer) Integer.parseInt(res + "")); tx.commit(); return getSumPerDoc(); } catch (NumberFormatException | HibernateException e) { logger.error(e.getMessage()); throw e; } }
From source file:cgi.lemans.portail.domaine.gamaweb.impl.AbsenceDao.java
@Override public Absence findAbsenceByPremierJourAbsence(String idRessource) { String hql = "from Absence a " + "where a.premierJourAbsence >= :dateToday " + "and a.refRessource.idRessource = :idRessource " + "order by a.premierJourAbsence"; Query query = getSession().createQuery(hql); query.setParameter("idRessource", idRessource); query.setDate("dateToday", new java.util.Date()); query.setMaxResults(1);/*from ww w.jav a 2 s .com*/ Absence results = (Absence) query.uniqueResult(); return results; }
From source file:cgi.lemans.portail.domaine.gamaweb.impl.AbsenceDao.java
@Override public Double findAbsenceByTypeByRessource(String idRessource, String type) { String hql = "SELECT sum(a.nombreJourAbsence) as pris " + "from Absence a " + "where YEAR(a.premierJourAbsence)= :annee " + "and a.refTypeAbsence.idTypeAbsence = :type " + "and a.refRessource.id = :idRessource "; Query query = getSession().createQuery(hql); query.setParameter("idRessource", idRessource); query.setParameter("annee", Calendar.getInstance().get(Calendar.YEAR)); query.setParameter("type", Integer.parseInt(type)); Double results = (Double) query.uniqueResult(); return results; }
From source file:cgi.lemans.portail.domaine.gamaweb.impl.CufRessourceAbsenceDao.java
@Override public CufRessourceAbsence findCufRessourceAbsenceByTypeByRessource(String idRessource, String type) { String hql = "from CufRessourceAbsence a " + "where a.annee= :annee " + "and a.typeAbsence.idTypeAbsence = :type " + "and a.ressourceTma.idRessource = :idRessource "; Query query = getSession().createQuery(hql); query.setParameter("idRessource", idRessource); query.setParameter("annee", Calendar.getInstance().get(Calendar.YEAR)); query.setParameter("type", Integer.parseInt(type)); CufRessourceAbsence results = (CufRessourceAbsence) query.uniqueResult(); return results; }
From source file:cgi.lemans.portail.domaine.gamaweb.impl.DemandeOuProjetDao.java
public DemandeOuProjet findIdMax() { String hql = "select max(a.idDemande) from DemandeOuprojet"; Query query = getSession().createQuery(hql); DemandeOuProjet results = (DemandeOuProjet) query.uniqueResult(); return results; }
From source file:ch.eggbacon.app.service.LeistungServiceImpl.java
License:Open Source License
@Override public Leistung getLeistungByBeschreibung(String beschreibung) { Query q = getSession().createQuery("FROM " + TABLE_NAME + " WHERE Beschreibung = :beschr"); q.setParameter("beschr", beschreibung); return ((Leistung) q.uniqueResult()); }
From source file:ch.eggbacon.app.service.RechungServiceImpl.java
License:Open Source License
@Override public List<Rechnung> searchRechnungenByPersonId(Long id) { BuchungService buchungService = new BuchungServiceImpl(); List<Buchung> buchungen = buchungService.searchBuchungenByPersonId(id); List<Rechnung> rechnungen = new ArrayList<>(); for (Buchung b : buchungen) { Query q = getSession().createQuery("FROM Rechnung WHERE buchungId = :buchungId"); q.setLong("buchungId", b.getPerson().getPersId()); rechnungen.add((Rechnung) q.uniqueResult()); }/*from ww w . j a v a 2s . c o m*/ return rechnungen; }
From source file:ch.tatool.app.service.impl.ModuleSessionDAO.java
License:Open Source License
private Integer findLastSessionIndex(final ModuleImpl module) { return (Integer) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) { String queryString = "select max(session.index) from ModuleSessionImpl session where session.module = :module"; Query query = session.createQuery(queryString); query.setParameter("module", module); Integer result = (Integer) query.uniqueResult(); if (result != null) { return result; } else { return 0; }// ww w.java 2s .co m } }); }
From source file:cl.cesfam.SERVLET.RequestHelper.java
private static void ObtenerInforme(HttpServletRequest request, HttpServletResponse response) { JSONArray medicamentos = new JSONArray(); JSONObject salida = new JSONObject(); try {//ww w .j a v a2 s. c o m if (cl.cesfam.DAO.MedicamentoDAO.getList() != null) { for (cl.cesfam.ENTITY.Medicamento tmp : cl.cesfam.DAO.MedicamentoDAO.getList()) { JSONObject item = new JSONObject(); String cantidadReservada; Session session = cl.cesfam.DAL.NewHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); Query query = session.createQuery( "select sum(cantidad) from Reserva where medicamento=" + tmp.getIdMedicamento()); if (query.uniqueResult() == null) { cantidadReservada = "0"; } else { cantidadReservada = query.uniqueResult().toString(); } session.close(); item.put("nombre", tmp.getNombreMedicamento()); item.put("fabricante", tmp.getFabricante()); item.put("presentacion", tmp.getPresentacion()); item.put("contenido", tmp.getContenidoEnvase()); item.put("stock", tmp.getStock()); item.put("stockCritico", tmp.getStockCritico()); item.put("cantidadReservada", (String) cantidadReservada); medicamentos.put(item); } salida.put("data", medicamentos); PrintWriter out = response.getWriter(); System.out.println("el objeto es :" + salida); out.println(salida); out.flush(); } else { salida.put("data", medicamentos); PrintWriter out = response.getWriter(); System.out.println("el objeto es :" + salida); out.println(salida); out.flush(); } } catch (Exception ex) { Logger.getLogger(RequestHelper.class.getName()).log(Level.SEVERE, null, ex); } }