Skip to content

Commit c29b606

Browse files
jphuiJonathan Hui
andauthored
Comment out equals() and hashcode() (#275)
<fix> : remove .equals() and .hashCode() overrides that go against encouraged Best Practices for Ebean This may have confounding effects on Ebean's ability to .find() records, introducing duplicity into the job-gms DB. --------- Co-authored-by: Jonathan Hui <jhui@jhui-ld2.linkedin.biz>
1 parent 6273d6e commit c29b606

File tree

2 files changed

+45
-38
lines changed

2 files changed

+45
-38
lines changed

dao-impl/ebean-dao/src/main/java/com/linkedin/metadata/dao/EbeanMetadataAspect.java

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
import lombok.NoArgsConstructor;
1616
import lombok.NonNull;
1717
import lombok.Setter;
18-
import lombok.SneakyThrows;
19-
import org.json.simple.JSONObject;
20-
import org.json.simple.parser.JSONParser;
18+
// import lombok.SneakyThrows;
19+
// import org.json.simple.JSONObject;
20+
// import org.json.simple.parser.JSONParser;
2121

2222

2323
/**
@@ -88,38 +88,39 @@ public static class PrimaryKey {
8888
@Column(name = CREATED_FOR_COLUMN, nullable = true)
8989
private String createdFor;
9090

91-
@SneakyThrows
92-
@Override
93-
public boolean equals(Object o) {
94-
if (o == null) {
95-
return false;
96-
}
97-
if (o.getClass() != this.getClass()) {
98-
return false;
99-
}
100-
EbeanMetadataAspect other = (EbeanMetadataAspect) o;
101-
102-
boolean primitiveEqualityCheck = this.key.equals(other.key)
103-
// either both metadata fields are null or both are equal (will check non-null equality after)
104-
&& ((this.metadata == null && other.metadata == null) || (this.metadata != null && other.metadata != null))
105-
&& Math.abs(this.createdOn.getTime() - other.getCreatedOn().getTime()) < 1000 // timestamps are considered equal if within 1s of each other
106-
&& this.createdBy.equals(other.getCreatedBy())
107-
// either both createdFor fields are null or both are equal (need to check this.createdFor != null to avoid NPE)
108-
&& ((this.createdFor == null && other.getCreatedFor() == null) || (this.createdFor != null && this.createdFor.equals(other.getCreatedFor())));
109-
if (!primitiveEqualityCheck) {
110-
return false;
111-
}
112-
113-
JSONParser parser = new JSONParser();
114-
JSONObject thisMetadata = (JSONObject) parser.parse(this.metadata);
115-
JSONObject otherMetadata = (JSONObject) parser.parse(other.metadata);
116-
return thisMetadata.equals(otherMetadata);
117-
}
118-
119-
@Override
120-
public int hashCode() {
121-
return super.hashCode();
122-
}
91+
// TODO (@jphui) META-18962 De-deduplicity investigation
92+
// @SneakyThrows
93+
// @Override
94+
// public boolean equals(Object o) {
95+
// if (o == null) {
96+
// return false;
97+
// }
98+
// if (o.getClass() != this.getClass()) {
99+
// return false;
100+
// }
101+
// EbeanMetadataAspect other = (EbeanMetadataAspect) o;
102+
103+
// boolean primitiveEqualityCheck = this.key.equals(other.key)
104+
// // either both metadata fields are null or both are equal (will check non-null equality after)
105+
// && ((this.metadata == null && other.metadata == null) || (this.metadata != null && other.metadata != null))
106+
// && Math.abs(this.createdOn.getTime() - other.getCreatedOn().getTime()) < 1000 // timestamps are considered equal if within 1s of each other
107+
// && this.createdBy.equals(other.getCreatedBy())
108+
// // either both createdFor fields are null or both are equal (need to check this.createdFor != null to avoid NPE)
109+
// && ((this.createdFor == null && other.getCreatedFor() == null) || (this.createdFor != null && this.createdFor.equals(other.getCreatedFor())));
110+
// if (!primitiveEqualityCheck) {
111+
// return false;
112+
// }
113+
114+
// JSONParser parser = new JSONParser();
115+
// JSONObject thisMetadata = (JSONObject) parser.parse(this.metadata);
116+
// JSONObject otherMetadata = (JSONObject) parser.parse(other.metadata);
117+
// return thisMetadata.equals(otherMetadata);
118+
// }
119+
120+
// @Override
121+
// public int hashCode() {
122+
// return super.hashCode();
123+
// }
123124

124125
@Override
125126
public String toString() {

dao-impl/ebean-dao/src/test/java/com/linkedin/metadata/dao/utils/EBeanDAOUtilsTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ public void testCompareResultsListEbeanMetadataAspectSingleton() {
8383
ema4.setCreatedFor("tester");
8484
ema4.setCreatedOn(new Timestamp(1234567890L));
8585

86-
assertFalse(EBeanDAOUtils.compareResults(Collections.singletonList(ema1), Collections.singletonList(ema4), "testMethod"));
86+
// TODO (@jphui) META-18962 De-deduplicity investigation
87+
// This test case is only used for new schema migration dual-mode validation
88+
// assertFalse(EBeanDAOUtils.compareResults(Collections.singletonList(ema1), Collections.singletonList(ema4), "testMethod"));
8789

8890
// same metadata, different order
8991
EbeanMetadataAspect ema4Different = new EbeanMetadataAspect();
@@ -106,13 +108,17 @@ public void testCompareResultsListEbeanMetadataAspectSingleton() {
106108

107109
assertTrue(EBeanDAOUtils.compareResults(Collections.singletonList(ema1), Collections.singletonList(ema5), "testMethod"));
108110

111+
// TODO (@jphui) META-18962 De-deduplicity investigation
112+
// This test case is only used for new schema migration dual-mode validation
109113
// different createdon
110114
ema5.setCreatedOn(new Timestamp(1234560000L)); // 7890 ms different than Timestamp(1234567890L)
111-
assertFalse(EBeanDAOUtils.compareResults(Collections.singletonList(ema1), Collections.singletonList(ema5), "testMethod"));
115+
// assertFalse(EBeanDAOUtils.compareResults(Collections.singletonList(ema1), Collections.singletonList(ema5), "testMethod"));
112116

117+
// TODO (@jphui) META-18962 De-deduplicity investigation
118+
// This test case is only used for new schema migration dual-mode validation
113119
// createdFor is nullable, set one EbeanMetadataAspect's createdFor field to null
114120
ema1.setCreatedFor(null);
115-
assertFalse(EBeanDAOUtils.compareResults(Collections.singletonList(ema1), Collections.singletonList(ema2), "testMethod"));
121+
// assertFalse(EBeanDAOUtils.compareResults(Collections.singletonList(ema1), Collections.singletonList(ema2), "testMethod"));
116122

117123
// both createdFor fields being null should return true
118124
ema2.setCreatedFor(null);

0 commit comments

Comments
 (0)