Example usage for org.hibernate.criterion CriteriaSpecification DISTINCT_ROOT_ENTITY

List of usage examples for org.hibernate.criterion CriteriaSpecification DISTINCT_ROOT_ENTITY

Introduction

In this page you can find the example usage for org.hibernate.criterion CriteriaSpecification DISTINCT_ROOT_ENTITY.

Prototype

ResultTransformer DISTINCT_ROOT_ENTITY

To view the source code for org.hibernate.criterion CriteriaSpecification DISTINCT_ROOT_ENTITY.

Click Source Link

Document

Each row of results is a distinct instance of the root entity

Usage

From source file:com.senacor.core.manager.BaseManagerImpl.java

License:Apache License

@SuppressWarnings("unchecked")
public List<T> findAll() {
    Session session = getSession();//from  w ww . ja  v a2s .c  om
    return session.createCriteria(boClass).setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
            .addOrder(Order.asc("id")).list();
}

From source file:com.senacor.core.manager.BaseManagerImpl.java

License:Apache License

public List<T> find(final T t) {
    Session session = getSession();/*from   w w  w.j  av  a  2 s . c  o m*/
    Criteria criteria = session.createCriteria(boClass);
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(boClass);
    BeanWrapper beanWrapper = new BeanWrapperImpl(t);
    for (PropertyDescriptor descriptor : descriptors) {
        if (!descriptor.getName().equals("class") && !descriptor.getName().equals("id")) {
            Object value = beanWrapper.getPropertyValue(descriptor.getName());
            if (value != null) {
                criteria.add(Restrictions.eq(descriptor.getName(), value));
            }
        }
    }
    criteria.addOrder(Order.asc("id"));
    return criteria.list();
}

From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java

License:Apache License

private DetachedCriteria buildPMRDetachedQuery(List<Long> pipelineIds) {
    DetachedCriteria criteria = DetachedCriteria.forClass(PipelineMaterialRevision.class);
    criteria.add(Restrictions.in("pipelineId", pipelineIds));
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    return criteria;
}

From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java

License:Apache License

private DetachedCriteria buildModificationDetachedQuery(List<Criterion> criteria) {
    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Modification.class);
    Disjunction disjunction = Restrictions.disjunction();
    detachedCriteria.add(disjunction);//  ww w.j a v a 2  s.  com
    for (Criterion criterion : criteria) {
        disjunction.add(criterion);
    }
    detachedCriteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    return detachedCriteria;
}

From source file:com.ust.coppel.incentivos.repository.impl.IncReglasNegocioRepositoryImpl.java

@Transactional
@Override/*  w  w w. j a  v a2  s  . c o m*/
public List<IncReglasNegocio> findAll(IncGruposReglas grupos) {
    Session session = sessionFactory.getCurrentSession();

    Criteria criteria = session.createCriteria(IncReglasNegocio.class);

    criteria.add(Restrictions.eq("incGruposReglas.iduGrupo", grupos.getIduGrupo()));
    criteria.add(Restrictions.ne("clvEstatus", 9));
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List<IncReglasNegocio> aux = criteria.list();

    return aux;
}

From source file:com.ust.coppel.incentivos.repository.impl.IncVariablesGlobalesRepositoryImpl.java

@Transactional
@Override//w ww .java2s . co  m
public List<IncVariablesGlobales> findAll(IncPaqueteReglas paq_) {
    Session session = sessionFactory.getCurrentSession();
    Criteria criteria = session.createCriteria(IncVariablesGlobales.class);

    criteria.add(Restrictions.eq("incPaqueteReglas.iduPaquete", paq_.getIduPaquete()));
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    List<IncVariablesGlobales> incVentasPorGerentesProgc = criteria.list();

    return incVentasPorGerentesProgc;
}

From source file:com.vmware.appfactory.application.dao.AppBuildRequestDaoImpl.java

License:Open Source License

/**
 * Get the list of buildRequests for a given app.
 *
 * @param appId/*ww w  .jav a 2s  .c  om*/
 * @return
 */
@Override
@SuppressWarnings("unchecked")
public List<AppBuildRequest> findBuildRequestForApp(Long appId) {
    if (appId == null) {
        return Collections.EMPTY_LIST;
    }
    Criteria criteria = getCurrentSession().createCriteria(AppBuildRequest.class);
    criteria.add(Restrictions.eq("_application._id", appId));

    // Return distinct root entities.
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    return criteria.list();
}

From source file:com.vmware.appfactory.common.base.AbstractDaoImpl.java

License:Open Source License

/**
 * Helper method that simplifies data loopups based on a criterion.
 *
 * @param criterion/*from w w  w .j av  a  2 s.co  m*/
 * @return
 */
@SuppressWarnings("unchecked")
protected List<T> findByCriterion(Criterion criterion) {
    Criteria criteria = getCurrentSession().createCriteria(_class);
    if (criterion != null) {
        criteria.add(criterion);
    }

    // Return distinct root entities. If not set, we can get duplicate rows.
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    return criteria.list();
}

From source file:com.vmware.appfactory.common.base.AbstractDaoImpl.java

License:Open Source License

/**
 * Returns the number of records matching the given criterion.
 *
 * @param criterion   condition to match
 * @return     a value from 0 to the number or rows in the table
 *///from   w  w w  . j a va2 s  .co  m
protected long countByCriterion(Criterion criterion) {
    Criteria criteria = getCurrentSession().createCriteria(_class);
    if (criterion != null) {
        criteria.add(criterion);
    }

    // Return distinct root entities. If not set, we can get duplicate rows.
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    criteria.setProjection(Projections.rowCount());
    return (Long) criteria.uniqueResult();
}

From source file:com.wwinsoft.modules.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * ?DetachedCriteria,./*from www .  ja  va2 s  .  com*/
 */
protected DetachedCriteria buildDetachedCriteriaByPropertyFilter(final List<PropertyFilter> filters,
        ResolveAlias ra) {
    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(entityClass);
    if (filters != null || filters.size() > 0) {
        ra.setDca(detachedCriteria);
        for (PropertyFilter propertyFilter : filters) {
            String propertyName = propertyFilter.getPropertyName();
            String realPropertyName = getRealPropertyName(propertyName, ra);
            detachedCriteria.add(buildCriterion(realPropertyName, propertyFilter.getMatchValue(),
                    propertyFilter.getMatchType()));
        }
    }
    // ??
    detachedCriteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    return detachedCriteria;
}