aboutsummaryrefslogtreecommitdiffstats
path: root/models-dao/src/main/java/org/onap
diff options
context:
space:
mode:
authorktimoney <kevin.timoney@est.tech>2021-04-13 14:40:06 +0100
committerktimoney <kevin.timoney@est.tech>2021-04-22 20:09:36 +0100
commita3241bec1cf1ae5fd514923ba5f923abc5427762 (patch)
tree0c06bc0d1d026ab411391c7cf9aac293207ad231 /models-dao/src/main/java/org/onap
parent0b7b94b17340406b34817d6088daa97d965d5c2c (diff)
Add a new key class which uses @GeneratedValue to base classes
This will provide an alternative unique key. It will be used in place of PfTimestampKey in the PdpStatistics table. We make use of the @GeneratedValue annotation to provide this feature. Added DummyGeneratedIdEntity and unit tests Added PfFilterFactory class Added new filter classes Issue-ID: POLICY-3189 Change-Id: I097eab318d2cb958e1157e35825fd6d35d429a25 Signed-off-by: ktimoney <kevin.timoney@est.tech>
Diffstat (limited to 'models-dao/src/main/java/org/onap')
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/PfDao.java32
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/PfFilter.java91
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/PfFilterFactory.java77
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java147
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/impl/PfNonTimestampKeyFilter.java46
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/impl/PfReferenceTimestampKeyFilter.java46
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/impl/PfTimestampKeyFilter.java46
7 files changed, 404 insertions, 81 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 eb77be9c0..844759367 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
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.Map;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfGeneratedIdKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfReferenceTimestampKey;
@@ -95,6 +96,15 @@ public interface PfDao {
<T extends PfConcept> void delete(Class<T> someClass, PfTimestampKey timeStampKey);
/**
+ * Delete an Policy Framework concept on the database.
+ *
+ * @param <T> the type of the object to delete, a subclass of {@link PfConcept}
+ * @param someClass the class of the object to delete, a subclass of {@link PfConcept}
+ * @param idKey the PfConceptIdKey of the object to delete
+ */
+ <T extends PfConcept> void delete(Class<T> someClass, PfGeneratedIdKey idKey);
+
+ /**
* Create a collection of objects in the database.
*
* @param <T> the type of the object to create, a subclass of {@link PfConcept}
@@ -203,6 +213,16 @@ public interface PfDao {
<T extends PfConcept> T get(Class<T> someClass, PfTimestampKey timestampKey);
/**
+ * Get an object from the database, referred to by reference key.
+ *
+ * @param <T> the type of the object to get, a subclass of {@link PfConcept}
+ * @param someClass the class of the object to get, a subclass of {@link PfConcept}
+ * @param idKey the PfConceptIdKey of the object to get
+ * @return the object that was retrieved from the database or null if the object was not retrieved
+ */
+ <T extends PfConcept> T get(Class<T> someClass, PfGeneratedIdKey idKey);
+
+ /**
* Get an object from the database, referred to by reference timestamp key.
*
* @param <T> the type of the object to get, a subclass of {@link PfConcept}
@@ -252,6 +272,18 @@ public interface PfDao {
<T extends PfConcept> List<T> getAllVersionsByParent(Class<T> someClass, final String parentKeyName);
/**
+ * 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 key the key of the PfGeneratedIdKey to get
+ * @param timeStamp the timeStamp of the concepts to get
+ * @return the objects or null if no objects were retrieved
+ */
+ <T extends PfConcept> List<T> getByTimestamp(final Class<T> someClass,
+ final PfGeneratedIdKey key, final Instant timeStamp);
+
+ /**
* Get a concept from the database with the given concept key.
*
* @param <T> the type of the object to get, a subclass of {@link PfConcept}
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/PfFilter.java b/models-dao/src/main/java/org/onap/policy/models/dao/PfFilter.java
new file mode 100644
index 000000000..ef9d4f939
--- /dev/null
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/PfFilter.java
@@ -0,0 +1,91 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.dao;
+
+import java.time.Instant;
+import java.util.Map;
+import lombok.Data;
+/**
+ * This abstract class is used as a base for the filter implementations.
+ *
+ */
+
+@Data
+public abstract class PfFilter {
+ private static final String AND = " AND ";
+ private static final String ORDER = " ORDER BY ";
+
+ private String nameFilter;
+ private String timeStampStartFilter;
+ private String timeStampEndFilter;
+ private String timeStampFilter;
+ private String nameParameter;
+
+ /**
+ * Generates filter string.
+ *
+ * @param inputFilterString current filterString generated from FilterMap
+ * @param name the pdpInstance name for the PDP statistics to get
+ * @param startTime the start timeStamp to filter from database, filter rule:
+ * startTime <= filteredRecord timeStamp <= endTime. null for ignore end time
+ * @param endTime the end timeStamp to filter from database, filter rule:
+ * startTime <= filteredRecord timeStamp <= endTime. null for ignore end time
+ * @param filterMap Map store extra key/value used to filter from database, can be null *
+ * @param sortOrder sortOrder to query database
+ * @param getRecordNum Total query count from database
+
+ */
+ public String addFilter(final String inputFilterString,
+ final String name, final Instant startTime, final Instant endTime,
+ final Map<String, Object> filterMap, final String sortOrder, final int getRecordNum) {
+ StringBuilder filterQueryString = new StringBuilder(inputFilterString);
+ if (filterMap != null) {
+ for (String key : filterMap.keySet()) {
+ filterQueryString.append("c." + key + "= :" + key + AND);
+ }
+ }
+
+ if (name != null) {
+ filterQueryString.append(getNameFilter() + AND);
+ }
+
+ if (startTime != null) {
+ if (endTime != null) {
+ filterQueryString.append(getTimeStampStartFilter());
+ filterQueryString.append(AND);
+ filterQueryString.append(getTimeStampEndFilter());
+ } else {
+ filterQueryString.append(getTimeStampStartFilter());
+ }
+ } else {
+ if (endTime != null) {
+ filterQueryString.append(getTimeStampEndFilter());
+ } else {
+ filterQueryString.delete(filterQueryString.length() - AND.length(), filterQueryString.length());
+ }
+ }
+
+ if (getRecordNum > 0) {
+ filterQueryString.append(ORDER + getTimeStampFilter() + sortOrder);
+ }
+ return filterQueryString.toString();
+ }
+}
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/PfFilterFactory.java b/models-dao/src/main/java/org/onap/policy/models/dao/PfFilterFactory.java
new file mode 100644
index 000000000..643481f39
--- /dev/null
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/PfFilterFactory.java
@@ -0,0 +1,77 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.dao;
+
+import java.time.Instant;
+import java.util.Map;
+import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.dao.impl.PfNonTimestampKeyFilter;
+import org.onap.policy.models.dao.impl.PfReferenceTimestampKeyFilter;
+import org.onap.policy.models.dao.impl.PfTimestampKeyFilter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This factory class creates a filter class for a key type.
+ * The filter returned depends on the type of class being used.
+ *
+ */
+public class PfFilterFactory {
+ // Get a reference to the logger
+ private static final Logger LOGGER = LoggerFactory.getLogger(PfFilterFactory.class);
+
+ /**
+ * Return a filter class for the input class.
+ *
+ * @param <T> the type of the object to get, a subclass of {@link PfConcept}*
+ * @return the filter type for the input class *
+ */
+ public <T extends PfConcept> PfFilter createFilter(final Class<T> someClass) {
+ PfFilter filter = null;
+
+ switch (getKeyName(someClass)) {
+ case "PfTimestampKey":
+ filter = new PfTimestampKeyFilter();
+ break;
+ case "PfReferenceTimestampKey":
+ filter = new PfReferenceTimestampKeyFilter();
+ break;
+ default:
+ filter = new PfNonTimestampKeyFilter();
+ }
+ return filter;
+ }
+
+ /**
+ * Gets the name of the key class of the class invoking the DAO.
+ * @param someClass class that invoked Dao
+ * @return the name of the key class
+ */
+ private <T extends PfConcept> String getKeyName(final Class<T> someClass) {
+ try {
+ String fullClassName = someClass.getDeclaredField("key").getType().toString();
+ return fullClassName.substring(fullClassName.lastIndexOf('.') + 1);
+ } catch (NoSuchFieldException e) {
+ LOGGER.error("Error getting the key:", e);
+ return "NON_TIMESTAMP_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 bdbc04e22..1bd2e09da 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
@@ -34,6 +34,7 @@ import javax.persistence.TypedQuery;
import javax.ws.rs.core.Response;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfGeneratedIdKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.base.PfReferenceKey;
@@ -42,6 +43,8 @@ import org.onap.policy.models.base.PfTimestampKey;
import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.dao.DaoParameters;
import org.onap.policy.models.dao.PfDao;
+import org.onap.policy.models.dao.PfFilter;
+import org.onap.policy.models.dao.PfFilterFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -56,6 +59,7 @@ public class DefaultPfDao implements PfDao {
private static final String NAME = "name";
private static final String VERSION = "version";
private static final String TIMESTAMP = "timeStamp";
+ private static final String GENERATEDID = "Id";
private static final String PARENT_NAME = "parentname";
private static final String PARENT_VERSION = "parentversion";
private static final String LOCAL_NAME = "localname";
@@ -73,8 +77,8 @@ public class DefaultPfDao implements PfDao {
private static final String NAME_FILTER = "c.key.name = :name";
private static final String VERSION_FILTER = "c.key.version = :version";
private static final String TIMESTAMP_FILTER = "c.key.timeStamp = :timeStamp";
- private static final String TIMESTAMP_START_FILTER = "c.key.timeStamp >= :startTime";
- private static final String TIMESTAMP_END_FILTER = "c.key.timeStamp <= :endTime";
+ private static final String TIMESTAMP_FILTER_NOKEY = "c.timeStamp = :timeStamp";
+ private static final String GENERATED_ID_FILTER = "c.key.generatedId = :Id";
private static final String PARENT_NAME_FILTER = "c.key.parentKeyName = :parentname";
private static final String PARENT_VERSION_FILTER = "c.key.parentKeyVersion = :parentversion";
private static final String LOCAL_NAME_FILTER = "c.key.localName = :localname";
@@ -89,6 +93,9 @@ public class DefaultPfDao implements PfDao {
private static final String DELETE_BY_TIMESTAMP_KEY =
DELETE_FROM_TABLE + WHERE + NAME_FILTER + AND + VERSION_FILTER + AND + TIMESTAMP_FILTER;
+ private static final String DELETE_BY_GENERATED_ID_KEY =
+ DELETE_FROM_TABLE + WHERE + NAME_FILTER + AND + VERSION_FILTER + AND + GENERATED_ID_FILTER;
+
private static final String DELETE_BY_REFERENCE_KEY =
DELETE_FROM_TABLE + WHERE + PARENT_NAME_FILTER + AND + PARENT_VERSION_FILTER + AND + LOCAL_NAME_FILTER;
@@ -103,6 +110,9 @@ public class DefaultPfDao implements PfDao {
private static final String SELECT_BY_CONCEPT_KEY =
SELECT_FROM_TABLE + WHERE + NAME_FILTER + AND + VERSION_FILTER;
+ private static final String SELECT_BY_TIMESTAMP_NOKEY =
+ SELECT_FROM_TABLE + WHERE + NAME_FILTER + AND + VERSION_FILTER + AND + TIMESTAMP_FILTER_NOKEY;
+
private static final String SELECT_BY_REFERENCE_KEY =
SELECT_FROM_TABLE + WHERE + PARENT_NAME_FILTER + AND + PARENT_VERSION_FILTER + AND + LOCAL_NAME_FILTER;
// @formatter:on
@@ -246,6 +256,27 @@ public class DefaultPfDao implements PfDao {
}
@Override
+ public <T extends PfConcept> void delete(final Class<T> someClass, final PfGeneratedIdKey key) {
+ if (key == null) {
+ return;
+ }
+ final EntityManager mg = getEntityManager();
+ try {
+ // @formatter:off
+ mg.getTransaction().begin();
+ mg.createQuery(setQueryTable(DELETE_BY_GENERATED_ID_KEY, someClass), someClass)
+ .setParameter(NAME, key.getName())
+ .setParameter(VERSION, key.getVersion())
+ .setParameter(GENERATEDID, key.getGeneratedId())
+ .executeUpdate();
+ mg.getTransaction().commit();
+ // @formatter:on
+ } finally {
+ mg.close();
+ }
+ }
+
+ @Override
public <T extends PfConcept> void createCollection(final Collection<T> objs) {
if (objs == null || objs.isEmpty()) {
return;
@@ -366,14 +397,11 @@ public class DefaultPfDao implements PfDao {
String filterQueryString = SELECT_FROM_TABLE + WHERE;
try {
- if (filterMap != null) {
- filterQueryString = buildFilter(filterMap, filterQueryString, isRefTimestampKey(someClass));
- }
- filterQueryString = addKeyFilterString(filterQueryString, name, startTime, endTime,
- isRefTimestampKey(someClass));
- if (getRecordNum > 0) {
- filterQueryString += ORDER + " c.key.timeStamp " + sortOrder;
- }
+ PfFilter timeStampFilter = new PfFilterFactory().createFilter(someClass);
+ filterQueryString = timeStampFilter.addFilter(filterQueryString,
+ name, startTime, endTime, filterMap, sortOrder, getRecordNum);
+
+
TypedQuery<T> query = mg.createQuery(setQueryTable(filterQueryString, someClass), someClass);
if (filterMap != null) {
@@ -382,11 +410,7 @@ public class DefaultPfDao implements PfDao {
}
}
if (name != null) {
- if (isRefTimestampKey(someClass)) {
- query.setParameter("parentKeyName", name);
- } else {
- query.setParameter("name", name);
- }
+ query.setParameter(timeStampFilter.getNameParameter(), name);
}
if (startTime != null) {
if (endTime != null) {
@@ -411,33 +435,6 @@ public class DefaultPfDao implements PfDao {
}
}
- /**
- * This method checks if the class invoking the DAO is using PfReferenceTimestamp Key.
- * @param someClass class that invoked Dao
- * @return true if the key is PfReferenceTimestampKey.
- */
- private <T extends PfConcept> boolean isRefTimestampKey(final Class<T> someClass) {
- try {
- return PfReferenceTimestampKey.class.isAssignableFrom(someClass.getDeclaredField("key").getType());
- } catch (NoSuchFieldException e) {
- LOGGER.error("Error verifying the key for reference timestamp:", e);
- return false;
- }
- }
-
- private String buildFilter(final Map<String, Object> filterMap, String filterQueryString,
- boolean isRefTimestampKey) {
- StringBuilder bld = new StringBuilder(filterQueryString);
- for (String key : filterMap.keySet()) {
- if (isRefTimestampKey) {
- bld.append("c.key.referenceKey." + key + "= :" + key + AND);
- } else {
- bld.append("c." + key + "= :" + key + AND);
- }
- }
- return bld.toString();
- }
-
@Override
public <T extends PfConcept> T get(final Class<T> someClass, final PfConceptKey key) {
return genericGet(someClass, key);
@@ -449,6 +446,11 @@ public class DefaultPfDao implements PfDao {
}
@Override
+ public <T extends PfConcept> T get(final Class<T> someClass, final PfGeneratedIdKey key) {
+ return genericGet(someClass, key);
+ }
+
+ @Override
public <T extends PfConcept> T get(final Class<T> someClass, final PfTimestampKey key) {
return genericGet(someClass, key);
}
@@ -540,6 +542,28 @@ public class DefaultPfDao implements PfDao {
}
@Override
+ 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();
+ }
+
+ final EntityManager mg = getEntityManager();
+ try {
+ // @formatter:off
+ return mg.createQuery(setQueryTable(SELECT_BY_TIMESTAMP_NOKEY, someClass), someClass)
+ .setParameter(NAME, key.getName())
+ .setParameter(VERSION, key.getVersion())
+ .setParameter(TIMESTAMP, Timestamp.from(timeStamp))
+ .getResultList();
+ // @formatter:on
+ } finally {
+ mg.close();
+ }
+ }
+
+ @Override
public <T extends PfConcept> T getConcept(final Class<T> someClass, final PfConceptKey key) {
if (someClass == null || key == null) {
return null;
@@ -644,45 +668,6 @@ public class DefaultPfDao implements PfDao {
}
/**
- * generate filter string with the filter value in TimestampKey.
- *
- * @param inputFilterString current filterString generated from FilterMap
- * @param name the pdp name the start timeStamp to filter from database, filter rule: startTime <= filteredRecord
- * timeStamp <= endTime. null for ignore start time.
- * @param endTime the end timeStamp to filter from database, filter rule: startTime <= filteredRecord timeStamp <=
- * endTime. null for ignore end time
- * @param isRefTimestampKey boolean value, set to true if the query invoked for pfReferenceTimestampKey
- * @return the filter string to query database
- */
- private String addKeyFilterString(String inputFilterString, final String name, final Instant startTime,
- final Instant endTime, final boolean isRefTimestampKey) {
- String filterQueryString;
- String inputFilter = inputFilterString;
- if (name != null) {
- if (isRefTimestampKey) {
- inputFilter += PARENT_NAME_REF_FILTER + AND;
- } else {
- inputFilter += NAME_FILTER + AND;
- }
- }
- if (startTime != null) {
- if (endTime != null) {
- filterQueryString = inputFilter + TIMESTAMP_START_FILTER + AND + TIMESTAMP_END_FILTER;
- } else {
- filterQueryString = inputFilter + TIMESTAMP_START_FILTER;
- }
- } else {
- if (endTime != null) {
- filterQueryString = inputFilter + TIMESTAMP_END_FILTER;
- } else {
- filterQueryString = inputFilter.substring(0, inputFilter.length() - AND.length());
- }
- }
-
- return filterQueryString;
- }
-
- /**
* check the result get from database and return the object.
*
* @param <T> the type of the object to get, a subclass of {@link PfConcept}
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/impl/PfNonTimestampKeyFilter.java b/models-dao/src/main/java/org/onap/policy/models/dao/impl/PfNonTimestampKeyFilter.java
new file mode 100644
index 000000000..9c9a3e844
--- /dev/null
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/impl/PfNonTimestampKeyFilter.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.dao.impl;
+
+import org.onap.policy.models.dao.PfFilter;
+
+/**
+ * This class is used to set the values for a non timeStamp key query.
+ *
+ */
+public class PfNonTimestampKeyFilter extends PfFilter {
+ private static final String NAME_FILTER = "c.key.name = :name";
+ private static final String TIMESTAMP_START_FILTER = "c.timeStamp >= :startTime";
+ private static final String TIMESTAMP_END_FILTER = "c.timeStamp <= :endTime";
+ private static final String TIMESTAMP_FILTER = " c.timeStamp ";
+ private static final String NAME_PARAMETER = "name";
+
+ /**
+ * The default constructor injects query strings.
+ */
+ public PfNonTimestampKeyFilter() {
+ setNameFilter(NAME_FILTER);
+ setTimeStampStartFilter(TIMESTAMP_START_FILTER);
+ setTimeStampEndFilter(TIMESTAMP_END_FILTER);
+ setTimeStampFilter(TIMESTAMP_FILTER);
+ setNameParameter(NAME_PARAMETER);
+ }
+}
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/impl/PfReferenceTimestampKeyFilter.java b/models-dao/src/main/java/org/onap/policy/models/dao/impl/PfReferenceTimestampKeyFilter.java
new file mode 100644
index 000000000..53802f306
--- /dev/null
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/impl/PfReferenceTimestampKeyFilter.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.dao.impl;
+
+import org.onap.policy.models.dao.PfFilter;
+
+/**
+ * This class is used to set the values for a reference timeStamp key query.
+ *
+ */
+public class PfReferenceTimestampKeyFilter extends PfFilter {
+ private static final String PARENT_NAME_REF_FILTER = "c.key.referenceKey.parentKeyName = :parentKeyName";
+ private static final String TIMESTAMP_START_FILTER = "c.key.timeStamp >= :startTime";
+ private static final String TIMESTAMP_END_FILTER = "c.key.timeStamp <= :endTime";
+ private static final String TIMESTAMP_FILTER = " c.key.timeStamp ";
+ private static final String NAME_PARAMETER = "parentKeyName";
+
+ /**
+ * The default constructor injects query strings.
+ */
+ public PfReferenceTimestampKeyFilter() {
+ setNameFilter(PARENT_NAME_REF_FILTER);
+ setTimeStampStartFilter(TIMESTAMP_START_FILTER);
+ setTimeStampEndFilter(TIMESTAMP_END_FILTER);
+ setTimeStampFilter(TIMESTAMP_FILTER);
+ setNameParameter(NAME_PARAMETER);
+ }
+}
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/impl/PfTimestampKeyFilter.java b/models-dao/src/main/java/org/onap/policy/models/dao/impl/PfTimestampKeyFilter.java
new file mode 100644
index 000000000..f01f80498
--- /dev/null
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/impl/PfTimestampKeyFilter.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.dao.impl;
+
+import org.onap.policy.models.dao.PfFilter;
+
+/**
+ * This class is used to set the values for a timeStamp key query.
+ *
+ */
+public class PfTimestampKeyFilter extends PfFilter {
+ private static final String NAME_FILTER = "c.key.name = :name";
+ private static final String TIMESTAMP_START_FILTER = "c.key.timeStamp >= :startTime";
+ private static final String TIMESTAMP_END_FILTER = "c.key.timeStamp <= :endTime";
+ private static final String TIMESTAMP_FILTER = " c.key.timeStamp ";
+ private static final String NAME_PARAMETER = "name";
+
+ /**
+ * The default constructor injects query strings.
+ */
+ public PfTimestampKeyFilter() {
+ setNameFilter(NAME_FILTER);
+ setTimeStampStartFilter(TIMESTAMP_START_FILTER);
+ setTimeStampEndFilter(TIMESTAMP_END_FILTER);
+ setTimeStampFilter(TIMESTAMP_FILTER);
+ setNameParameter(NAME_PARAMETER);
+ }
+}