From 9a67d321484b935eaf63e55373088fa64b0ffd76 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Tue, 12 Jan 2021 11:52:29 -0500 Subject: Add more methods to query deployment status Issue-ID: POLICY-2648 Change-Id: I398fa1332eb5a862dabd97ed409ef6413bb0c202 Signed-off-by: Jim Hahn --- .../java/org/onap/policy/models/dao/PfDao.java | 11 +++++++++++ .../onap/policy/models/dao/impl/DefaultPfDao.java | 22 +++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'models-dao') 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 062ec4662..6c862bb64 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 @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 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. @@ -229,6 +230,16 @@ public interface PfDao { */ List getAllVersions(Class someClass, final String name); + /** + * Get all the objects in the database of a given type. + * + * @param 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 parentKeyName the name of the concepts for which to get all versions + * @return the objects or null if no objects were retrieved + */ + List getAllVersionsByParent(Class someClass, final String parentKeyName); + /** * Get a concept from the database with the given concept key. * 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 ad9ef1215..b7dda8dbb 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 @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2020 Nordix Foundation. - * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2021 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. @@ -91,6 +91,9 @@ public class DefaultPfDao implements PfDao { private static final String SELECT_ALL_FOR_PARENT = SELECT_FROM_TABLE + WHERE + PARENT_NAME_FILTER + AND + PARENT_VERSION_FILTER; + private static final String SELECT_ALL_VERSIONS_FOR_PARENT = + SELECT_FROM_TABLE + WHERE + PARENT_NAME_FILTER; + private static final String SELECT_ALL_VERSIONS = SELECT_FROM_TABLE + WHERE + NAME_FILTER; private static final String SELECT_BY_CONCEPT_KEY = @@ -469,6 +472,23 @@ public class DefaultPfDao implements PfDao { } } + @Override + public List getAllVersionsByParent(final Class someClass, final String parentKeyName) { + if (someClass == null || parentKeyName == null) { + return Collections.emptyList(); + } + final EntityManager mg = getEntityManager(); + try { + // @formatter:off + return mg.createQuery(setQueryTable(SELECT_ALL_VERSIONS_FOR_PARENT, someClass), someClass) + .setParameter(PARENT_NAME, parentKeyName) + .getResultList(); + // @formatter:on + } finally { + mg.close(); + } + } + @Override public List getAllVersions(final Class someClass, final String conceptName) { if (someClass == null || conceptName == null) { -- cgit 1.2.3-korg