Example usage for org.hibernate Query uniqueResult

List of usage examples for org.hibernate Query uniqueResult

Introduction

In this page you can find the example usage for org.hibernate Query uniqueResult.

Prototype

R uniqueResult();

Source Link

Document

Convenience method to return a single instance that matches the query, or null if the query returns no results.

Usage

From source file:clases.cDN.java

public DocumentoNotificacion leer_cod(Integer codDocumentoNotificacion) {
    DocumentoNotificacion obj = null;//from   ww w.  j  a  v  a2s . co  m
    Transaction trns = null;
    sesion = HibernateUtil.getSessionFactory().openSession();
    try {
        trns = sesion.beginTransaction();
        Query q = sesion
                .createQuery("from DocumentoNotificacion dn where dn.codDocumentoNotificacion = :param1");
        q.setInteger("param1", codDocumentoNotificacion);
        obj = (DocumentoNotificacion) q.uniqueResult();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        sesion.flush();
        sesion.close();
    }
    return obj;
}

From source file:clases.cExtra.java

/**
 *
 * @param codExtra/*from   w w  w. j av a  2s .  c  om*/
 * @param tipo sucursal, propietario,marca, estado
 * @return
 */
public Extra leer_cod(Integer codExtra) {
    Extra obj = null;
    Transaction trns = null;
    sesion = HibernateUtil.getSessionFactory().openSession();
    try {
        trns = sesion.beginTransaction();
        Query q = sesion.createQuery("from Extra e " + "where e.codExtra = :param1 ").setInteger("param1",
                codExtra);
        obj = (Extra) q.uniqueResult();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        sesion.flush();
        sesion.close();
    }
    return obj;
}

From source file:cn.dao.MedicineInfoDao.java

public int getPageCount(Session session, String hql, Map properties) {
    StringBuffer countHql = new StringBuffer();
    countHql.append("select count(1) ");
    countHql.append(hql);//from w  w  w  .  jav  a 2  s . c  o m
    Query query = session.createQuery(countHql.toString());
    if (properties != null) {
        query.setProperties(properties);
    }
    return Integer.parseInt(query.uniqueResult().toString());
}

From source file:cn.dao.MedicinePurchaseDao.java

public int getPageCount(Session session, String hql, Map properties) {
    StringBuffer countHql = new StringBuffer();
    countHql.append("select count(1) from(");
    countHql.append(hql);//from w ww.ja v  a 2  s  .c  o  m
    countHql.append(") c");
    Query query = session.createSQLQuery(countHql.toString());
    if (properties != null) {
        query.setProperties(properties);
    }
    return Integer.parseInt(query.uniqueResult().toString());
}

From source file:cn.effine.dao.OauthAccessTokenDaoImpl.java

@Override
public OauthAccessToken getoAccessToken(String id) {
    String hql = "from OauthAccessToken u where u.id=?";
    Query query = sessionFactory.getCurrentSession().createQuery(hql);
    query.setString(0, id);/*from w ww .  ja  va  2  s.  c  o  m*/
    return (OauthAccessToken) query.uniqueResult();
}

From source file:cn.mljia.common.notify.port.adapter.persistence.HibernateNotifyRecordRepository.java

License:Apache License

@Override
public Integer notifyRecordOfByPageCount(Integer maxNotifyTimes) throws NegativeException {
    // TODO Auto-generated method stub
    StringBuilder sql = new StringBuilder();
    sql.append(//  w  ww  .j  a v a 2s.  c  om
            "select count(1) from tb_common_notify_record  where 1 = 1 and status != 'SUCCESS' and status != 'FAILED' and notify_times < :maxNotifyTimes  ");
    Query query = this.session().createSQLQuery(sql.toString()).setParameter("maxNotifyTimes", maxNotifyTimes);
    BigInteger count = (BigInteger) query.uniqueResult();
    return count != null ? count.intValue() : 0;
}

From source file:cn.trymore.core.dao.impl.DAOGenericImpl.java

License:Open Source License

public Object findUnique(final String hsql, final Object[] params) {
    return getHibernateTemplate().execute(new HibernateCallback() {

        @Override/*from  ww  w. ja  va 2 s  .co m*/
        public Object doInHibernate(Session paramSession) throws HibernateException, SQLException {
            Query localQuery = paramSession.createQuery(hsql);
            if (params != null) {
                for (int i = 0; i < params.length; i++) {
                    localQuery.setParameter(i, params[i]);
                }
            }

            return localQuery.uniqueResult();
        }
    });
}

From source file:cn.zhuqi.mavenssh.dao.impl.GenericDAO.java

@SuppressWarnings("unchecked")
protected T queryForObject(String hql, Object[] params) {
    Query query = getSession().createQuery(hql);
    setQueryParams(query, params);/*from   w w  w. j ava  2s . co  m*/
    return (T) query.uniqueResult();
}

From source file:co.com.codesoftware.logic.ProductoLogic.java

/**
 * Funcion con la cual valido la exitencia de un codigo externo para que no
 * halla duplicidad//from w w w  . j  av  a 2s .  c o m
 *
 * @param idDska
 * @param codExterno
 * @return
 */
public String validaCodigoExterno(Integer idDska, String codExterno) {
    String rta = "";
    try {
        initOperation();
        Query query = sesion.createQuery(
                "select count(*) from ProductoSimpleEntity where codigoExt = :codExt and id <> :idDska");
        query.setParameter("codExt", codExterno);
        query.setInteger("idDska", idDska);
        String count = "" + query.uniqueResult();
        if (Integer.parseInt(count) == 0) {
            rta = "unico";
        } else {
            rta = "duplicado";
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return rta;
}

From source file:co.com.codesoftware.logica.facturacion.FacturacionLogica.java

/**
 * Funcion con la cual busco el id de un producto por medio de su codigo
 * Externo/*w  w w .j  av  a 2s . co  m*/
 *
 * @param codigoExterno
 * @return
 */
public Integer buscaIdProductoXCodigoExterno(String codigoExterno) {
    Integer idDska = 0;
    try {
        Query query = sesion.createQuery("select p.id from ProductoEntity p where codigoExt = :codExterno ");
        query.setParameter("codExterno", codigoExterno);
        idDska = (Integer) query.uniqueResult();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return idDska;
}