Search in sources :

Example 1 with SearchQuery

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

the class DataAccessServiceImpl method find.

@Override
@Transactional(readOnly = true)
@Monitorable
public SearchResult find(final SearchQuery searchQuery) {
    checkArgument(searchQuery != null, "SearchCriteria must be given");
    Query query = searchQuery.createQuery(hibernateService.getCurrentSession());
    searchQuery.addParameters(query);
    searchQuery.addCacheable(query);
    int totalNumberOfEntities = -1;
    if (searchQuery.hasFirstAndMaxResults()) {
        totalNumberOfEntities = hibernateService.list(query).size();
        searchQuery.addFirstAndMaxResults(query);
    }
    if (totalNumberOfEntities == 0) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("There is no entity matching criteria " + searchQuery);
        }
        return getResultSet(null, totalNumberOfEntities, Collections.emptyList());
    }
    List<?> results = hibernateService.list(query);
    if (totalNumberOfEntities == -1) {
        totalNumberOfEntities = results.size();
        if (totalNumberOfEntities == 0) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("There is no entity matching criteria " + searchQuery);
            }
            return getResultSet(null, totalNumberOfEntities, Collections.emptyList());
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("There are " + totalNumberOfEntities + " entities matching criteria " + searchQuery);
    }
    InternalDataDefinition searchQueryDataDefinition = (InternalDataDefinition) searchQuery.getDataDefinition();
    if (searchQueryDataDefinition == null) {
        searchQueryDataDefinition = hibernateService.resolveDataDefinition(query);
    }
    return getResultSet(searchQueryDataDefinition, totalNumberOfEntities, results);
}
Also used : Query(org.hibernate.Query) SearchQuery(com.qcadoo.model.internal.search.SearchQuery) 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 SearchQuery (com.qcadoo.model.internal.search.SearchQuery)1 Query (org.hibernate.Query)1 Transactional (org.springframework.transaction.annotation.Transactional)1