Merge "Use keys to speed DB queries"
authorPamela Dragosh <pdragosh@research.att.com>
Mon, 15 Apr 2019 16:50:51 +0000 (16:50 +0000)
committerGerrit Code Review <gerrit@onap.org>
Mon, 15 Apr 2019 16:50:51 +0000 (16:50 +0000)
models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java

index 0a0f5f7..efdf5f2 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -79,9 +80,8 @@ public class PdpProvider {
      */
     public List<PdpGroup> getFilteredPdpGroups(@NonNull final PfDao dao, @NonNull final PdpGroupFilter filter) {
 
-        List<JpaPdpGroup> jpaPdpGroupList = dao.getAll(JpaPdpGroup.class);
-
-        return filter.filter(asPdpGroupList(jpaPdpGroupList));
+        return filter.filter(
+                        asPdpGroupList(dao.getFiltered(JpaPdpGroup.class, filter.getName(), PfKey.NULL_KEY_VERSION)));
     }
 
     /**
index 46f920c..5f8729e 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -200,7 +201,10 @@ public class AuthorativeToscaProvider {
     public ToscaServiceTemplate getFilteredPolicies(@NonNull final PfDao dao, @NonNull final ToscaPolicyFilter filter)
             throws PfModelException {
 
-        ToscaServiceTemplate serviceTemplate = new SimpleToscaProvider().getPolicies(dao, null, null).toAuthorative();
+        String version = ToscaPolicyFilter.LATEST_VERSION.equals(filter.getVersion()) ? null : filter.getVersion();
+
+        ToscaServiceTemplate serviceTemplate =
+                        new SimpleToscaProvider().getPolicies(dao, filter.getName(), version).toAuthorative();
 
         List<ToscaPolicy> filteredPolicies = asConceptList(serviceTemplate.getToscaTopologyTemplate().getPolicies());
         filteredPolicies = filter.filter(filteredPolicies);
@@ -221,7 +225,8 @@ public class AuthorativeToscaProvider {
     public List<ToscaPolicy> getFilteredPolicyList(@NonNull final PfDao dao, @NonNull final ToscaPolicyFilter filter)
             throws PfModelException {
 
-        return filter.filter(getPolicyList(dao, null, null));
+        String version = ToscaPolicyFilter.LATEST_VERSION.equals(filter.getVersion()) ? null : filter.getVersion();
+        return filter.filter(getPolicyList(dao, filter.getName(), version));
     }
 
     /**