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);
}
Aggregations