Java 17 Upgrade
[policy/models.git] / models-base / src / main / java / org / onap / policy / models / base / PfReferenceTimestampKey.java
index 06af688..c7838d8 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021, 2023 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.
 
 package org.onap.policy.models.base;
 
-import java.sql.Timestamp;
+import jakarta.persistence.Column;
+import jakarta.persistence.Embeddable;
+import jakarta.persistence.Embedded;
+import jakarta.persistence.Temporal;
+import jakarta.persistence.TemporalType;
+import java.io.Serial;
 import java.time.Instant;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
-import javax.persistence.Column;
-import javax.persistence.Embeddable;
-import javax.persistence.Embedded;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
@@ -41,15 +45,17 @@ import org.onap.policy.common.utils.validation.Assertions;
 
 @Embeddable
 @Data
-@EqualsAndHashCode
+@EqualsAndHashCode(callSuper = false)
 public class PfReferenceTimestampKey extends PfKey {
+    @Serial
     private static final long serialVersionUID = 1130918285832617215L;
 
     private static final String TIMESTAMP_TOKEN = "timeStamp";
 
-    @Column(name = TIMESTAMP_TOKEN)
+    @Column(name = TIMESTAMP_TOKEN, precision = 3)
+    @Temporal(TemporalType.TIMESTAMP)
     @NotNull
-    private Timestamp timeStamp;
+    private Date timeStamp;
 
     @Embedded
     @Column
@@ -60,7 +66,7 @@ public class PfReferenceTimestampKey extends PfKey {
      */
     public PfReferenceTimestampKey() {
         this.referenceKey = new PfReferenceKey();
-        this.timeStamp = new Timestamp(0);
+        this.timeStamp = new Date(0);
     }
 
     /**
@@ -82,7 +88,7 @@ public class PfReferenceTimestampKey extends PfKey {
      */
     public PfReferenceTimestampKey(final PfConceptKey pfConceptKey) {
         this.referenceKey = new PfReferenceKey(pfConceptKey);
-        this.timeStamp = new Timestamp(0);
+        this.timeStamp = new Date(0);
     }
 
     /**
@@ -97,7 +103,7 @@ public class PfReferenceTimestampKey extends PfKey {
      */
     public PfReferenceTimestampKey(final PfConceptKey pfConceptKey, final String localName, final Instant instant) {
         this.referenceKey = new PfReferenceKey(pfConceptKey, localName);
-        this.timeStamp = Timestamp.from(instant);
+        this.timeStamp = Date.from(instant);
     }
 
     /**
@@ -113,7 +119,7 @@ public class PfReferenceTimestampKey extends PfKey {
     public PfReferenceTimestampKey(final PfReferenceKey parentReferenceKey, final String localName,
                                    final Instant instant) {
         this.referenceKey = new PfReferenceKey(parentReferenceKey, localName);
-        this.timeStamp = Timestamp.from(instant);
+        this.timeStamp = Date.from(instant);
     }
 
     /**
@@ -132,7 +138,7 @@ public class PfReferenceTimestampKey extends PfKey {
     public PfReferenceTimestampKey(final PfConceptKey pfConceptKey, final String parentLocalName,
                                    final String localName, final Instant instant) {
         this.referenceKey = new PfReferenceKey(pfConceptKey, parentLocalName, localName);
-        this.timeStamp = Timestamp.from(instant);
+        this.timeStamp = Date.from(instant);
     }
 
     /**
@@ -151,7 +157,7 @@ public class PfReferenceTimestampKey extends PfKey {
     public PfReferenceTimestampKey(final String parentKeyName, final String parentKeyVersion, final String localName,
                                    final Instant instant) {
         this.referenceKey = new PfReferenceKey(parentKeyName, parentKeyVersion, PfKey.NULL_KEY_NAME, localName);
-        this.timeStamp = Timestamp.from(instant);
+        this.timeStamp = Date.from(instant);
     }
 
     /**
@@ -172,7 +178,7 @@ public class PfReferenceTimestampKey extends PfKey {
     public PfReferenceTimestampKey(final String parentKeyName, final String parentKeyVersion,
                                    final String parentLocalName, final String localName, final Instant instant) {
         this.referenceKey = new PfReferenceKey(parentKeyName, parentKeyVersion, parentLocalName, localName);
-        this.timeStamp = Timestamp.from(instant);
+        this.timeStamp = Date.from(instant);
     }
 
 
@@ -183,7 +189,7 @@ public class PfReferenceTimestampKey extends PfKey {
      */
     public PfReferenceTimestampKey(final String id) {
         this.referenceKey = new PfReferenceKey(id.substring(0, id.lastIndexOf(':')));
-        this.timeStamp = new Timestamp(Long.parseLong(id.substring(id.lastIndexOf(':') + 1)));
+        this.timeStamp = new Date(Long.parseLong(id.substring(id.lastIndexOf(':') + 1)));
     }
 
 
@@ -202,7 +208,7 @@ public class PfReferenceTimestampKey extends PfKey {
     }
 
     public void setInstant(final Instant instant) {
-        setTimeStamp(Timestamp.from(instant));
+        setTimeStamp(Date.from(instant));
     }
 
     /**
@@ -210,6 +216,7 @@ public class PfReferenceTimestampKey extends PfKey {
      *
      * @return the pfReferenceTimestamp key
      */
+    @Override
     public PfReferenceTimestampKey getKey() {
         return this;
     }
@@ -218,6 +225,7 @@ public class PfReferenceTimestampKey extends PfKey {
      * Get the key as a string.
      * @return pfReferenceTimestamp key.
      */
+    @Override
     public String getId() {
         return getReferenceKey().getId() + ':' + getTimeStamp().getTime();
     }
@@ -292,10 +300,9 @@ public class PfReferenceTimestampKey extends PfKey {
 
     @Override
     public boolean isCompatible(@NonNull PfKey otherKey) {
-        if (!(otherKey instanceof PfReferenceTimestampKey)) {
+        if (!(otherKey instanceof PfReferenceTimestampKey otherReferenceKey)) {
             return false;
         }
-        final PfReferenceTimestampKey otherReferenceKey = (PfReferenceTimestampKey) otherKey;
 
         return this.getReferenceKey().getParentConceptKey().isCompatible(otherReferenceKey.getReferenceKey()
             .getParentConceptKey());