List of usage examples for org.hibernate Query setFirstResult
@Override
Query<R> setFirstResult(int startPosition);
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 w w .j a va 2s .co m 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; }
From source file:com.abiquo.server.core.infrastructure.network.IpPoolManagementDAO.java
License:Open Source License
public List<IpPoolManagement> findPublicIpsByVlan(final Integer datacenterId, final Integer vlanId, Integer startwith, final Integer limit, final String filter, final OrderByEnum orderByEnum, final Boolean descOrAsc, final Boolean all) { Query finalQuery = getSession().createQuery( BY_PUBLIC_VLAN + " " + defineAllFilter(all) + " " + defineOrderBy(orderByEnum, descOrAsc)); finalQuery.setParameter("datacenter_id", datacenterId); 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); }//ww w . j a v a 2 s . c o m 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> findpublicIpsPurchasedByVirtualDatacenter(final Integer vdcId, final Boolean onlyAvailabe, Integer startwith, final Integer limit, final String filter, final OrderByEnum orderByEnum, final Boolean descOrAsc) { Query finalQuery = getSession().createQuery(BY_VDC_PURCHASED + " " + defineOnlyAvailableFilter(onlyAvailabe) + defineOrderBy(orderByEnum, descOrAsc)); finalQuery.setParameter("vdc_id", vdcId); 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); }/*from w w w.ja v a 2 s .c o m*/ 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> findpublicIpsToPurchaseByVirtualDatacenter(final Integer vdcId, Integer startwith, final Integer limit, final String filter, final OrderByEnum orderByEnum, final Boolean descOrAsc) { Query finalQuery = getSession() .createQuery(BY_VDC_TO_PURCHASE + " " + defineOrderBy(orderByEnum, descOrAsc)); finalQuery.setParameter("vdc_id", vdcId); 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 w w .ja v a2 s.c o m 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.storage.VolumeManagementDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<VolumeManagement> getVolumesByPool(final StoragePool sp, final FilterOptions filters) { // Check if the orderBy element is actually one of the available ones VolumeManagement.OrderByEnum orderByEnum = VolumeManagement.OrderByEnum .valueOf(filters.getOrderBy().toUpperCase()); String orderBy = defineOrderBy(orderByEnum.getColumnHQL(), filters.getAsc()); Query query = getSession().getNamedQuery(VolumeManagement.VOLUMES_BY_POOL); String req = query.getQueryString() + orderBy; // Add order filter to the query Query queryWithOrder = getSession().createQuery(req); queryWithOrder.setString("poolId", sp.getId()); queryWithOrder.setString("filterLike", filters.getFilter().isEmpty() ? "%" : "%" + filters.getFilter() + "%"); Integer size = queryWithOrder.list().size(); queryWithOrder.setFirstResult(filters.getStartwith()); queryWithOrder.setMaxResults(filters.getLimit()); PagedList<VolumeManagement> volumesList = new PagedList<VolumeManagement>(queryWithOrder.list()); volumesList.setTotalResults(size);//from www . j ava 2s . c o m volumesList.setPageSize(filters.getLimit() > size ? size : filters.getLimit()); volumesList.setCurrentElement(filters.getStartwith()); return volumesList; }
From source file:com.abiquo.server.core.infrastructure.storage.VolumeManagementDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<VolumeManagement> getVolumesByVirtualDatacenter(final VirtualDatacenter vdc, final FilterOptions filters) { // Check if the orderBy element is actually one of the available ones VolumeManagement.OrderByEnum orderByEnum = VolumeManagement.OrderByEnum .valueOf(filters.getOrderBy().toUpperCase()); String orderBy = defineOrderBy(orderByEnum.getColumnHQL(), filters.getAsc()); Query query = getSession().getNamedQuery(VolumeManagement.VOLUMES_BY_VDC); String req = query.getQueryString() + orderBy; // Add order filter to the query Query queryWithOrder = getSession().createQuery(req); queryWithOrder.setInteger("vdcId", vdc.getId()); queryWithOrder.setString("filterLike", filters.getFilter().isEmpty() ? "%" : "%" + filters.getFilter() + "%"); Integer size = queryWithOrder.list().size(); queryWithOrder.setFirstResult(filters.getStartwith()); queryWithOrder.setMaxResults(filters.getLimit()); PagedList<VolumeManagement> volumesList = new PagedList<VolumeManagement>(queryWithOrder.list()); volumesList.setTotalResults(size);//ww w .j av a2s .c o m volumesList.setPageSize(filters.getLimit() > size ? size : filters.getLimit()); volumesList.setCurrentElement(filters.getStartwith()); return volumesList; }
From source file:com.abiquo.server.core.infrastructure.storage.VolumeManagementDAO.java
License:Open Source License
public List<VolumeManagement> getVolumesByEnterprise(final Integer id, final FilterOptions filters) { // Check if the orderBy element is actually one of the available ones VolumeManagement.OrderByEnum orderByEnum = VolumeManagement.OrderByEnum .valueOf(filters.getOrderBy().toUpperCase()); Query query = getSession().createSQLQuery(SQL_VOLUME_MANAGEMENT_GET_VOLUMES_FROM_ENTERPRISE + defineOrderBy(orderByEnum.getColumnSQL(), filters.getAsc())); query.setParameter("idEnterprise", id); query.setParameter("filterLike", filters.getFilter().isEmpty() ? "%" : "%" + filters.getFilter() + "%"); Integer size = getSQLQueryResults(getSession(), query, VolumeManagement.class, 0).size(); query.setFirstResult(filters.getStartwith()); query.setMaxResults(filters.getLimit()); PagedList<VolumeManagement> volumes = new PagedList<VolumeManagement>( getSQLQueryResults(getSession(), query, VolumeManagement.class, 0)); volumes.setTotalResults(size);/*from w w w . ja v a2s .co m*/ volumes.setPageSize(filters.getLimit() > size ? size : filters.getLimit()); volumes.setCurrentElement(filters.getStartwith()); return volumes; }
From source file:com.abiquo.server.core.infrastructure.storage.VolumeManagementDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<VolumeManagement> getAvailableVolumes(final VirtualDatacenter vdc, final FilterOptions filters) { // Check if the orderBy element is actually one of the available ones VolumeManagement.OrderByEnum orderByEnum = VolumeManagement.OrderByEnum .valueOf(filters.getOrderBy().toUpperCase()); String orderBy = defineOrderBy(orderByEnum.getColumnHQL(), filters.getAsc()); Query query = getSession().getNamedQuery(VolumeManagement.VOLUMES_AVAILABLES); String req = query.getQueryString() + orderBy; // Add order filter to the query Query queryWithOrder = getSession().createQuery(req); queryWithOrder.setInteger("vdcId", vdc.getId()); queryWithOrder.setString("filterLike", filters.getFilter().isEmpty() ? "%" : "%" + filters.getFilter() + "%"); Integer size = queryWithOrder.list().size(); // Limit 0 means no size filter if (filters.getLimit() == 0) { filters.setLimit(size);//from ww w . j a v a 2s. c o m filters.setStartwith(0); } queryWithOrder.setFirstResult(filters.getStartwith()); queryWithOrder.setMaxResults(filters.getLimit()); PagedList<VolumeManagement> volumesList = new PagedList<VolumeManagement>(queryWithOrder.list()); volumesList.setTotalResults(size); volumesList.setPageSize(filters.getLimit() > size ? size : filters.getLimit()); volumesList.setCurrentElement(filters.getStartwith()); return volumesList; }
From source file:com.abiquo.server.core.infrastructure.storage.VolumeManagementDAO.java
License:Open Source License
public List<VolumeManagement> getVolumesByVirtualMachine(final VirtualMachine vm, final FilterOptions filters) { if (filters != null) { // Check if the orderBy element is actually one of the available ones VolumeManagement.OrderByEnum orderByEnum = VolumeManagement.OrderByEnum .valueOf(filters.getOrderBy().toUpperCase()); String orderBy = defineOrderBy(orderByEnum.getColumnHQL(), filters.getAsc()); Query query = getSession().getNamedQuery(VolumeManagement.VOLUMES_ATTACHED_TO_VM); String req = query.getQueryString() + orderBy; // Add order filter to the query Query queryWithOrder = getSession().createQuery(req); queryWithOrder.setInteger("vmId", vm.getId()); queryWithOrder.setParameter("state", VolumeState.ATTACHED); queryWithOrder.setString("filterLike", filters.getFilter().isEmpty() ? "%" : "%" + filters.getFilter() + "%"); Integer size = queryWithOrder.list().size(); queryWithOrder.setFirstResult(filters.getStartwith()); queryWithOrder.setMaxResults(filters.getLimit()); PagedList<VolumeManagement> volumesList = new PagedList<VolumeManagement>(queryWithOrder.list()); volumesList.setTotalResults(size); volumesList.setPageSize(filters.getLimit() > size ? size : filters.getLimit()); volumesList.setCurrentElement(filters.getStartwith()); return volumesList; } else {/*from ww w .j a v a2 s . com*/ Criteria criteria = createCriteria(sameVirtualMachine(vm), sameState(VolumeState.ATTACHED)); return getResultList(criteria); } }
From source file:com.abssh.util.GenericDao.java
License:Apache License
/** * ?Query,.//from w w w. j a va2 s. co m */ protected Query setPageParameter(final Query q, final Page<T> page) { // hibernatefirstResult??0 if (page.getPageSize() > 0) { q.setFirstResult(page.getFirst() - 1); q.setMaxResults(page.getPageSize()); } return q; }