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

License:Open Source License

public int countSqlServerOK() {

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

    try {/*  w ww  .jav  a 2  s  .  c  o 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 ava2s  . co m*/
        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   www .  j ava2  s.  c  o  m
        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  w w w  .j  av a  2  s.c om
        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);//from  w  w  w .  j  a  v  a 2s. com
    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);//  www  .j av  a2  s . co  m
    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);/*from w w w. j  a  v a 2s  .c  om*/
    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);//w  ww . j a  v  a  2s. c om
    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);/*  w w  w  .  j  ava  2 s  .  c o m*/
    return (String) subject.uniqueResult();
}