@Override
public List<StoragePoolVO> findLocalStoragePoolsByHostAndTags(long hostId, String[] tags) {
SearchBuilder<StoragePoolVO> hostSearch = createSearchBuilder();
SearchBuilder<StoragePoolHostVO> hostPoolSearch = _hostDao.createSearchBuilder();
SearchBuilder<StoragePoolTagVO> tagPoolSearch = _tagsDao.createSearchBuilder();
;
hostPoolSearch.and("hostId", hostPoolSearch.entity().getHostId(), Op.EQ);
hostSearch.and("scope", hostSearch.entity().getScope(), Op.EQ);
hostSearch.and("removed", hostSearch.entity().getRemoved(), Op.NULL);
hostSearch.and("status", hostSearch.entity().getStatus(), Op.EQ);
hostSearch.join("hostJoin", hostPoolSearch, hostSearch.entity().getId(), hostPoolSearch.entity().getPoolId(), JoinBuilder.JoinType.INNER);
if (!(tags == null || tags.length == 0)) {
tagPoolSearch.and("tag", tagPoolSearch.entity().getTag(), Op.EQ);
hostSearch.join("tagJoin", tagPoolSearch, hostSearch.entity().getId(), tagPoolSearch.entity().getPoolId(), JoinBuilder.JoinType.INNER);
}
SearchCriteria<StoragePoolVO> sc = hostSearch.create();
sc.setJoinParameters("hostJoin", "hostId", hostId);
sc.setParameters("scope", ScopeType.HOST.toString());
sc.setParameters("status", Status.Up.toString());
if (!(tags == null || tags.length == 0)) {
for (String tag : tags) {
sc.setJoinParameters("tagJoin", "tag", tag);
}
}
return listBy(sc);
}