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.BancoDadosDAO.java

License:Open Source License

public int countSqlServerOK() {

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

    try {/*from  ww  w .  ja v a 2  s  .co  m*/
        final Criteria criteria = session().createCriteria(BancoDados.class);
        criteria.add(Restrictions.and(Restrictions.eq("vendor", "SQLSERVER"), Restrictions.eq("status", "OK")));
        criteria.setProjection(Projections.rowCount());
        final int count = ((Long) criteria.uniqueResult()).intValue();
        log.fine("[ " + userInfo.getLoggedUsername() + " ] countSqlServerOK -> " + count + " found.");
        return count;

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

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

License:Open Source License

public int countSqlServerNOK() {

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

    try {//from  w ww .j a va 2  s  .com
        final Criteria criteria = session().createCriteria(BancoDados.class);
        criteria.add(Restrictions.and(Restrictions.eq("vendor", "SQLSERVER"),
                Restrictions.or(Restrictions.eq("trClass", "Error"), Restrictions.eq("status", "NOK"))));
        criteria.setProjection(Projections.rowCount());
        final int count = ((Long) criteria.uniqueResult()).intValue();
        log.fine("[ " + userInfo.getLoggedUsername() + " ] countSqlServerNOK() -> " + count + " found.");
        return count;

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

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

License:Open Source License

public int countDB2OK() {

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

    try {/*from w  ww. jav  a2  s. com*/
        final Criteria criteria = session().createCriteria(BancoDados.class);
        criteria.add(Restrictions.and(Restrictions.eq("vendor", "DB2"), Restrictions.eq("status", "OK")));
        criteria.setProjection(Projections.rowCount());
        final int count = ((Long) criteria.uniqueResult()).intValue();
        log.fine("[ " + userInfo.getLoggedUsername() + " ] countDB2OK -> " + count + " found.");
        return count;

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

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

License:Open Source License

public int countDB2NOK() {

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

    try {/*from   ww  w  . j a va  2s  .c  o m*/
        final Criteria criteria = session().createCriteria(BancoDados.class);
        criteria.add(Restrictions.and(Restrictions.eq("vendor", "DB2"),
                Restrictions.or(Restrictions.eq("trClass", "Error"), Restrictions.eq("status", "NOK"))));
        criteria.setProjection(Projections.rowCount());
        final int count = ((Long) criteria.uniqueResult()).intValue();
        log.fine("[ " + userInfo.getLoggedUsername() + " ] countDB2NOK() -> " + count + " found.");
        return count;

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

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

License:Open Source License

public String getMailSender() {

    log.fine("[ " + userInfo.getLoggedUsername() + " ] getMailSender()");
    final Criteria mailFrom = session().createCriteria(Configurations.class);
    final ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("mailFrom"));
    mailFrom.setProjection(proList);
    return (String) mailFrom.uniqueResult();
}

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

License:Open Source License

public String getMailSenderNotLogged() {

    log.fine("[ System ] getMailSenderNotLogged()");

    final Criteria mailFrom = session().createCriteria(Configurations.class);
    final ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("mailFrom"));
    mailFrom.setProjection(proList);
    return (String) mailFrom.uniqueResult();
}

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

License:Open Source License

public boolean sendNotification() {

    log.fine("Invoking sendNotification() database query,");

    final Criteria sendNotification = session().createCriteria(Configurations.class);
    final ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("sendNotification"));
    sendNotification.setProjection(proList);
    return (Boolean) sendNotification.uniqueResult();
}

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

License:Open Source License

public String getSubject() {

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

    final Criteria subject = session().createCriteria(Configurations.class);
    final ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("subject"));
    subject.setProjection(proList);
    return (String) subject.uniqueResult();
}

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

License:Open Source License

public String getSubjectNotLogged() {

    log.fine("[ System ] getSubjectNotLogged()");

    final Criteria subject = session().createCriteria(Configurations.class);
    final ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("subject"));
    subject.setProjection(proList);
    return (String) subject.uniqueResult();
}

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

License:Open Source License

public String getDests() {

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

    final Criteria subject = session().createCriteria(Configurations.class);
    final ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("dests"));
    subject.setProjection(proList);
    return (String) subject.uniqueResult();
}