public int getServerCount() { Query query = PersistenceUtility.createCountQuery(entityManager, Server.QUERY_FIND_ALL); try { long serverCount = (Long) query.getSingleResult(); return (int) serverCount; } catch (NoResultException nre) { log.debug("Could not get count of cloud instances, returning 0..."); return 0; } }
@RequiredPermissions({ @RequiredPermission(Permission.MANAGE_SETTINGS), @RequiredPermission(Permission.MANAGE_INVENTORY) }) public PageList<FailoverListDetails> getFailoverListDetailsByAgentId( Subject subject, int agentId, PageControl pc) { pc.initDefaultOrderingField("fld.ordinal"); Query query = PersistenceUtility.createQueryWithOrderBy( entityManager, FailoverListDetails.QUERY_GET_VIA_AGENT_ID_WITH_SERVERS, pc); Query countQuery = PersistenceUtility.createCountQuery( entityManager, FailoverListDetails.QUERY_GET_VIA_AGENT_ID); query.setParameter("agentId", agentId); countQuery.setParameter("agentId", agentId); @SuppressWarnings("unchecked") List<FailoverListDetails> list = query.getResultList(); long count = (Long) countQuery.getSingleResult(); return new PageList<FailoverListDetails>(list, (int) count, pc); }