/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2021 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 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 javax.persistence.Temporal;
+import javax.persistence.TemporalType;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
@Embeddable
@Data
-@EqualsAndHashCode
+@EqualsAndHashCode(callSuper = false)
public class PfReferenceTimestampKey extends PfKey {
private static final long serialVersionUID = 1130918285832617215L;
private static final String TIMESTAMP_TOKEN = "timeStamp";
@Column(name = TIMESTAMP_TOKEN)
+ @Temporal(TemporalType.TIMESTAMP)
@NotNull
- private Timestamp timeStamp;
+ private Date timeStamp;
@Embedded
@Column
*/
public PfReferenceTimestampKey() {
this.referenceKey = new PfReferenceKey();
- this.timeStamp = new Timestamp(0);
+ this.timeStamp = new Date(0);
}
/**
*/
public PfReferenceTimestampKey(final PfConceptKey pfConceptKey) {
this.referenceKey = new PfReferenceKey(pfConceptKey);
- this.timeStamp = new Timestamp(0);
+ this.timeStamp = new Date(0);
}
/**
*/
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);
}
/**
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);
}
/**
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);
}
/**
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);
}
/**
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);
}
*/
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)));
}
}
public void setInstant(final Instant instant) {
- setTimeStamp(Timestamp.from(instant));
+ setTimeStamp(Date.from(instant));
}
/**
* ONAP Policy Model
* ================================================================================
* Copyright (C) 2019-2021 Nordix Foundation.
- * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * 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 java.time.Instant;
+import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Embeddable;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
private String version;
@Column(name = TIMESTAMP_TOKEN)
+ @Temporal(TemporalType.TIMESTAMP)
@NonNull
- private Timestamp timeStamp;
+ private Date timeStamp;
/**
public PfTimestampKey(@NonNull final String name, @NonNull final String version,
@NonNull final Instant instant) {
super(name, version);
- this.timeStamp = Timestamp.from(instant);
+ this.timeStamp = Date.from(instant);
}
/**
*/
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
}
public void setInstant(final Instant instant) {
- setTimeStamp(Timestamp.from(instant));
+ setTimeStamp(Date.from(instant));
}
@Override
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import java.sql.Timestamp;
import java.time.Instant;
+import java.util.Date;
import org.junit.Test;
public class PfReferenceTimestampKeyTest {
assertEquals(LOCAL_NAME,
new PfReferenceTimestampKey(new PfReferenceKey(), LOCAL_NAME, Instant.ofEpochSecond(timeStamp))
.getReferenceKey().getLocalName());
- assertEquals(Timestamp.from(Instant.ofEpochSecond(timeStamp)), new PfReferenceTimestampKey(new PfConceptKey(),
+ assertEquals(Date.from(Instant.ofEpochSecond(timeStamp)), new PfReferenceTimestampKey(new PfConceptKey(),
PARENT_LOCAL_NAME, LOCAL_NAME, Instant.ofEpochSecond(timeStamp)).getTimeStamp());
assertThat(new PfReferenceTimestampKey("ParentKeyName", VERSION001, PARENT_LOCAL_NAME, LOCAL_NAME,
testReferenceKey.getReferenceKey().setLocalName("LN");
assertEquals("LN", testReferenceKey.getReferenceKey().getLocalName());
- testReferenceKey.setTimeStamp(Timestamp.from(DEFAULT_TIMESTAMP));
- assertEquals(Timestamp.from(DEFAULT_TIMESTAMP), testReferenceKey.getTimeStamp());
+ testReferenceKey.setTimeStamp(Date.from(DEFAULT_TIMESTAMP));
+ assertEquals(Date.from(DEFAULT_TIMESTAMP), testReferenceKey.getTimeStamp());
assertThatThrownBy(() -> testReferenceKey.isCompatible(null))
PfReferenceTimestampKey clonedReferenceKey = new PfReferenceTimestampKey(testReferenceKey);
- assertEquals("PfReferenceTimestampKey(timeStamp=" + Timestamp.from(Instant.EPOCH) + ","
+ assertEquals("PfReferenceTimestampKey(timeStamp=" + Date.from(Instant.EPOCH) + ","
+ " referenceKey=PfReferenceKey(parentKeyName=PKN, parentKeyVersion=0.0.1, "
+ "parentLocalName=ParentLocalName, localName=LN))", clonedReferenceKey.toString());
assertEquals(testReferenceKey, clonedReferenceKey);
assertNotEquals(testReferenceKey, new PfReferenceTimestampKey("PKN", VERSION001, "PLN",
"LN", Instant.ofEpochSecond(timeStamp)));
- testReferenceKey.setTimeStamp(Timestamp.from(Instant.ofEpochSecond(timeStamp)));
+ testReferenceKey.setTimeStamp(Date.from(Instant.ofEpochSecond(timeStamp)));
assertEquals(testReferenceKey, new PfReferenceTimestampKey("PKN", VERSION001, PARENT_LOCAL_NAME, "LN",
Instant.ofEpochSecond(timeStamp)));
assertThatThrownBy(() -> key1.isNewerThan((PfKey) null)).isInstanceOf(NullPointerException.class)
.hasMessageMatching("^otherKey is marked .*on.*ull but is null$");
- key2.setTimeStamp(Timestamp.from(Instant.ofEpochSecond(timeStamp).plusSeconds(80)));
+ key2.setTimeStamp(Date.from(Instant.ofEpochSecond(timeStamp).plusSeconds(80)));
assertTrue(key2.isNewerThan(key1));
}
/*-
* ============LICENSE_START=======================================================
* 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");
* you may not use this file except in compliance with the License.
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import java.sql.Timestamp;
import java.time.Instant;
+import java.util.Date;
import org.junit.Test;
public class PfTimestampKeyTest {
PfTimestampKey someKey0 = new PfTimestampKey();
assertEquals(PfTimestampKey.getNullKey(), someKey0);
assertTrue(someKey0.isNullKey());
- assertEquals("PfTimestampKey(name=NULL, version=0.0.0, timeStamp=" + Timestamp.from(Instant.EPOCH) + ")",
+ assertEquals("PfTimestampKey(name=NULL, version=0.0.0, timeStamp=" + Date.from(Instant.EPOCH) + ")",
someKey0.toString());
PfTimestampKey someKey1 = new PfTimestampKey("my-name", VERSION001, Instant.ofEpochSecond(timeStamp));
assertEquals(someKey1, someKey3);
assertFalse(someKey1.isNullVersion());
assertEquals("PfTimestampKey(name=my-name, version=0.0.1, timeStamp="
- + Timestamp.from(Instant.ofEpochSecond(timeStamp)) + ")", someKey1.toString());
+ + Date.from(Instant.ofEpochSecond(timeStamp)) + ")", someKey1.toString());
assertEquals("my-name", someKey1.getName());
assertEquals(VERSION001, someKey1.getVersion());
assertFalse(someKey1.isNewerThan(someKey2));
assertThatThrownBy(() -> someKey1.isNewerThan((PfKey) null)).isInstanceOf(NullPointerException.class)
.hasMessageMatching("^otherKey is marked .*on.*ull but is null$");
- someKey2.setTimeStamp(Timestamp.from(Instant.ofEpochSecond(timeStamp).plusMillis(90)));
+ someKey2.setTimeStamp(Date.from(Instant.ofEpochSecond(timeStamp).plusMillis(90)));
assertTrue(someKey2.isNewerThan(someKey1));
someKey3.setName("my-name3");
assertTrue(someKey3.isNewerThan(someKey1));