Example usage for org.hibernate.criterion Projections groupProperty

List of usage examples for org.hibernate.criterion Projections groupProperty

Introduction

In this page you can find the example usage for org.hibernate.criterion Projections groupProperty.

Prototype

public static PropertyProjection groupProperty(String propertyName) 

Source Link

Document

A grouping property value projection

Usage

From source file:com.qcadoo.model.api.search.SearchProjections.java

License:Open Source License

/**
 * Creates projection which add given field to the "GROUP BY" clause.
 * /*from  w  ww. j av  a  2 s . c o  m*/
 * @param field
 *            field
 * @return projection
 */
public static SearchProjection groupField(final String field) {
    return new SearchProjectionImpl(Projections.groupProperty(field));
}

From source file:com.reignite.query.StructuredQuery.java

License:Open Source License

private void processGroups() {
    if (groups.size() > 0) {
        if (projections == null) {
            projections = Projections.projectionList();
        }//from  www  .jav a 2s  .  com
        for (String group : groups) {
            projections.add(Projections.groupProperty(group));
            expectedFields.add(group);
            if (hasJoin) {
                for (Join join : joins) {
                    join.addExpectedField(group);
                }
            }
        }
    }
}

From source file:com.romeikat.datamessie.core.base.dao.impl.CrawlingDao.java

License:Open Source License

public List<CrawlingDto> getAsDtos(final SharedSessionContract ssc, final Long projectId) {
    // Query: Crawling
    final EntityWithIdQuery<Crawling> crawlingQuery = new EntityWithIdQuery<>(Crawling.class);
    crawlingQuery.addRestriction(Restrictions.eqOrIsNull("projectId", projectId));
    crawlingQuery.addOrder(Order.desc("started"));
    crawlingQuery.setResultTransformer(new AliasToBeanResultTransformer(CrawlingDto.class));

    // Done//from w  ww . j  av a2 s  .com
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("id"), "id");
    projectionList.add(Projections.property("started"), "started");
    projectionList.add(Projections.property("completed"), "completed");
    @SuppressWarnings("unchecked")
    final List<CrawlingDto> dtos = (List<CrawlingDto>) crawlingQuery.listForProjection(ssc, projectionList);

    // Set duration
    setDurationForDtos(dtos);

    return dtos;
}

From source file:com.romeikat.datamessie.core.base.dao.impl.CrawlingDao.java

License:Open Source License

public List<CrawlingOverviewDto> getAsOverviewDtos(final SharedSessionContract ssc, final Long projectId,
        final Long first, final Long count) {
    // Query: Crawling
    final EntityWithIdQuery<Crawling> crawlingQuery = new EntityWithIdQuery<>(Crawling.class);
    crawlingQuery.addRestriction(Restrictions.eqOrIsNull("projectId", projectId));
    crawlingQuery.setFirstResult(first == null ? null : first.intValue());
    crawlingQuery.setMaxResults(count == null ? null : count.intValue());
    crawlingQuery.addOrder(Order.desc("started"));
    crawlingQuery.setResultTransformer(new AliasToBeanResultTransformer(CrawlingOverviewDto.class));

    // Done/*  w  w w .  j av  a 2s  . c  o m*/
    final ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.groupProperty("id"), "id");
    projectionList.add(Projections.property("started"), "started");
    projectionList.add(Projections.property("completed"), "completed");
    @SuppressWarnings("unchecked")
    final List<CrawlingOverviewDto> dtos = (List<CrawlingOverviewDto>) crawlingQuery.listForProjection(ssc,
            projectionList);

    // Set duration
    setDurationForOverviewDtos(dtos);

    return dtos;
}

From source file:com.segundo.piso.daos.impl.DAOReportImpl.java

@Override
@Transactional//from  ww w .jav  a 2 s  . c o  m
public List<ReporteAlumno> getStudentsByExpiredMovement(int clasesRestantes) {
    System.out.println(sessionFactory);
    StringBuilder restriction = new StringBuilder();
    restriction.append("date_add(movimiento1_.fecha_inicio, interval 31 day) > curdate() ").append(
            "and date_add(movimiento1_.fecha_inicio, interval 31 day) < date_add(current_date(), interval 10 day)")
            .append("and movimiento1_.id_movimiento = asistencia2_.id_movimiento ");

    return this.sessionFactory.getCurrentSession().createCriteria(Alumno.class, "alumno")
            .createAlias("alumno.movimientoList", "movimiento")
            .createAlias("alumno.asistenciaList", "asistencia").createAlias("movimiento.idEvento", "evento")
            .setProjection(Projections.projectionList().add(Projections.property("alumno.codigo"), "codigo")
                    .add(Projections.property("alumno.nombre"), "nombre")
                    .add(Projections.min("asistencia.diasRestantes"), "clasesRestantes")
                    .add(Projections.max("movimiento.idMovimiento"))
                    .add(Projections.property("alumno.idAlumno"), "idAlumno")
                    .add(Projections.max("movimiento.fechaInicio"), "fecha")
                    .add(Projections.groupProperty("alumno.idAlumno")))
            .add(Restrictions.sqlRestriction(restriction.toString()))
            .add(Restrictions.eq("movimiento.activo", true)).add(Restrictions.gt("evento.diasMes", 1))
            .setResultTransformer(Transformers.aliasToBean(ReporteAlumno.class))
            .addOrder(Order.desc("asistencia.diasRestantes")).list();
}

From source file:com.silverpeas.mailinglist.service.model.dao.MessageDaoImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Activity> listActivity(String componentId) {
    Criteria criteria = getSession().createCriteria(Message.class);
    criteria.add(Restrictions.eq("componentId", componentId));
    criteria.add(Restrictions.eq("moderated", Boolean.TRUE));
    criteria.setProjection(Projections.projectionList().add(Projections.rowCount(), "nb")
            .add(Projections.groupProperty("year"), "year").add(Projections.groupProperty("month"), "month"));
    List result = criteria.list();
    List<Activity> activities;
    if (result != null && !result.isEmpty()) {
        activities = new ArrayList<Activity>(result.size());
        for (Object aResult : result) {
            Object[] line = (Object[]) aResult;
            Activity activity = new Activity();
            activity.setNbMessages(((Long) line[0]).intValue());
            activity.setYear((Integer) line[1]);
            activity.setMonth((Integer) line[2]);
            activities.add(activity);/*from   w w w . j  a  v a2s. c  o m*/
        }
    } else {
        activities = new ArrayList<Activity>();
    }
    return activities;
}

From source file:com.smartitengineering.dao.impl.hibernate.AbstractDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
private void processCriteria(Criteria criteria, String element, QueryParameter parameter) {
    switch (parameter.getParameterType()) {
    case PARAMETER_TYPE_PROPERTY: {
        criteria.add(getCriterion(element, parameter));
        return;//  ww w  .  j av a2  s.c o  m
    }
    case PARAMETER_TYPE_ORDER_BY: {
        final Order order;
        SimpleNameValueQueryParameter<com.smartitengineering.dao.common.queryparam.Order> queryParameter = QueryParameterCastHelper.SIMPLE_PARAM_HELPER
                .cast(parameter);
        com.smartitengineering.dao.common.queryparam.Order requestedOrder = queryParameter.getValue();
        switch (requestedOrder) {
        case ASC: {
            order = Order.asc(element);
            break;
        }
        case DESC: {
            order = Order.desc(element);
            break;
        }
        default: {
            order = null;
            break;
        }
        }
        if (order != null) {
            criteria.addOrder(order);
        }
        return;
    }
    case PARAMETER_TYPE_MAX_RESULT: {
        ValueOnlyQueryParameter<Integer> queryParameter = QueryParameterCastHelper.VALUE_PARAM_HELPER
                .cast(parameter);
        criteria.setMaxResults(queryParameter.getValue());
        return;
    }
    case PARAMETER_TYPE_FIRST_RESULT: {
        ValueOnlyQueryParameter<Integer> queryParameter = QueryParameterCastHelper.VALUE_PARAM_HELPER
                .cast(parameter);
        criteria.setFirstResult(queryParameter.getValue());
        return;
    }
    case PARAMETER_TYPE_DISJUNCTION: {
        processDisjunction(criteria, parameter);
        return;
    }
    case PARAMETER_TYPE_CONJUNCTION: {
        processConjunction(criteria, parameter);
        return;
    }
    case PARAMETER_TYPE_NESTED_PROPERTY: {
        processNestedParameter(criteria, element, parameter);
        return;
    }
    case PARAMETER_TYPE_COUNT: {
        final Projection countProjection = Projections.count(element);
        setProjection(criteria, countProjection);
        return;
    }
    case PARAMETER_TYPE_ROW_COUNT: {
        final Projection rowCount = Projections.rowCount();
        setProjection(criteria, rowCount);
        return;
    }
    case PARAMETER_TYPE_SUM: {
        final AggregateProjection sum = Projections.sum(element);
        setProjection(criteria, sum);
        return;
    }
    case PARAMETER_TYPE_MAX: {
        final AggregateProjection max = Projections.max(element);
        setProjection(criteria, max);
        return;
    }
    case PARAMETER_TYPE_MIN: {
        final AggregateProjection min = Projections.min(element);
        setProjection(criteria, min);
        return;
    }
    case PARAMETER_TYPE_AVG: {
        final AggregateProjection avg = Projections.avg(element);
        setProjection(criteria, avg);
        return;
    }
    case PARAMETER_TYPE_GROUP_BY: {
        final PropertyProjection groupProperty = Projections.groupProperty(element);
        setProjection(criteria, groupProperty);
        return;
    }
    case PARAMETER_TYPE_COUNT_DISTINCT: {
        final CountProjection countDistinct = Projections.countDistinct(element);
        setProjection(criteria, countDistinct);
        return;
    }
    case PARAMETER_TYPE_DISTINCT_PROP: {
        final Projection distinct = Projections.distinct(Projections.property(element));
        setProjection(criteria, distinct);
        return;
    }
    case PARAMETER_TYPE_UNIT_PROP: {
        final PropertyProjection property = Projections.property(element);
        setProjection(criteria, property);
        return;
    }
    }
}

From source file:com.square.adherent.noyau.dao.implementations.contrat.ContratDaoImpl.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public List<String> getListeContratsCollectifsByCriteres(ContratCollectifCriteresDto criteres) {
    // Cration du critre
    final Criteria crit = createCriteria(Contrat.class);
    // Projection sur la colonne contrat
    crit.setProjection(Projections.groupProperty("numeroContrat"));
    // Critres de recherche
    if (criteres.getUidEntreprise() != null) {
        crit.add(Restrictions.eq("uidSouscripteur", criteres.getUidEntreprise()));
    }// ww  w.j a va 2s. c o  m
    crit.add(Restrictions.ilike("identifiantExterieur", "%groupe%"));
    // Tri sur le contrat
    crit.addOrder(Order.asc("numeroContrat"));
    return (ArrayList<String>) crit.list();
}

From source file:com.square.core.dao.implementations.CommuneDaoImplementation.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//  w w w.  java2  s .com
public List<IdentifiantLibelleCodePostalCommuneDto> rechercherCodesPostauxCommunes(
        DimensionCriteresRechercheDto criteres) {
    final Criteria criteria = createCriteria(CodePostalCommune.class);
    criteria.createAlias("commune", "commune");
    criteria.createAlias("codePostal", "codePostal");
    criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("commune.id"))
            .add(Projections.groupProperty("commune.libelle")).add(Projections.groupProperty("codePostal.id"))
            .add(Projections.groupProperty("codePostal.codePostal"))
            .add(Projections.groupProperty("commune.ordre"))
            .add(Projections.groupProperty("codePostal.ordre")));

    // Critre sur l'identifiant
    if (criteres.getId() != null) {
        criteria.add(Restrictions.eq("commune.id", criteres.getId()));
    }
    // Critre sur le libelle
    if (criteres.getLibelle() != null && !criteres.getLibelle().equals("")) {
        criteria.add(Restrictions.ilike("codePostal.codePostal", criteres.getLibelle().toLowerCase() + "%"));
    }
    // Critre sur la visibilit
    if (criteres.getVisible() != null) {
        criteria.add(Restrictions.eq("commune.visible", criteres.getVisible()));
        criteria.add(Restrictions.eq("codePostal.visible", criteres.getVisible()));
    }
    // Maxresults
    if (criteres.getMaxResults() != null) {
        criteria.setFirstResult(0);
        criteria.setMaxResults(criteres.getMaxResults());
    }
    // Ordonner les lments
    criteria.addOrder(Order.asc("commune.ordre"));
    criteria.addOrder(Order.asc("commune.libelle"));
    criteria.addOrder(Order.asc("codePostal.ordre"));

    final List<Object[]> resultat = criteria.list();
    final List<IdentifiantLibelleCodePostalCommuneDto> list = new ArrayList<IdentifiantLibelleCodePostalCommuneDto>();
    for (Object[] row : resultat) {
        final IdentifiantLibelleCodePostalCommuneDto identifiantLibelleCodePostalCommuneDto = new IdentifiantLibelleCodePostalCommuneDto();
        identifiantLibelleCodePostalCommuneDto.setIdCodePostal((Long) row[2]);
        identifiantLibelleCodePostalCommuneDto.setIdCommune((Long) row[0]);
        identifiantLibelleCodePostalCommuneDto.setLibelleCodePostal(String.valueOf(row[3]));
        identifiantLibelleCodePostalCommuneDto.setLibelleCommune(String.valueOf(row[1]));
        list.add(identifiantLibelleCodePostalCommuneDto);
    }
    return list;
}

From source file:com.square.core.dao.implementations.CommuneDaoImplementation.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from ww  w .  jav a  2  s.  c o  m*/
public List<IdentifiantLibelleCodePostalCommuneDto> rechercherCommunesCodesPostaux(
        DimensionCriteresRechercheDto criteres) {
    final Criteria criteria = createCriteria(CodePostalCommune.class);
    criteria.createAlias("commune", "commune");
    criteria.createAlias("codePostal", "codePostal");
    criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("commune.id"))
            .add(Projections.groupProperty("commune.libelle")).add(Projections.groupProperty("codePostal.id"))
            .add(Projections.groupProperty("codePostal.codePostal"))
            .add(Projections.groupProperty("commune.ordre"))
            .add(Projections.groupProperty("codePostal.ordre")));

    // Critre sur l'identifiant
    if (criteres.getId() != null) {
        criteria.add(Restrictions.eq("commune.id", criteres.getId()));
    }
    // Critre sur le libelle
    if (criteres.getLibelle() != null && !criteres.getLibelle().equals("")) {
        criteria.add(Restrictions.ilike("commune.libelle", criteres.getLibelle().toLowerCase() + "%"));
    }
    // Critre sur la visibilit
    if (criteres.getVisible() != null) {
        criteria.add(Restrictions.eq("commune.visible", criteres.getVisible()));
        criteria.add(Restrictions.eq("codePostal.visible", criteres.getVisible()));
    }
    // Maxresults
    if (criteres.getMaxResults() != null) {
        criteria.setFirstResult(0);
        criteria.setMaxResults(criteres.getMaxResults());
    }
    // Ordonner les lments
    criteria.addOrder(Order.asc("commune.ordre"));
    criteria.addOrder(Order.asc("commune.libelle"));
    criteria.addOrder(Order.asc("codePostal.ordre"));

    final List<Object[]> resultat = criteria.list();
    final List<IdentifiantLibelleCodePostalCommuneDto> list = new ArrayList<IdentifiantLibelleCodePostalCommuneDto>();
    for (Object[] row : resultat) {
        final IdentifiantLibelleCodePostalCommuneDto identifiantLibelleCodePostalCommuneDto = new IdentifiantLibelleCodePostalCommuneDto();
        identifiantLibelleCodePostalCommuneDto.setIdCodePostal((Long) row[2]);
        identifiantLibelleCodePostalCommuneDto.setIdCommune((Long) row[0]);
        identifiantLibelleCodePostalCommuneDto.setLibelleCodePostal(String.valueOf(row[3]));
        identifiantLibelleCodePostalCommuneDto.setLibelleCommune(String.valueOf(row[1]));
        list.add(identifiantLibelleCodePostalCommuneDto);
    }
    return list;
}