aboutsummaryrefslogtreecommitdiffstats
path: root/models-dao/src/main/java/org
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-06-02 14:35:48 +0000
committerGerrit Code Review <gerrit@onap.org>2021-06-02 14:35:48 +0000
commit2ba648e483fe5f5ef953acb2b25135e9a3cbd742 (patch)
tree1af38fd6a6ada71ab88e2b412e8b504564eb09ba /models-dao/src/main/java/org
parentb1ebc97af3bf155a34100380435b5d21a2be774d (diff)
parent09e2bc57b947fb71c4dde9a8c0ded52f695abda1 (diff)
Merge "Handling Policy deploy/undeploy audit models"
Diffstat (limited to 'models-dao/src/main/java/org')
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/PfDao.java11
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java35
2 files changed, 39 insertions, 7 deletions
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/PfDao.java b/models-dao/src/main/java/org/onap/policy/models/dao/PfDao.java
index 844759367..378ae59b6 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/PfDao.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/PfDao.java
@@ -256,6 +256,17 @@ public interface PfDao {
*
* @param <T> the type of the objects to get, a subclass of {@link PfConcept}
* @param someClass the class of the objects to get, a subclass of {@link PfConcept}
+ * @param orderBy field from class to order results by
+ * @param numRecords number of records to be retrieved
+ * @return the objects or null if no objects were retrieved
+ */
+ <T extends PfConcept> List<T> getAll(Class<T> someClass, String orderBy, Integer numRecords);
+
+ /**
+ * Get all the objects in the database of a given type.
+ *
+ * @param <T> the type of the objects to get, a subclass of {@link PfConcept}
+ * @param someClass the class of the objects to get, a subclass of {@link PfConcept}
* @param name the name of the concepts for which to get all versions
* @return the objects or null if no objects were retrieved
*/
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java b/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java
index d27f3c6ed..336abf7df 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java
@@ -32,6 +32,7 @@ import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;
import javax.ws.rs.core.Response;
+import org.apache.commons.lang3.StringUtils;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfGeneratedIdKey;
@@ -72,6 +73,7 @@ public class DefaultPfDao implements PfDao {
private static final String WHERE = " WHERE ";
private static final String AND = " AND ";
+ private static final String ORDER_BY = " ORDER BY c.";
private static final String NAME_FILTER = "c.key.name = :name";
private static final String VERSION_FILTER = "c.key.version = :version";
@@ -395,9 +397,8 @@ public class DefaultPfDao implements PfDao {
try {
PfFilter timeStampFilter = new PfFilterFactory().createFilter(someClass);
- filterQueryString = timeStampFilter.addFilter(filterQueryString,
- name, startTime, endTime, filterMap, sortOrder, getRecordNum);
-
+ filterQueryString = timeStampFilter.addFilter(filterQueryString, name, startTime, endTime, filterMap,
+ sortOrder, getRecordNum);
TypedQuery<T> query = mg.createQuery(setQueryTable(filterQueryString, someClass), someClass);
@@ -427,7 +428,7 @@ public class DefaultPfDao implements PfDao {
LOGGER.debug("filterQueryString is \"{}\"", filterQueryString);
return query.getResultList();
- } finally {
+ } finally {
mg.close();
}
}
@@ -505,6 +506,27 @@ public class DefaultPfDao implements PfDao {
}
@Override
+ public <T extends PfConcept> List<T> getAll(Class<T> someClass, String orderBy, Integer numRecords) {
+
+ if (someClass == null) {
+ return Collections.emptyList();
+ }
+ final var mg = getEntityManager();
+ try {
+ String query = setQueryTable(SELECT_FROM_TABLE, someClass);
+
+ if (StringUtils.isNotBlank(orderBy)) {
+ query = query.concat(ORDER_BY).concat(orderBy);
+ }
+
+ return mg.createQuery(query, someClass).setMaxResults(numRecords)
+ .getResultList();
+ } finally {
+ mg.close();
+ }
+ }
+
+ @Override
public <T extends PfConcept> List<T> getAllVersionsByParent(final Class<T> someClass, final String parentKeyName) {
if (someClass == null || parentKeyName == null) {
return Collections.emptyList();
@@ -539,9 +561,8 @@ public class DefaultPfDao implements PfDao {
}
@Override
- public <T extends PfConcept> List<T> getByTimestamp(final Class<T> someClass,
- final PfGeneratedIdKey key,
- final Instant timeStamp) {
+ public <T extends PfConcept> List<T> getByTimestamp(final Class<T> someClass, final PfGeneratedIdKey key,
+ final Instant timeStamp) {
if (someClass == null || key == null || timeStamp == null) {
return Collections.emptyList();
}