List of usage examples for org.hibernate SQLQuery uniqueResult
R uniqueResult();
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public int getCTDGraphBreadCrumbCount(Map<String, String> key) { String sql = getCTDSQL(key, "graphbreadcrumb"); Session session = factory.getCurrentSession(); session.beginTransaction();// w w w . j a v a 2 s. c o m SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q = bindGraphCTDSQLValues(q, key); q.setCacheable(true); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public int getCTDGraphCount(Map<String, String> key) { String sql = getCTDSQL(key, "graphcount"); Session session = factory.getCurrentSession(); session.beginTransaction();//w w w . j a va2s. c o m SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q = bindGraphCTDSQLValues(q, key); q.setCacheable(true); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public int getGADBreadCrumbCount(Map<String, String> key) { String sql = getGADSQL(key, "breadcrumb"); Session session = factory.getCurrentSession(); session.beginTransaction();/*from w w w . j av a 2s . com*/ SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q = bindSQLValues(q, key); q.setCacheable(true); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public int getGADGraphBreadCrumbCount(Map<String, String> key) { String sql = getGADSQL(key, "graphbreadcrumb"); Session session = factory.getCurrentSession(); session.beginTransaction();/* www. j a va 2s. com*/ SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q = bindGraphGADSQLValues(q, key); q.setCacheable(true); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public int getGADGraphCount(Map<String, String> key) { String sql = getGADSQL(key, "graphcount"); Session session = factory.getCurrentSession(); session.beginTransaction();//from ww w . j a va2 s . co m SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q = bindGraphGADSQLValues(q, key); q.setCacheable(true); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }
From source file:edu.vt.vbi.patric.dao.DBDisease.java
License:Apache License
public int getGADCount(Map<String, String> key) { String sql = getGADSQL(key, "count"); Session session = factory.getCurrentSession(); session.beginTransaction();//from w ww. j a va 2 s .co m SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q = bindSQLValues(q, key); q.setCacheable(true); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }
From source file:edu.vt.vbi.patric.dao.DBPRC.java
License:Apache License
public int getPRCCount(String taxonId, String filter) { String sql = "select count(*) cnt from (select distinct experiment_id, description, speciesname, processing_type, summary, pubmed_id, count(distinct sample_id) from app.post_genomic"; if (filter.equals("MS")) sql += " where processing_type = 'Mass spectrometry'"; else if (filter.equals("MA")) sql += " where processing_type = 'Microarray'"; else/*ww w .java 2s . com*/ sql += " where processing_type = 'Protein interaction'"; sql += " and taxon_id in (" + DBSummary.getTaxonIdsInTaxonSQL(":taxonId") + ")"; sql += " group by experiment_id, description, speciesname, processing_type, summary, pubmed_id)"; Session session = factory.getCurrentSession(); session.beginTransaction(); SQLQuery q = session.createSQLQuery(sql).addScalar("cnt", Hibernate.INTEGER); q.setCacheable(true); q.setTimeout(SQL_TIMEOUT); q.setString("taxonId", taxonId); Object obj = q.uniqueResult(); session.getTransaction().commit(); return Integer.parseInt(obj.toString()); }
From source file:es.emergya.bbdd.dao.RecursoHome.java
License:Open Source License
@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRED) public RecursoBean getByDispositivoSQL(Integer issi) { SQLQuery query = getSession().createSQLQuery("select r.x_recurso as " + "id, r.identificador as identificador, r.habilitado as habilitado, " + "r.tipo as \"tipoRecurso\", s.nombre as " + "subflota, r.dispositivo as dispositivo from recursos as r join flotas s on r.flota_x_flota = s.x_flota " + "where r.dispositivo = :DISPOSITIVO"); query.setInteger("DISPOSITIVO", issi); query.setResultTransformer(Transformers.aliasToBean(RecursoBean.class)); RecursoBean recurso = (RecursoBean) query.uniqueResult(); return recurso; }
From source file:financeiro.dao.hibernate.LancamentoDAOHibernate.java
License:Creative Commons License
public float saldo(Conta conta, Date data) { if (data == null) { throw new IllegalArgumentException("[Financeiro] data cannot be null"); }/*from w w w. j a v a2 s . c o m*/ StringBuffer sql = new StringBuffer(); sql.append("select sum(l.valor * c.fator)"); sql.append(" from LANCAMENTO l,"); sql.append(" CATEGORIA c"); sql.append(" where l.categoria = c.codigo"); sql.append(" and l.conta = :conta"); sql.append(" and l.data <= :data"); SQLQuery query = this.session.createSQLQuery(sql.toString()); query.setParameter("conta", conta.getConta()); query.setParameter("data", data); BigDecimal saldo = (BigDecimal) query.uniqueResult(); if (saldo != null) { return saldo.floatValue(); } return 0f; }
From source file:fr.gael.dhus.database.dao.ActionRecordReaderDao.java
License:Open Source License
/** * Returns the result of a SQL query.//from ww w.ja v a 2 s. c o m * * @param sql * The sql string. * @param periodicity * A list of two Date or null if not applicable. * @return number of elements returned by the passed query. Is something is * wrong with the query result, 0 is returned */ private int getCountValue(final String sql, final Date start, final Date end) { boolean newSession = false; Session session; try { session = getSessionFactory().getCurrentSession(); } catch (HibernateException e) { session = getSessionFactory().openSession(); newSession = true; } SQLQuery query = session.createSQLQuery(sql); if (start != null) query.setDate(0, start); if (end != null) query.setDate(1, end); BigInteger result = (BigInteger) query.uniqueResult(); if (newSession) session.disconnect(); return result.intValue(); }