aboutsummaryrefslogtreecommitdiffstats
path: root/models-dao/src
diff options
context:
space:
mode:
authorrameshiyer27 <ramesh.murugan.iyer@est.tech>2021-02-16 16:25:18 +0000
committerrameshiyer27 <ramesh.murugan.iyer@est.tech>2021-02-19 15:26:11 +0000
commit5a94ebda407e82a8df4abea1b8a916ea4f88d9cd (patch)
tree9372cfd5e716196ddd1bf908d4da5db7e64f93c0 /models-dao/src
parent7e4f9950ed004042e36e7e1f6f78224d62888e74 (diff)
Refactor timestamp property in policy models to use Instant
Updated JPA classes to use java.sql.TImestamp rather than Instant. Issue-ID: POLICY-3069 Signed-off-by: zrrmmua <ramesh.murugan.iyer@est.tech> Change-Id: If5b874ec96931d4b8dd142d46a9980e83a4708fc
Diffstat (limited to 'models-dao/src')
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/PfDao.java8
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java19
-rw-r--r--models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java10
3 files changed, 19 insertions, 18 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 6c862bb64..05f907fdd 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,8 +21,8 @@
package org.onap.policy.models.dao;
+import java.time.Instant;
import java.util.Collection;
-import java.util.Date;
import java.util.List;
import java.util.Map;
import org.onap.policy.models.base.PfConcept;
@@ -168,8 +168,8 @@ public interface PfDao {
* @param getRecordNum Total query count from database
* @return the objects that was retrieved from the database
*/
- <T extends PfConcept> List<T> getFiltered(Class<T> someClass, String name, String version, Date startTime,
- Date endTime, Map<String, Object> filterMap, String sortOrder, int getRecordNum);
+ <T extends PfConcept> List<T> getFiltered(Class<T> someClass, String name, String version, Instant startTime,
+ Instant endTime, Map<String, Object> filterMap, String sortOrder, int getRecordNum);
/**
* Get an object from the database, referred to by 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 5e89ee591..c29c4bf2d 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,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,9 +21,10 @@
package org.onap.policy.models.dao.impl;
+import java.sql.Timestamp;
+import java.time.Instant;
import java.util.Collection;
import java.util.Collections;
-import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.persistence.EntityManager;
@@ -355,7 +356,7 @@ public class DefaultPfDao implements PfDao {
@Override
public <T extends PfConcept> List<T> getFiltered(final Class<T> someClass, final String name, final String version,
- final Date startTime, final Date endTime, final Map<String, Object> filterMap, final String sortOrder,
+ final Instant startTime, final Instant endTime, final Map<String, Object> filterMap, final String sortOrder,
final int getRecordNum) {
final EntityManager mg = getEntityManager();
@@ -381,14 +382,14 @@ public class DefaultPfDao implements PfDao {
}
if (startTime != null) {
if (endTime != null) {
- query.setParameter("startTime", startTime);
- query.setParameter("endTime", endTime);
+ query.setParameter("startTime", Timestamp.from(startTime));
+ query.setParameter("endTime", Timestamp.from(endTime));
} else {
- query.setParameter("startTime", startTime);
+ query.setParameter("startTime", Timestamp.from(startTime));
}
} else {
if (endTime != null) {
- query.setParameter("endTime", endTime);
+ query.setParameter("endTime", Timestamp.from(endTime));
}
}
if (getRecordNum > 0) {
@@ -620,8 +621,8 @@ public class DefaultPfDao implements PfDao {
* endTime. null for ignore end time
* @return the filter string to query database
*/
- private String addKeyFilterString(String inputFilterString, final String name, final Date startTime,
- final Date endTime) {
+ private String addKeyFilterString(String inputFilterString, final String name, final Instant startTime,
+ final Instant endTime) {
String filterQueryString;
if (name != null) {
inputFilterString += NAME_FILTER + AND;
diff --git a/models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java b/models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java
index 040b76b9b..1ba2e4139 100644
--- a/models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java
+++ b/models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,8 +27,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import java.time.Instant;
import java.util.ArrayList;
-import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -58,9 +58,9 @@ public class EntityTest {
private static final String VERSION003 = "0.0.3";
private static final String VERSION002 = "0.0.2";
private static final String VERSION001 = "0.0.1";
- private static final Date TIMESTAMP0 = new Date();
- private static final Date TIMESTAMP1 = new Date();
- private static final Date TIMESTAMP2 = new Date();
+ private static final Instant TIMESTAMP0 = Instant.ofEpochSecond(1613494293);
+ private static final Instant TIMESTAMP1 = Instant.ofEpochSecond(1613494293).plusSeconds(55);
+ private static final Instant TIMESTAMP2 = Instant.ofEpochSecond(1613494293).plusSeconds(90);
private PfDao pfDao;
@Test