use of com.cloud.api.query.vo.HostTagVO in project cloudstack by apache.
the class QueryManagerImpl method searchForHostTagsInternal.
private Pair<List<HostTagVO>, Integer> searchForHostTagsInternal(ListHostTagsCmd cmd) {
Filter searchFilter = new Filter(HostTagVO.class, "id", Boolean.TRUE, null, null);
SearchBuilder<HostTagVO> sb = _hostTagDao.createSearchBuilder();
// select distinct
sb.select(null, Func.DISTINCT, sb.entity().getId());
SearchCriteria<HostTagVO> sc = sb.create();
// search host tag details by ids
Pair<List<HostTagVO>, Integer> uniqueTagPair = _hostTagDao.searchAndCount(sc, searchFilter);
Integer count = uniqueTagPair.second();
if (count.intValue() == 0) {
return uniqueTagPair;
}
List<HostTagVO> uniqueTags = uniqueTagPair.first();
Long[] vrIds = new Long[uniqueTags.size()];
int i = 0;
for (HostTagVO v : uniqueTags) {
vrIds[i++] = v.getId();
}
List<HostTagVO> vrs = _hostTagDao.searchByIds(vrIds);
return new Pair<List<HostTagVO>, Integer>(vrs, count);
}