Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Refactor
  • Loading branch information
nvazquez committed Aug 26, 2024
commit 04e849c8fff9932084d10f6b9c59b149132babf7
6 changes: 5 additions & 1 deletion framework/db/src/main/java/com/cloud/utils/db/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Filter(Class<?> clazz, String field, boolean ascending, Long offset, Long
_offset = offset;
_limit = limit;

addOrderBy(clazz, field, ascending, null);
addOrderBy(clazz, field, ascending);
}

public Filter(Class<?> clazz, String field, boolean ascending) {
Expand All @@ -75,6 +75,10 @@ public Filter(Filter that) {
that._limit = null;
}

public void addOrderBy(Class<?> clazz, String field, boolean ascending) {
addOrderBy(clazz, field, ascending, null);
}

public void addOrderBy(Class<?> clazz, String field, boolean ascending, String tableAlias) {
Comment thread
vishesh92 marked this conversation as resolved.
if (field == null) {
return;
Expand Down
4 changes: 2 additions & 2 deletions framework/db/src/test/java/com/cloud/utils/db/FilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public void testAddOrderBy() {

Assert.assertTrue(filter.getOrderBy().trim().toLowerCase().equals("order by test.fld_string asc"));

filter.addOrderBy(DbTestVO.class, "fieldLong", true, null);
filter.addOrderBy(DbTestVO.class, "fieldLong", true);

Assert.assertTrue(filter.getOrderBy().contains(","));
Assert.assertTrue(filter.getOrderBy().split(",")[1].trim().toLowerCase().equals("test.fld_long asc"));

filter.addOrderBy(DbTestVO.class, "fieldInt", true, null);
filter.addOrderBy(DbTestVO.class, "fieldInt", true);

Assert.assertTrue(filter.getOrderBy().split(",").length == 3);
Assert.assertTrue(filter.getOrderBy().split(",")[2].trim().toLowerCase().equals("test.fld_int asc"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ public QuotaTariffVO doInTransaction(final TransactionStatus status) {
public Pair<List<QuotaTariffVO>, Integer> listQuotaTariffs(Date startDate, Date endDate, Integer usageType, String name, String uuid, boolean listAll, Long startIndex, Long pageSize) {
SearchCriteria<QuotaTariffVO> searchCriteria = createListQuotaTariffsSearchCriteria(startDate, endDate, usageType, name, uuid);
Filter sorter = new Filter(QuotaTariffVO.class, "usageType", false, startIndex, pageSize);
sorter.addOrderBy(QuotaTariffVO.class, "effectiveOn", false, null);
sorter.addOrderBy(QuotaTariffVO.class, "updatedOn", false, null);
sorter.addOrderBy(QuotaTariffVO.class, "effectiveOn", false);
sorter.addOrderBy(QuotaTariffVO.class, "updatedOn", false);

return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback<Pair<List<QuotaTariffVO>, Integer>>) status -> searchAndCount(searchCriteria, sorter, listAll));
}
Expand Down
10 changes: 5 additions & 5 deletions server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ private Pair<List<Long>, Integer> searchForEventIdsAndCount(ListEventsCmd cmd) {
Filter searchFilter = new Filter(EventVO.class, "createDate", false, cmd.getStartIndex(), cmd.getPageSizeVal());
// additional order by since createdDate does not have milliseconds
// and two events, created within one second can be incorrectly ordered (for example VM.CREATE Completed before Scheduled)
searchFilter.addOrderBy(EventVO.class, "id", false, null);
searchFilter.addOrderBy(EventVO.class, "id", false);

SearchBuilder<EventVO> eventSearchBuilder = eventDao.createSearchBuilder();
eventSearchBuilder.select(null, Func.DISTINCT, eventSearchBuilder.entity().getId());
Expand Down Expand Up @@ -3421,7 +3421,7 @@ private Ternary<List<Long>, Integer, String[]> searchForDiskOfferingsIdsAndCount
DiskOffering.State state = cmd.getState();

Filter searchFilter = new Filter(DiskOfferingVO.class, "sortKey", SortKeyAscending.value(), cmd.getStartIndex(), cmd.getPageSizeVal());
searchFilter.addOrderBy(DiskOfferingVO.class, "id", true, null);
searchFilter.addOrderBy(DiskOfferingVO.class, "id", true);
SearchBuilder<DiskOfferingVO> diskOfferingSearch = _diskOfferingDao.createSearchBuilder();
diskOfferingSearch.select(null, Func.DISTINCT, diskOfferingSearch.entity().getId()); // select distinct

Expand Down Expand Up @@ -3719,7 +3719,7 @@ private Pair<List<Long>, Integer> searchForServiceOfferingIdsAndCount(ListServic
}

Filter searchFilter = new Filter(ServiceOfferingVO.class, "sortKey", SortKeyAscending.value(), cmd.getStartIndex(), cmd.getPageSizeVal());
searchFilter.addOrderBy(ServiceOfferingVO.class, "id", true, null);
searchFilter.addOrderBy(ServiceOfferingVO.class, "id", true);

SearchBuilder<ServiceOfferingVO> serviceOfferingSearch = _srvOfferingDao.createSearchBuilder();
serviceOfferingSearch.select(null, Func.DISTINCT, serviceOfferingSearch.entity().getId()); // select distinct
Expand Down Expand Up @@ -4183,7 +4183,7 @@ private Pair<List<DataCenterJoinVO>, Integer> listDataCentersInternal(ListZonesC
}

Filter searchFilter = new Filter(DataCenterJoinVO.class, "sortKey", SortKeyAscending.value(), cmd.getStartIndex(), cmd.getPageSizeVal());
searchFilter.addOrderBy(DataCenterJoinVO.class, "id", true, null);
searchFilter.addOrderBy(DataCenterJoinVO.class, "id", true);
SearchCriteria<DataCenterJoinVO> sc = sb.create();

if (networkType != null) {
Expand Down Expand Up @@ -4468,7 +4468,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long temp
VMTemplateVO template = null;

Filter searchFilter = new Filter(TemplateJoinVO.class, "sortKey", SortKeyAscending.value(), startIndex, pageSize);
searchFilter.addOrderBy(TemplateJoinVO.class, "tempZonePair", SortKeyAscending.value(), null);
searchFilter.addOrderBy(TemplateJoinVO.class, "tempZonePair", SortKeyAscending.value());

SearchBuilder<TemplateJoinVO> sb = _templateJoinDao.createSearchBuilder();
if (showUnique) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ public List<TemplateJoinVO> searchByTemplateZonePair(Boolean showRemoved, String
}
// query details by batches
Filter searchFilter = new Filter(TemplateJoinVO.class, "sortKey", QueryService.SortKeyAscending.value(), null, null);
searchFilter.addOrderBy(TemplateJoinVO.class, "tempZonePair", QueryService.SortKeyAscending.value(), null);
searchFilter.addOrderBy(TemplateJoinVO.class, "tempZonePair", QueryService.SortKeyAscending.value());
List<TemplateJoinVO> uvList = new ArrayList<TemplateJoinVO>();
// query details by batches
int curr_index = 0;
Expand Down Expand Up @@ -706,7 +706,7 @@ public List<TemplateJoinVO> findByDistinctIds(Long... ids) {
}

Filter searchFilter = new Filter(TemplateJoinVO.class, "sortKey", QueryService.SortKeyAscending.value(), null, null);
searchFilter.addOrderBy(TemplateJoinVO.class, "tempZonePair", true, null);
searchFilter.addOrderBy(TemplateJoinVO.class, "tempZonePair", true);

SearchCriteria<TemplateJoinVO> sc = tmpltIdsSearch.create();
sc.setParameters("idsIN", ids);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6813,7 +6813,7 @@ protected void validateNtwkOffDetails(final Map<Detail, String> details, final M
@Override
public Pair<List<? extends NetworkOffering>, Integer> searchForNetworkOfferings(final ListNetworkOfferingsCmd cmd) {
final Filter searchFilter = new Filter(NetworkOfferingJoinVO.class, "sortKey", QueryService.SortKeyAscending.value(), null, null);
searchFilter.addOrderBy(NetworkOfferingJoinVO.class, "id", true, null);
searchFilter.addOrderBy(NetworkOfferingJoinVO.class, "id", true);
final Account caller = CallContext.current().getCallingAccount();
final SearchCriteria<NetworkOfferingJoinVO> sc = networkOfferingJoinDao.createSearchCriteria();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ public List<IPAddressVO> listAvailablePublicIps(final long dcId, final Long podI
boolean ascOrder = ! forSystemVms;
Filter filter = new Filter(IPAddressVO.class, "forSystemVms", ascOrder, 0l, 1l);

filter.addOrderBy(IPAddressVO.class,"vlanId", true, null);
filter.addOrderBy(IPAddressVO.class,"vlanId", true);

List<IPAddressVO> addrs = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ public Pair<List<? extends VpcOffering>, Integer> listVpcOfferings(ListVPCOfferi
final Long domainId = cmd.getDomainId();
final Long zoneId = cmd.getZoneId();
final Filter searchFilter = new Filter(VpcOfferingJoinVO.class, "sortKey", QueryService.SortKeyAscending.value(), null, null);
searchFilter.addOrderBy(VpcOfferingJoinVO.class, "id", true, null);
searchFilter.addOrderBy(VpcOfferingJoinVO.class, "id", true);
final SearchCriteria<VpcOfferingJoinVO> sc = vpcOfferingJoinDao.createSearchCriteria();

verifyDomainId(domainId, caller);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2725,9 +2725,9 @@ public Pair<List<? extends GuestOsCategory>, Integer> listGuestOSCategoriesByCri
public Pair<List<? extends GuestOSHypervisor>, Integer> listGuestOSMappingByCriteria(final ListGuestOsMappingCmd cmd) {
final String guestOsId = "guestOsId";
final Filter searchFilter = new Filter(GuestOSHypervisorVO.class, "hypervisorType", true, cmd.getStartIndex(), cmd.getPageSizeVal());
searchFilter.addOrderBy(GuestOSHypervisorVO.class, "hypervisorVersion", false, null);
searchFilter.addOrderBy(GuestOSHypervisorVO.class, guestOsId, true, null);
searchFilter.addOrderBy(GuestOSHypervisorVO.class, "created", false, null);
searchFilter.addOrderBy(GuestOSHypervisorVO.class, "hypervisorVersion", false);
searchFilter.addOrderBy(GuestOSHypervisorVO.class, guestOsId, true);
searchFilter.addOrderBy(GuestOSHypervisorVO.class, "created", false);
final Long id = cmd.getId();
final Long osTypeId = cmd.getOsTypeId();
final String osDisplayName = cmd.getOsDisplayName();
Expand Down