Example usage for org.hibernate Criteria setProjection

List of usage examples for org.hibernate Criteria setProjection

Introduction

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

Prototype

public Criteria setProjection(Projection projection);

Source Link

Document

Used to specify that the query results will be a projection (scalar in nature).

Usage

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

License:Open Source License

public int countWindows() {

    log.info("[ " + userInfo.getLoggedUsername() + " ] countWindows()");

    final Criteria criteria = session().createCriteria(Servidores.class);
    criteria.add(Restrictions.eq("SO", "WINDOWS"));
    criteria.setProjection(Projections.rowCount());
    final int count = ((Long) criteria.uniqueResult()).intValue();
    log.fine("[ " + userInfo.getLoggedUsername() + " ] countWindows() -> Found " + count + " servers.");
    return count;
}

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

License:Open Source License

public int countUnix() {

    log.info("[ " + userInfo.getLoggedUsername() + " ] countUnix()");

    final Criteria criteria = session().createCriteria(Servidores.class);
    criteria.add(Restrictions.eq("SO", "UNIX"));
    criteria.setProjection(Projections.rowCount());
    final int count = ((Long) criteria.uniqueResult()).intValue();
    log.fine("[ " + userInfo.getLoggedUsername() + " ] countUnix() -> Found " + count + " servers.");
    return count;
}

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

License:Open Source License

public int countAllServers() {

    log.info("[ " + userInfo.getLoggedUsername() + " ] countAllServers()");

    final Criteria criteria = session().createCriteria(Servidores.class);
    criteria.setProjection(Projections.rowCount());
    final int count = ((Long) criteria.uniqueResult()).intValue();
    log.fine("[ " + userInfo.getLoggedUsername() + " ] countAllServers() -> Found " + count + " servers.");
    return count;
}

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

License:Open Source License

public int countServersOK() {

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

    try {//from   w  ww . ja v  a2s .c  o m
        final Criteria criteria = session().createCriteria(Servidores.class);
        criteria.add(Restrictions.eq("status", "OK"));
        criteria.setProjection(Projections.rowCount());
        final int count = ((Long) criteria.uniqueResult()).intValue();
        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 countServersNOK() {

    log.fine("Invoking countServersNOK()");

    try {//from  ww w  .  jav a  2  s  .c om
        final Criteria criteria = session().createCriteria(Servidores.class);
        criteria.add(Restrictions.or(Restrictions.eq("trClass", "Error"), Restrictions.eq("status", "NOK")));
        criteria.setProjection(Projections.rowCount());
        final int count = ((Long) criteria.uniqueResult()).intValue();
        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 countUnixOK() {

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

    try {/*from   w  w w.  ja  v  a 2  s. c  om*/

        final Criteria criteria = session().createCriteria(Servidores.class);
        criteria.add(Restrictions.and(Restrictions.eq("SO", "UNIX"), Restrictions.eq("status", "OK")));
        criteria.setProjection(Projections.rowCount());
        final int count = ((Long) criteria.uniqueResult()).intValue();
        log.fine("[ " + userInfo.getLoggedUsername() + " ] countUnixOK -> " + 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 countUnixNOK() {

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

    try {//from  w w  w .j ava2  s.c o  m

        final Criteria criteria = session().createCriteria(Servidores.class);
        criteria.add(Restrictions.and(Restrictions.eq("SO", "UNIX"), (Restrictions.eq("trClass", "Error"))));
        criteria.setProjection(Projections.rowCount());
        final int count = ((Long) criteria.uniqueResult()).intValue();
        log.fine("[ " + userInfo.getLoggedUsername() + " ] countUnixNOK -> " + 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 countWindowsOK() {

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

    try {/*w  w  w.  ja v a  2s.  co  m*/

        final Criteria criteria = session().createCriteria(Servidores.class);
        criteria.add(Restrictions.and(Restrictions.eq("SO", "WINDOWS"), Restrictions.eq("status", "OK")));
        criteria.setProjection(Projections.rowCount());
        final int count = ((Long) criteria.uniqueResult()).intValue();
        log.fine("[ " + userInfo.getLoggedUsername() + " ] countWindowsOK -> " + 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 countWindowsNOK() {

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

    try {//from   w  w w. j a v a  2 s . c o m

        final Criteria criteria = session().createCriteria(Servidores.class);
        criteria.add(Restrictions.and(Restrictions.eq("SO", "WINDOWS"), (Restrictions.eq("trClass", "Error"))));
        criteria.setProjection(Projections.rowCount());
        final int count = ((Long) criteria.uniqueResult()).intValue();
        log.fine("[ " + userInfo.getLoggedUsername() + " ] countWindowsNOK -> " + count + " found.");
        return count;

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

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

License:Open Source License

public int countOtherOK() {

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

    try {//from   w  ww .  j a  v  a  2 s. co  m

        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;
    }
}