Search in sources :

Example 1 with SearchCriteria

use of com.qcadoo.model.internal.search.SearchCriteria in project qcadoo by qcadoo.

the class DataAccessServiceImpl method find.

@Override
@Transactional(readOnly = true)
@Monitorable
public SearchResult find(final SearchCriteria searchCriteria) {
    checkArgument(searchCriteria != null, "SearchCriteria must be given");
    Criteria criteria = searchCriteria.createCriteria(hibernateService.getCurrentSession());
    int totalNumberOfEntities = hibernateService.getTotalNumberOfEntities(criteria);
    if (totalNumberOfEntities == 0) {
        LOG.debug("There is no entity matching criteria " + searchCriteria);
        return getResultSet(null, totalNumberOfEntities, Collections.emptyList());
    }
    searchCriteria.addFirstAndMaxResults(criteria);
    searchCriteria.addOrders(criteria);
    searchCriteria.addCacheable(criteria);
    List<?> results = hibernateService.list(criteria);
    if (LOG.isDebugEnabled()) {
        LOG.debug("There are " + totalNumberOfEntities + " entities matching criteria " + searchCriteria);
    }
    InternalDataDefinition searchQueryDataDefinition = (InternalDataDefinition) searchCriteria.getDataDefinition();
    if (searchQueryDataDefinition == null) {
        searchQueryDataDefinition = hibernateService.resolveDataDefinition(criteria);
    }
    return getResultSet(searchQueryDataDefinition, totalNumberOfEntities, results);
}
Also used : SearchCriteria(com.qcadoo.model.internal.search.SearchCriteria) Criteria(org.hibernate.Criteria) InternalDataDefinition(com.qcadoo.model.internal.api.InternalDataDefinition) Monitorable(com.qcadoo.model.api.aop.Monitorable) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Monitorable (com.qcadoo.model.api.aop.Monitorable)1 InternalDataDefinition (com.qcadoo.model.internal.api.InternalDataDefinition)1 SearchCriteria (com.qcadoo.model.internal.search.SearchCriteria)1 Criteria (org.hibernate.Criteria)1 Transactional (org.springframework.transaction.annotation.Transactional)1