aboutsummaryrefslogtreecommitdiffstats
path: root/models-base/src/main
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-base/src/main
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-base/src/main')
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java69
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java42
2 files changed, 60 insertions, 51 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java
index 5cb639ed5..47a72e8cd 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java
@@ -20,6 +20,7 @@
package org.onap.policy.models.base;
+import java.sql.Timestamp;
import java.time.Instant;
import javax.persistence.Column;
import javax.persistence.Embeddable;
@@ -37,15 +38,16 @@ import org.onap.policy.common.utils.validation.Assertions;
*/
@Embeddable
@Data
-@EqualsAndHashCode
+@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class PfReferenceTimestampKey extends PfReferenceKey {
+ private static final long serialVersionUID = 1130918285832617215L;
+
private static final String TIMESTAMP_TOKEN = "timeStamp";
- private static final Instant DEFAULT_TIMESTAMP = Instant.EPOCH;
@Column(name = TIMESTAMP_TOKEN)
@NotNull
- private Instant timeStamp;
+ private Timestamp timeStamp;
/**
@@ -53,7 +55,7 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
*/
public PfReferenceTimestampKey() {
super();
- this.timeStamp = DEFAULT_TIMESTAMP;
+ this.timeStamp = new Timestamp(0);
}
/**
@@ -75,7 +77,7 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
*/
public PfReferenceTimestampKey(final PfConceptKey pfConceptKey) {
super(pfConceptKey);
- this.timeStamp = DEFAULT_TIMESTAMP;
+ this.timeStamp = new Timestamp(0);
}
/**
@@ -85,12 +87,12 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
* the parent concept key of this reference key
* @param localName
* the local name of this reference key
- * @param timeStamp
- * the timestamp for this reference key
+ * @param instant
+ * the time stamp for this reference key
*/
- public PfReferenceTimestampKey(final PfConceptKey pfConceptKey, final String localName, final Instant timeStamp) {
+ public PfReferenceTimestampKey(final PfConceptKey pfConceptKey, final String localName, final Instant instant) {
super(pfConceptKey, localName);
- this.timeStamp = timeStamp;
+ this.timeStamp = Timestamp.from(instant);
}
/**
@@ -100,13 +102,13 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
* the parent reference key of this reference key
* @param localName
* the local name of this reference key
- * @param timeStamp
- * the timestamp for this reference key
+ * @param instant
+ * the time stamp for this reference key
*/
public PfReferenceTimestampKey(final PfReferenceKey parentReferenceKey, final String localName,
- final Instant timeStamp) {
+ final Instant instant) {
super(parentReferenceKey, localName);
- this.timeStamp = timeStamp;
+ this.timeStamp = Timestamp.from(instant);
}
/**
@@ -119,13 +121,13 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
* the local name of the parent reference key of this reference key
* @param localName
* the local name of this reference key
- * @param timeStamp
- * the timestamp for this reference key
+ * @param instant
+ * the time stamp for this reference key
*/
public PfReferenceTimestampKey(final PfConceptKey pfConceptKey, final String parentLocalName,
- final String localName, final Instant timeStamp) {
+ final String localName, final Instant instant) {
super(pfConceptKey, parentLocalName, localName);
- this.timeStamp = timeStamp;
+ this.timeStamp = Timestamp.from(instant);
}
/**
@@ -138,13 +140,13 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
* the version of the parent concept key of this reference key
* @param localName
* the local name of this reference key
- * @param timeStamp
- * the timestamp for this reference key
+ * @param instant
+ * the time stamp for this reference key
*/
public PfReferenceTimestampKey(final String parentKeyName, final String parentKeyVersion, final String localName,
- final Instant timeStamp) {
+ final Instant instant) {
super(parentKeyName, parentKeyVersion, NULL_KEY_NAME, localName);
- this.timeStamp = timeStamp;
+ this.timeStamp = Timestamp.from(instant);
}
/**
@@ -159,13 +161,13 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
* the parent local name of this reference key
* @param localName
* the local name of this reference key
- * @param timeStamp
- * the timestamp for this reference key
+ * @param instant
+ * the instant for this reference key
*/
public PfReferenceTimestampKey(final String parentKeyName, final String parentKeyVersion,
- final String parentLocalName, final String localName, final Instant timeStamp) {
+ final String parentLocalName, final String localName, final Instant instant) {
super(parentKeyName, parentKeyVersion, parentLocalName, localName);
- this.timeStamp = timeStamp;
+ this.timeStamp = Timestamp.from(instant);
}
@@ -176,7 +178,7 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
*/
public PfReferenceTimestampKey(final String id) {
super(id.substring(0, id.lastIndexOf(':')));
- this.timeStamp = Instant.ofEpochSecond(Long.parseLong(id.substring(id.lastIndexOf(':') + 1)));
+ this.timeStamp = new Timestamp(Long.parseLong(id.substring(id.lastIndexOf(':') + 1)));
}
@@ -187,9 +189,16 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
*/
public static PfReferenceTimestampKey getNullKey() {
return new PfReferenceTimestampKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, PfKey.NULL_KEY_NAME,
- PfKey.NULL_KEY_NAME, DEFAULT_TIMESTAMP);
+ PfKey.NULL_KEY_NAME, Instant.EPOCH);
+ }
+
+ public Instant getInstant() {
+ return timeStamp.toInstant();
}
+ public void setInstant(final Instant instant) {
+ setTimeStamp(Timestamp.from(instant));
+ }
@Override
public PfReferenceTimestampKey getKey() {
@@ -198,12 +207,12 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
@Override
public String getId() {
- return super.getId() + ':' + getTimeStamp().getEpochSecond();
+ return super.getId() + ':' + getTimeStamp().getTime();
}
@Override
public boolean isNullKey() {
- return super.isNullKey() && getTimeStamp().getEpochSecond() == 0;
+ return super.isNullKey() && getTimeStamp().getTime() == 0;
}
@Override
@@ -215,7 +224,7 @@ public class PfReferenceTimestampKey extends PfReferenceKey {
return false;
}
if (!getTimeStamp().equals(otherConceptKey.timeStamp)) {
- return timeStamp.isAfter(otherConceptKey.timeStamp);
+ return timeStamp.after(otherConceptKey.timeStamp);
}
return super.isNewerThan(otherKey);
}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java
index d12466c60..a99651999 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy Model
* ================================================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,17 +23,18 @@
package org.onap.policy.models.base;
-import java.util.Date;
+import java.sql.Timestamp;
+import java.time.Instant;
import javax.persistence.Column;
import javax.persistence.Embeddable;
+import lombok.Data;
import lombok.EqualsAndHashCode;
-import lombok.Getter;
import lombok.NonNull;
import org.onap.policy.common.parameters.annotations.Pattern;
import org.onap.policy.common.utils.validation.Assertions;
@Embeddable
-@Getter
+@Data
@EqualsAndHashCode(callSuper = false)
public class PfTimestampKey extends PfKeyImpl {
private static final long serialVersionUID = -8410208962541783805L;
@@ -49,14 +50,15 @@ public class PfTimestampKey extends PfKeyImpl {
private String version;
@Column(name = TIMESTAMP_TOKEN)
- private Date timeStamp;
+ @NonNull
+ private Timestamp timeStamp;
/**
* The default constructor creates a null concept key.
*/
public PfTimestampKey() {
- this(NULL_KEY_NAME, NULL_KEY_VERSION, new Date(0));
+ this(NULL_KEY_NAME, NULL_KEY_VERSION, Instant.EPOCH);
}
/**
@@ -66,8 +68,7 @@ public class PfTimestampKey extends PfKeyImpl {
*/
public PfTimestampKey(@NonNull final PfTimestampKey copyConcept) {
super(copyConcept);
- long millis = copyConcept.getTimeStamp().getTime();
- this.timeStamp = new Date(millis);
+ this.timeStamp = copyConcept.getTimeStamp();
}
/**
@@ -75,12 +76,12 @@ public class PfTimestampKey extends PfKeyImpl {
*
* @param name the key name
* @param version the key version
- * @param timeStamp the timestamp of key
+ * @param instant the time stamp of key
*/
public PfTimestampKey(@NonNull final String name, @NonNull final String version,
- @NonNull final Date timeStamp) {
+ @NonNull final Instant instant) {
super(name, version);
- this.timeStamp = new Date(timeStamp.getTime());
+ this.timeStamp = Timestamp.from(instant);
}
/**
@@ -90,7 +91,7 @@ public class PfTimestampKey extends PfKeyImpl {
*/
public PfTimestampKey(final String id) {
super(id.substring(0, id.lastIndexOf(':')));
- this.timeStamp = new Date(Long.parseLong(id.substring(id.lastIndexOf(':') + 1)));
+ this.timeStamp = new Timestamp(Long.parseLong(id.substring(id.lastIndexOf(':') + 1)));
}
@Override
@@ -104,13 +105,15 @@ public class PfTimestampKey extends PfKeyImpl {
* @return a null key
*/
public static final PfTimestampKey getNullKey() {
- return new PfTimestampKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, new Date(0));
+ return new PfTimestampKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, Instant.EPOCH);
}
- @Override
- public String toString() {
- return "PfTimestampKey(name=" + getName() + ", version=" + getVersion() + ", timestamp="
- + getTimeStamp().getTime() + ")";
+ public Instant getInstant() {
+ return timeStamp.toInstant();
+ }
+
+ public void setInstant(final Instant instant) {
+ setTimeStamp(Timestamp.from(instant));;
}
@Override
@@ -130,10 +133,6 @@ public class PfTimestampKey extends PfKeyImpl {
return super.isNewerThan(otherKey);
}
- public void setTimeStamp(@NonNull final Date timeStamp) {
- this.timeStamp = new Date(timeStamp.getTime());
- }
-
@Override
public boolean isNullKey() {
return super.isNullKey() && getTimeStamp().getTime() == 0;
@@ -158,4 +157,5 @@ public class PfTimestampKey extends PfKeyImpl {
public void setVersion(@NonNull String version) {
this.version = Assertions.validateStringParameter(VERSION_TOKEN, version, getVersionRegEx());
}
+
}