Example usage for org.hibernate Criteria uniqueResult

List of usage examples for org.hibernate Criteria uniqueResult

Introduction

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

Prototype

public Object uniqueResult() throws HibernateException;

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:br.com.hrstatus.dao.impl.ServersDAO.java

License:Open Source License

public int countOtherOK() {

    log.fine("[ " + userInfo.getLoggedUsername() + " ] countOtherOK()");

    try {/*from   ww w  .  jav a 2s  .c  om*/

        final Criteria criteria = session().createCriteria(Servidores.class);
        criteria.add(Restrictions.ne("SO", "Windows"));
        criteria.add(Restrictions.ne("SO", "Unix"));
        criteria.add(Restrictions.eq("status", "OK"));
        criteria.setProjection(Projections.rowCount());
        final int count = ((Long) criteria.uniqueResult()).intValue();
        log.fine("[ " + userInfo.getLoggedUsername() + " ] countOtherOK -> " + count + " found.");
        return count;

    } catch (Exception e) {
        log.severe("[ " + userInfo.getLoggedUsername() + " ] Error: " + e);
        return 0;
    }
}

From source file:br.com.hrstatus.dao.impl.ServersDAO.java

License:Open Source License

public int countServerWithLog() {

    log.fine("[ " + userInfo.getLoggedUsername() + " ] countServerWithLog()");

    try {/*from  w w w.  java  2s . c  o m*/
        final Criteria criteria = session().createCriteria(Servidores.class);
        criteria.add(Restrictions.not(Restrictions.eq("logDir", "")));
        criteria.setProjection(Projections.rowCount());
        final int count = ((Long) criteria.uniqueResult()).intValue();
        log.fine("[ " + userInfo.getLoggedUsername() + " ] countServerWithLog -> found: " + count);
        return count;
    } catch (Exception e) {
        log.severe("[ " + userInfo.getLoggedUsername() + " ] Error: " + e);
        return 0;
    }
}

From source file:br.com.hrstatus.dao.impl.ServersDAO.java

License:Open Source License

public Servidores getServerLogDir(String hostname) {

    log.fine("[ " + userInfo.getLoggedUsername() + " ] getServerLogDir(String " + hostname + ")");
    final Criteria criteria = session().createCriteria(Servidores.class);
    criteria.add(Restrictions.eq("hostname", hostname));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return (Servidores) criteria.uniqueResult();

}

From source file:br.com.hrstatus.dao.impl.UsersDAO.java

License:Open Source License

public String getPass(String username) {

    log.fine("[ " + userInfo.getLoggedUsername() + " ] getPass(String user)[" + username + "]");

    final Criteria criteria = session().createCriteria(Users.class);
    criteria.add(Restrictions.eq("username", username));
    final ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("password"));
    criteria.setProjection(proList);/*from   w ww.ja  v a2s .co m*/
    return criteria.uniqueResult().toString();
}

From source file:br.com.hrstatus.dao.impl.UsersDAO.java

License:Open Source License

public int searchUser(String username) {

    log.fine("[ " + userInfo.getLoggedUsername() + " ] searchUser(String username)[" + username + "]");
    final Criteria criteria = session().createCriteria(Users.class);
    criteria.add(Restrictions.eq("username", username));
    criteria.setProjection(Projections.rowCount());
    final int count = ((Long) criteria.uniqueResult()).intValue();
    return count;
}

From source file:br.com.hrstatus.dao.impl.UsersDAO.java

License:Open Source License

public int searchUserNotLogged(String username) {

    log.fine("[ System ] searchUser(String username)[" + username + "]");
    final Criteria criteria = session().createCriteria(Users.class);
    criteria.add(Restrictions.eq("username", username));
    criteria.setProjection(Projections.rowCount());
    final int count = ((Long) criteria.uniqueResult()).intValue();
    return count;
}

From source file:br.com.hrstatus.dao.impl.UsersDAO.java

License:Open Source License

public String getMail(String username) {

    log.fine("[ " + userInfo.getLoggedUsername() + " ] getMail(String username)[" + username + "]");
    final Criteria criteria = session().createCriteria(Users.class);
    criteria.add(Restrictions.eq("username", username));
    final ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("mail"));
    criteria.setProjection(proList);/* ww w.ja  v  a  2  s  .c om*/
    return criteria.uniqueResult().toString();
}

From source file:br.com.hrstatus.dao.impl.UsersDAO.java

License:Open Source License

public String getMailNotLogged(String username) {

    log.fine("[ System ] getMail(String username)[" + username + "]");
    final Criteria criteria = session().createCriteria(Users.class);
    criteria.add(Restrictions.eq("username", username));
    final ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("mail"));
    criteria.setProjection(proList);//w  ww. j  av  a  2  s  . c om
    return criteria.uniqueResult().toString();
}

From source file:br.com.hrstatus.dao.impl.UsersDAO.java

License:Open Source License

public int searchUserChangePass(String username) {

    log.fine(/* w ww.  ja v a  2  s .  c  o  m*/
            "[ " + userInfo.getLoggedUsername() + " ] searchUserChangePass(String username)[" + username + "]");
    final Criteria criteria = session().createCriteria(PassExpire.class);
    criteria.add(Restrictions.eq("username", username));
    criteria.setProjection(Projections.rowCount());
    final int count = ((Long) criteria.uniqueResult()).intValue();
    return count;
}

From source file:br.com.hrstatus.dao.impl.UsersDAO.java

License:Open Source License

public int searchUserChangePassNotLogged(String username) {

    log.fine("[ System ] searchUserChangePass(String username)[" + username + "]");
    final Criteria criteria = session().createCriteria(PassExpire.class);
    criteria.add(Restrictions.eq("username", username));
    criteria.setProjection(Projections.rowCount());
    final int count = ((Long) criteria.uniqueResult()).intValue();
    return count;
}