List of usage examples for org.hibernate Query setMaxResults
@Override
Query<R> setMaxResults(int maxResult);
From source file:com.abiquo.server.core.infrastructure.network.IpPoolManagementDAO.java
License:Open Source License
public List<IpPoolManagement> findExternalIpsByVlan(final Integer entId, final Integer datacenterLimitId, final Integer vlanId, Integer startwith, final Integer limit, final String filter, final OrderByEnum orderByEnum, final Boolean descOrAsc, final Boolean onlyAvailable) { // TODO Auto-generated method stub Query finalQuery = getSession().createQuery(BY_EXTERNAL_VLAN + " " + defineOnlyAvailableFilter(onlyAvailable) + defineOrderBy(orderByEnum, descOrAsc)); finalQuery.setParameter("ent_id", entId); finalQuery.setParameter("dc_limit_id", datacenterLimitId); finalQuery.setParameter("vlan_id", vlanId); finalQuery.setParameter("filterLike", filter == null || filter.isEmpty() ? "%" : "%" + filter + "%"); // Check if the page requested is bigger than the last one Integer totalResults = finalQuery.list().size(); if (limit != null) { finalQuery.setMaxResults(limit); }/* w ww . j a v a 2s .c om*/ if (startwith >= totalResults) { startwith = totalResults - limit; } finalQuery.setFirstResult(startwith); finalQuery.setMaxResults(limit); PagedList<IpPoolManagement> ipList = new PagedList<IpPoolManagement>(finalQuery.list()); ipList.setTotalResults(totalResults); ipList.setPageSize(limit); ipList.setCurrentElement(startwith); return ipList; }
From source file:com.abiquo.server.core.infrastructure.network.IpPoolManagementDAO.java
License:Open Source License
public List<IpPoolManagement> findIpsByEnterprise(final Integer entId, Integer firstElem, final Integer numElem, final String has, final IpPoolManagement.OrderByEnum orderby, final Boolean asc) { // Get the query that counts the total results. Query finalQuery = getSession().createQuery(BY_ENT + " " + defineOrderBy(orderby, asc)); finalQuery.setParameter("ent_id", entId); finalQuery.setParameter("filterLike", has.isEmpty() ? "%" : "%" + has + "%"); // Check if the page requested is bigger than the last one Integer totalResults = finalQuery.list().size(); if (firstElem >= totalResults) { firstElem = totalResults - numElem; }/*from w ww.j a v a2 s. c o m*/ // Get the list of elements finalQuery.setFirstResult(firstElem); finalQuery.setMaxResults(numElem); PagedList<IpPoolManagement> ipList = new PagedList<IpPoolManagement>(finalQuery.list()); ipList.setTotalResults(totalResults); ipList.setPageSize(numElem); ipList.setCurrentElement(firstElem); return ipList; }
From source file:com.abiquo.server.core.infrastructure.network.IpPoolManagementDAO.java
License:Open Source License
/** * Return all the IPs from a VLAN filtered by a string and saying how many elements do you want * and the first element to retrieve//from ww w. ja v a2 s . c o m * * @param network {@link Network} network entity that stores all the VLANs * @param vlanId identifier of the VLAN to search into. * @param has to filter the search * @param firstElem firstelement to retrieve. * @param numeElem to retrieve. * @return all the {@link IpPoolManagement} ips. */ public List<IpPoolManagement> findIpsByNetwork(final Network network, final Integer vlanId, final String has, Integer firstElem, final Integer numElem) { Query finalQuery = getSession().createQuery(BY_NETWORK); finalQuery.setParameter("net_id", network.getId()); finalQuery.setParameter("vlan_id", vlanId); finalQuery.setParameter("filterLike", has == null || has.isEmpty() ? "%" : "%" + has + "%"); // Check if the page requested is bigger than the last one Integer totalResults = finalQuery.list().size(); if (numElem != null) { finalQuery.setMaxResults(numElem); } if (firstElem >= totalResults) { firstElem = totalResults - 1; finalQuery.setMaxResults(1); } finalQuery.setFirstResult(firstElem); PagedList<IpPoolManagement> ipList = new PagedList<IpPoolManagement>(finalQuery.list()); ipList.setTotalResults(totalResults); ipList.setPageSize(numElem); ipList.setCurrentElement(firstElem); return ipList; }
From source file:com.abiquo.server.core.infrastructure.network.IpPoolManagementDAO.java
License:Open Source License
/** * Find all the IpPoolManagement created and available by a vLAN with filter options * /*from ww w . j a v a 2 s.co m*/ * @param vdcId identifier of the virtual datacenter. * @param vlanId identifier of the vlan. * @param firstElem first element to retrieve. * @param numElem number of elements to retrieve. * @param has filter %like% * @param orderby ordering filter. {@see IpPoolManagement.OrderByEnum} * @param asc ordering filter, ascending = true, descending = false. * @return List of IP addresses that pass the filter. */ public List<IpPoolManagement> findIpsByPrivateVLANAvailableFiltered(final Integer vdcId, final Integer vlanId, Integer firstElem, final Integer numElem, final String has, final IpPoolManagement.OrderByEnum orderby, final Boolean asc) { // Get the query that counts the total results. Query finalQuery = getSession() .createQuery(BY_VLAN + " " + defineFilterAvailable() + defineOrderBy(orderby, asc)); finalQuery.setParameter("vdc_id", vdcId); finalQuery.setParameter("vlan_id", vlanId); finalQuery.setParameter("filterLike", has.isEmpty() ? "%" : "%" + has + "%"); // Check if the page requested is bigger than the last one Integer totalResults = finalQuery.list().size(); if (firstElem >= totalResults) { firstElem = totalResults - numElem; } finalQuery.setFirstResult(firstElem); finalQuery.setMaxResults(numElem); PagedList<IpPoolManagement> ipList = new PagedList<IpPoolManagement>(finalQuery.list()); ipList.setTotalResults(totalResults); ipList.setPageSize(numElem); ipList.setCurrentElement(firstElem); return ipList; }
From source file:com.abiquo.server.core.infrastructure.network.IpPoolManagementDAO.java
License:Open Source License
/** * Find next IpPoolManagement created and available by a vLAN with filter options * //from ww w . j a v a 2 s.com * @param vlanId identifier of the vlan. * @param excludedIps ips excluded from result if exists * @return next available IP address. */ public IpPoolManagement findNextIpAvailable(final Integer vlanId, final String... excludedIps) { // Get the query that counts the total results. Query query = getSession() .createQuery(BY_VLAN_NEXT_AVAILABLE + defineOrderBy(IpPoolManagement.OrderByEnum.IP, Boolean.TRUE)); query.setMaxResults(1); query.setParameter("vlan_id", vlanId); // query.setLockMode("next_ip", LockMode.PESSIMISTIC_WRITE); if (excludedIps != null && excludedIps.length != 0) { query.setParameterList("excludedIp", Arrays.asList(excludedIps)); } else { query.setString("excludedIp", null); } List<IpPoolManagement> result = query.list(); return result.isEmpty() ? null : result.get(0); }
From source file:com.abiquo.server.core.infrastructure.network.IpPoolManagementDAO.java
License:Open Source License
/** * Find next IpPoolManagement created and available by a vLAN with filter options * //from w w w . ja va 2 s . co m * @param vlanId identifier of the vlan. * @param excludedIps ips excluded from result if exists * @return next available IP address. */ public IpPoolManagement findNextExternalIpAvailable(final Integer vlanId, final String... excludedIps) { // Get the query that counts the total results. Query query = getSession().createQuery( BY_VLAN_NEXT_EXTERNAL_IP_AVAILABLE + defineOrderBy(IpPoolManagement.OrderByEnum.IP, Boolean.TRUE)); query.setMaxResults(1); query.setParameter("vlan_id", vlanId); // query.setLockMode("next_ip", LockMode.PESSIMISTIC_WRITE); if (excludedIps != null && excludedIps.length != 0) { query.setParameterList("excludedIp", Arrays.asList(excludedIps)); } else { query.setString("excludedIp", null); } List<IpPoolManagement> result = query.list(); return result.isEmpty() ? null : result.get(0); }
From source file:com.abiquo.server.core.infrastructure.network.IpPoolManagementDAO.java
License:Open Source License
/** * Find all the IpPoolManagement created by a vLAN with filter options * //from w w w . j a va 2 s .c o m * @param vdcId identifier of the virtual datacenter. * @param vlanId identifier of the vlan. * @param firstElem first element to retrieve. * @param numElem number of elements to retrieve. * @param has filter %like% * @param orderby ordering filter. {@see IpPoolManagement.OrderByEnum} * @param asc ordering filter, ascending = true, descending = false. * @return List of IP addresses that pass the filter. */ public List<IpPoolManagement> findIpsByPrivateVLANFiltered(final Integer vdcId, final Integer vlanId, Integer firstElem, final Integer numElem, final String has, final IpPoolManagement.OrderByEnum orderby, final Boolean asc, final Boolean freeIps) { // Get the query that counts the total results. Query finalQuery; if (!freeIps) { finalQuery = getSession().createQuery(BY_VLAN + " " + defineOrderBy(orderby, asc)); } else { finalQuery = getSession().createQuery( BY_VLAN_WITHOUT_USED_IPS + " " + defineFilterAvailable() + defineOrderBy(orderby, asc)); } finalQuery.setParameter("vdc_id", vdcId); finalQuery.setParameter("vlan_id", vlanId); finalQuery.setParameter("filterLike", has.isEmpty() ? "%" : "%" + has + "%"); // Check if the page requested is bigger than the last one Integer totalResults = finalQuery.list().size(); if (firstElem >= totalResults) { firstElem = totalResults - numElem; } finalQuery.setFirstResult(firstElem); finalQuery.setMaxResults(numElem); PagedList<IpPoolManagement> ipList = new PagedList<IpPoolManagement>(finalQuery.list()); ipList.setTotalResults(totalResults); ipList.setPageSize(numElem); ipList.setCurrentElement(firstElem); return ipList; }
From source file:com.abiquo.server.core.infrastructure.network.IpPoolManagementDAO.java
License:Open Source License
public List<IpPoolManagement> findIpsByVdc(final Integer vdcId, Integer firstElem, final Integer numElem, final String has, final IpPoolManagement.OrderByEnum orderby, final Boolean asc) { // Get the query that counts the total results. Query finalQuery = getSession().createQuery(BY_VDC + " " + defineOrderBy(orderby, asc)); finalQuery.setParameter("vdc_id", vdcId); finalQuery.setParameter("filterLike", has.isEmpty() ? "%" : "%" + has + "%"); // Check if the page requested is bigger than the last one Integer totalResults = finalQuery.list().size(); if (firstElem == null) { firstElem = 0;// w ww . j a va 2 s. co m } if (firstElem >= totalResults) { firstElem = totalResults - numElem; } finalQuery.setFirstResult(firstElem); finalQuery.setMaxResults(numElem); PagedList<IpPoolManagement> ipList = new PagedList<IpPoolManagement>(finalQuery.list()); ipList.setTotalResults(totalResults); ipList.setPageSize(numElem); ipList.setCurrentElement(firstElem); return ipList; }
From source file:com.abiquo.server.core.infrastructure.network.IpPoolManagementDAO.java
License:Open Source License
/** * Return all the public IPS defined into a Datacenter. * //from w w w. j a v a 2 s. c o m * @param datacenterId identifier of the datacenter. * @param startwith first element to retrieve. * @param limit number of elements to retrieve. * @param filter filter query. * @param orderByEnum the way we order the query. * @param descOrAsc if the order is ascendant or descendant. * @return the list of matching {@link IpPoolManagement} object. */ public List<IpPoolManagement> findPublicIpsByDatacenter(final Integer datacenterId, Integer startwith, final Integer limit, final String filter, final OrderByEnum orderByEnum, final Boolean descOrAsc, NetworkType type, final Boolean all) { NetworkType type2 = type; String query = BY_DATACENTER; if (type != null) { if (type.equals(NetworkType.EXTERNAL_UNMANAGED)) { type = NetworkType.EXTERNAL; // to check. unecessary because with unmanaged vlan doesn't exist ips type2 = NetworkType.UNMANAGED; } // Get the query that counts the total results. query = BY_DATACENTER + " AND (vlan.type = :type OR vlan.type = :type2 )"; } Query finalQuery = getSession() .createQuery(query + " " + defineAllFilter(all) + " " + defineOrderBy(orderByEnum, descOrAsc)); finalQuery.setParameter("datacenter_id", datacenterId); finalQuery.setParameter("filterLike", filter == null || filter.isEmpty() ? "%" : "%" + filter + "%"); if (type != null) { finalQuery.setParameter("type", type); finalQuery.setParameter("type2", type2); } // Check if the page requested is bigger than the last one Integer totalResults = finalQuery.list().size(); if (limit != null) { finalQuery.setMaxResults(limit); } if (startwith >= totalResults) { startwith = totalResults - limit; } finalQuery.setFirstResult(startwith); finalQuery.setMaxResults(limit); PagedList<IpPoolManagement> ipList = new PagedList<IpPoolManagement>(finalQuery.list()); ipList.setTotalResults(totalResults); ipList.setPageSize(limit); ipList.setCurrentElement(startwith); return ipList; }
From source file:com.abiquo.server.core.infrastructure.network.IpPoolManagementDAO.java
License:Open Source License
public List<IpPoolManagement> findPublicIpsByEnterpriseAndDatacenter(final Integer datacenterId, final Integer enterpriseId, Integer startwith, final Integer limit, final String filter, final OrderByEnum orderByEnum, final Boolean descOrAsc, NetworkType type, final Boolean all) { NetworkType type2 = type;/*from w ww.ja va2s.c om*/ String query = BY_DATACENTER; if (type != null) { if (type.equals(NetworkType.EXTERNAL_UNMANAGED)) { type = NetworkType.EXTERNAL; // to check. unecessary because with unmanaged vlan doesn't exist ips type2 = NetworkType.UNMANAGED; } // Get the query that counts the total results. query = BY_DATACENTER + " AND ent.id = :enterpriseId AND (vlan.type = :type OR vlan.type = :type2 ) "; } Query finalQuery = getSession() .createQuery(query + " " + defineAllFilter(all) + " " + defineOrderBy(orderByEnum, descOrAsc)); finalQuery.setParameter("datacenter_id", datacenterId); finalQuery.setParameter("filterLike", filter == null || filter.isEmpty() ? "%" : "%" + filter + "%"); if (type != null) { finalQuery.setParameter("type", type); finalQuery.setParameter("type2", type2); finalQuery.setParameter("enterpriseId", enterpriseId); } // Check if the page requested is bigger than the last one Integer totalResults = finalQuery.list().size(); if (limit != null) { finalQuery.setMaxResults(limit); } if (startwith >= totalResults) { startwith = totalResults - limit; } finalQuery.setFirstResult(startwith); finalQuery.setMaxResults(limit); PagedList<IpPoolManagement> ipList = new PagedList<IpPoolManagement>(finalQuery.list()); ipList.setTotalResults(totalResults); ipList.setPageSize(limit); ipList.setCurrentElement(startwith); return ipList; }