Java 17 Upgrade
[policy/models.git] / models-base / src / main / java / org / onap / policy / models / base / PfTimestampKey.java
index 22d29f7..ea12889 100644 (file)
@@ -2,8 +2,8 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy Model
  * ================================================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
- * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2021, 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2020-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.Temporal;
+import jakarta.persistence.TemporalType;
+import java.io.Serial;
 import java.time.Instant;
-import javax.persistence.Column;
-import javax.persistence.Embeddable;
+import java.util.Date;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NonNull;
@@ -37,6 +40,7 @@ import org.onap.policy.common.utils.validation.Assertions;
 @Data
 @EqualsAndHashCode(callSuper = false)
 public class PfTimestampKey extends PfKeyImpl {
+    @Serial
     private static final long serialVersionUID = -8410208962541783805L;
 
     private static final String TIMESTAMP_TOKEN = "timeStamp";
@@ -49,9 +53,10 @@ public class PfTimestampKey extends PfKeyImpl {
     @Pattern(regexp = VERSION_REGEXP)
     private String version;
 
-    @Column(name = TIMESTAMP_TOKEN)
+    @Column(name = TIMESTAMP_TOKEN, precision = 3)
+    @Temporal(TemporalType.TIMESTAMP)
     @NonNull
-    private Timestamp timeStamp;
+    private Date timeStamp;
 
 
     /**
@@ -74,14 +79,14 @@ public class PfTimestampKey extends PfKeyImpl {
     /**
      * Constructor to create a key with the specified name and version.
      *
-     * @param name the key name
+     * @param name    the key name
      * @param version the key version
      * @param instant the time stamp of key
      */
     public PfTimestampKey(@NonNull final String name, @NonNull final String version,
-            @NonNull final Instant instant) {
+                          @NonNull final Instant instant) {
         super(name, version);
-        this.timeStamp = Timestamp.from(instant);
+        this.timeStamp = Date.from(instant);
     }
 
     /**
@@ -91,7 +96,7 @@ public class PfTimestampKey extends PfKeyImpl {
      */
     public PfTimestampKey(final String id) {
         super(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)));
     }
 
     @Override
@@ -104,7 +109,7 @@ public class PfTimestampKey extends PfKeyImpl {
      *
      * @return a null key
      */
-    public static final PfTimestampKey getNullKey() {
+    public static PfTimestampKey getNullKey() {
         return new PfTimestampKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, Instant.EPOCH);
     }
 
@@ -113,7 +118,7 @@ public class PfTimestampKey extends PfKeyImpl {
     }
 
     public void setInstant(final Instant instant) {
-        setTimeStamp(Timestamp.from(instant));
+        setTimeStamp(Date.from(instant));
     }
 
     @Override