Example usage for org.hibernate Criteria setResultTransformer

List of usage examples for org.hibernate Criteria setResultTransformer

Introduction

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

Prototype

public Criteria setResultTransformer(ResultTransformer resultTransformer);

Source Link

Document

Set a strategy for handling the query results.

Usage

From source file:br.com.gerenciapessoal.repository.Lancamentos.java

@SuppressWarnings("UnusedAssignment")
public Map<Date, BigDecimal> valoresTotaisPorData(Integer numeroDeDias, Conta conta) {
    Session session = manager.unwrap(Session.class);

    Calendar dataInicial = Calendar.getInstance();
    dataInicial = DateUtils.truncate(dataInicial, Calendar.DAY_OF_MONTH);
    dataInicial.add(Calendar.DAY_OF_MONTH, numeroDeDias * -1);

    Map<Date, BigDecimal> resultado = criarMapaVazio(numeroDeDias, dataInicial);

    Criteria criteria = session.createCriteria(Lancamento.class).createAlias("conta", "c");

    criteria.setProjection(Projections.projectionList()
            .add(Projections.sqlGroupProjection("date(data_emissao) as data", "date(data_emissao)",
                    new String[] { "data" }, new Type[] { StandardBasicTypes.DATE }))
            .add(Projections.sum("valorLanca").as("valor")))
            .add(Restrictions.ge("dataEmissao", dataInicial.getTime()));

    if (conta != null) {
        criteria.add(Restrictions.eq("c.id", conta.getId()));
    }/*from ww  w .  j a v  a 2  s.c o m*/
    List<DataValor> valoresPorData = criteria.setResultTransformer(Transformers.aliasToBean(DataValor.class))
            .list();

    for (DataValor dataValor : valoresPorData) {
        resultado.put(dataValor.getData(), dataValor.getValor());
    }

    return resultado;
}

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

License:Open Source License

public Servidores getServerByID(int id) {

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

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

License:Open Source License

@SuppressWarnings("unchecked")
public List<Servidores> listServerByID(int id) {

    log.fine("[ " + userInfo.getLoggedUsername() + " ] listServerByID(int " + id + ")");
    final Criteria criteria = session().createCriteria(Servidores.class);
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return criteria.add(Restrictions.eq("id", id)).list();
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public List<Servidores> listServers() {

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

    final Criteria criteria = session().createCriteria(Servidores.class);
    criteria.addOrder(Order.asc("hostname"));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return criteria.list();
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public List<Servidores> listServersVerActive() {

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

    final Criteria criteria = session().createCriteria(Servidores.class);
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return criteria.add(Restrictions.eq("verify", "SIM")).list();
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public List<Servidores> listServersVerActiveScheduler(String schedulerName) {

    log.info("[ " + schedulerName + " ] listServersVerActiveScheduler(String schedulerName)");

    final Criteria criteria = session().createCriteria(Servidores.class);
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return criteria.add(Restrictions.eq("verify", "SIM")).list();
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public List<Servidores> getServersOK() {

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

    try {//from  w w w  .  j  a v  a2 s .  co m
        final Criteria criteria = session().createCriteria(Servidores.class);
        criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        return criteria.add(Restrictions.eq("status", "OK")).list();

    } catch (Exception e) {
        log.severe("[ " + userInfo.getLoggedUsername() + " ] Error: " + e);
        return new ArrayList<Servidores>();
    }
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public List<Servidores> getServersNOK() {

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

    try {//  w w w .  jav a2s.com
        final Criteria criteria = session().createCriteria(Servidores.class);
        criteria.add(Restrictions.or(Restrictions.eq("trClass", "error"), Restrictions.eq("status", "NOK")));
        criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        return criteria.list();

    } catch (Exception e) {
        log.severe("[ " + userInfo.getLoggedUsername() + " ] Error: " + e);
        return new ArrayList<Servidores>();
    }
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public List<Servidores> getServersNOKVerActive() {

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

    try {/*from  w  w w .  j a v  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.add(Restrictions.eq("verify", "SIM"));
        criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        return criteria.list();

    } catch (Exception e) {
        log.severe("[ " + userInfo.getLoggedUsername() + " ] Error: " + e);
        return new ArrayList<Servidores>();
    }
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public List<Servidores> getSOWindows() {

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

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

        final Criteria criteria = session().createCriteria(Servidores.class);
        criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        return criteria.add(Restrictions.eq("SO", "WINDOWS")).list();

    } catch (Exception e) {
        log.severe("[ " + userInfo.getLoggedUsername() + " ] Error: " + e);
        return new ArrayList<Servidores>();
    }
}