From 86374588a6103114b1f0f335a1b65da1ad0817a5 Mon Sep 17 00:00:00 2001 From: "ning.xi" Date: Thu, 26 Dec 2019 21:37:52 +0800 Subject: update Db provider to support query number Issue-ID: POLICY-1629 Signed-off-by: ning.xi Change-Id: I42c9542adc44d52b760a70e710ab4cc6fa8a1b3b --- .../pdp/persistence/provider/PdpStatisticsProvider.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'models-pdp/src/main') diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java index f149a3602..3b1718090 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpStatisticsProvider.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Model * ================================================================================ - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,6 +52,7 @@ public class PdpStatisticsProvider { // Recurring string constants private static final String NOT_VALID = "\" is not valid \n"; + private static final String DESC_ORDER = "DESC"; /** * Get PDP statistics. @@ -84,12 +85,14 @@ public class PdpStatisticsProvider { * @param pdpSubGroup pdpSubGroupType name to filter statistics * @param startTimeStamp startTimeStamp to filter statistics * @param endTimeStamp endTimeStamp to filter statistics + * @param sortOrder sortOrder to query database + * @param getRecordNum Total query count from database * @return the PDP statistics found * @throws PfModelException on errors getting policies */ public List getFilteredPdpStatistics(@NonNull final PfDao dao, final String name, @NonNull final String pdpGroupName, final String pdpSubGroup, final Date startTimeStamp, - final Date endTimeStamp) { + final Date endTimeStamp, final String sortOrder, final int getRecordNum) { Map filterMap = new HashMap<>(); filterMap.put("pdpGroupName", pdpGroupName); if (pdpSubGroup != null) { @@ -97,7 +100,7 @@ public class PdpStatisticsProvider { } return asPdpStatisticsList(dao.getFiltered(JpaPdpStatistics.class, name, PfKey.NULL_KEY_VERSION, startTimeStamp, - endTimeStamp, filterMap)); + endTimeStamp, filterMap, sortOrder, getRecordNum)); } /** @@ -187,8 +190,8 @@ public class PdpStatisticsProvider { */ public List deletePdpStatistics(@NonNull final PfDao dao, @NonNull final String name, final Date timestamp) { - List pdpStatisticsListToDel = asPdpStatisticsList( - dao.getFiltered(JpaPdpStatistics.class, name, PfKey.NULL_KEY_VERSION, timestamp, timestamp, null)); + List pdpStatisticsListToDel = asPdpStatisticsList(dao.getFiltered(JpaPdpStatistics.class, name, + PfKey.NULL_KEY_VERSION, timestamp, timestamp, null, DESC_ORDER, 0)); pdpStatisticsListToDel.stream().forEach(s -> dao.delete(JpaPdpStatistics.class, new PfTimestampKey(s.getPdpInstanceId(), PfKey.NULL_KEY_VERSION, s.getTimeStamp()))); -- cgit 1.2.3-korg