List of usage examples for org.hibernate SQLQuery uniqueResult
R uniqueResult();
From source file:com.bitranger.parknshop.common.ads.PsPromotItemDAO.java
License:Open Source License
public double calAdRevenue() { return getHibernateTemplate().execute(new HibernateCallback<Double>() { @Override/*from w w w . j a va2 s . c o m*/ public Double doInHibernate(Session session) throws HibernateException, SQLException { SQLQuery q = session .createSQLQuery(" select sum(AD.num_fetched * AD.weight) as ACC from ps_promot_item as PI " + " inner join ps_ad_item as AD on AD.id_promot = PI.id " + " where AD.time_start < CURRENT_TIMESTAMP " + " and CURRENT_TIMESTAMP < AD.time_end "); q.addScalar("ACC", Hibernate.DOUBLE); Double db = (Double) q.uniqueResult(); return db == null ? 0.0 : db; } }); }
From source file:com.bitranger.parknshop.common.dao.impl.PersistantMap.java
License:Open Source License
@Override public Object get(final String key) { Assert.notBlank(key);//from ww w . jav a 2 s. c om byte[] b = getHibernateTemplate().execute(new HibernateCallback<byte[]>() { @Override public byte[] doInHibernate(Session arg0) throws HibernateException, SQLException { SQLQuery query = arg0.createSQLQuery("select val from ps_key_values where key = ?"); query.setString(0, key); query.addScalar("val", Hibernate.BLOB); return (byte[]) query.uniqueResult(); } }); return ObjUtils.fromBytes(b); }
From source file:com.bitranger.parknshop.seller.dao.impl.PsOrderDAO.java
License:Open Source License
@Override public double countTnxVolumn() { return getHibernateTemplate().execute(new HibernateCallback<Double>() { @Override/* w w w . j a v a2 s.c om*/ public Double doInHibernate(Session session) throws HibernateException, SQLException { SQLQuery query = session.createSQLQuery( " select sum(OD.price_total)as REV from ps_order as OD " + " where OD.status = 3"); query.addScalar("REV", Hibernate.DOUBLE); Double db = (Double) query.uniqueResult(); return db == null ? 0.0 : db; } }); }
From source file:com.bookselling.dao.RatingDaoImpl.java
@Override public double getAveragePoint(Serializable id) { SQLQuery query = getSession().createSQLQuery(" select avg(point) " + " from rating " + " where sellingPostId = :id " + " group by sellingPostId "); query.setInteger("id", (int) id); BigDecimal averagePoint = (BigDecimal) query.uniqueResult(); return averagePoint != null ? averagePoint.doubleValue() : -1.0; }
From source file:com.bookselling.dao.SellingPostDaoImpl.java
@Override public int totalPost() { SQLQuery sqlQuery = getSession().createSQLQuery("select COUNT(*) " + "from post"); BigInteger figure = (BigInteger) sqlQuery.uniqueResult(); return figure != null ? figure.intValue() : 0; }
From source file:com.bookselling.dao.SystemInvoiceDaoImpl.java
@Override public double totalProfit() { SQLQuery sqlQuery = getSession().createSQLQuery("select SUM(FEE) " + "from systeminvoice "); Double figure = (Double) sqlQuery.uniqueResult(); return figure != null ? figure.doubleValue() : 0.0; }
From source file:com.bookselling.dao.UserDaoImpl.java
@Override public int totalUser() { SQLQuery sqlQuery = getSession().createSQLQuery("select count(*) " + "from user"); BigInteger figure = (BigInteger) sqlQuery.uniqueResult(); return figure != null ? figure.intValue() : 0; }
From source file:com.br.uepb.dao.MedicaoBalancaDAO.java
License:Open Source License
/** * Metodo para listar a ultima medio do paciente cadastrada * @param idPaciente int/* w ww. j a v a 2 s . c om*/ * @return MedicaoBalancaDomain */ public MedicaoBalancaDomain obtemUltimaMedicao(int idPaciente) { String comando = "select mb.* from medicao_balanca mb " + "where mb.paciente_id = :idPaciente " + "order by data_hora desc " + "limit 1"; SQLQuery query = SessaoAtual().createSQLQuery(comando); query.setParameter("idPaciente", idPaciente); query.addEntity(MedicaoBalancaDomain.class); MedicaoBalancaDomain medicao = (MedicaoBalancaDomain) query.uniqueResult(); return medicao; }
From source file:com.br.uepb.dao.MedicaoOximetroDAO.java
License:Open Source License
/** * Mtodo para obter a ultima medio cadastrada de acordo com o id do paciente * @param idPaciente Id do paciente//w w w .j a va 2 s .co m * @return MedicaoOximetroDomain */ public MedicaoOximetroDomain obtemUltimaMedicao(int idPaciente) { String comando = "select mo.* from Medicao_oximetro mo " + "where mo.paciente_id = :idPaciente " + "order by data_hora desc " + "limit 1"; SQLQuery query = SessaoAtual().createSQLQuery(comando); query.setParameter("idPaciente", idPaciente); query.addEntity(MedicaoOximetroDomain.class); MedicaoOximetroDomain medicao = (MedicaoOximetroDomain) query.uniqueResult(); return medicao; }
From source file:com.br.uepb.dao.MedicaoPressaoDAO.java
License:Open Source License
/** * Mtodo para obter a ultima medio cadastrada * @param idPaciente Id do paciente//from w ww . j a va 2 s . co m * @return MedicaoPressaoDomain */ public MedicaoPressaoDomain obtemUltimaMedicao(int idPaciente) { String comando = "select mp.* from medicao_pressao mp " + "where mp.paciente_id = :idPaciente " + "order by data_hora desc " + "limit 1"; SQLQuery query = SessaoAtual().createSQLQuery(comando); query.setParameter("idPaciente", idPaciente); query.addEntity(MedicaoPressaoDomain.class); MedicaoPressaoDomain medicao = (MedicaoPressaoDomain) query.uniqueResult(); return medicao; }