Skip to content

Commit

Permalink
#332 - Remove @DaTa annotation from jpa classes
Browse files Browse the repository at this point in the history
- Remove @DaTa and @EqualsAndHashCode annotations and replace them with @getter @Setter @tostring (excluding lazily loaded variables) and custom equals and hashcode methods
- Change id datatype from int to Long in entity classes
  • Loading branch information
michael-82 committed Sep 2, 2024
1 parent e98ba94 commit 3bde47b
Show file tree
Hide file tree
Showing 17 changed files with 391 additions and 113 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,43 @@
package de.numcodex.feasibility_gui_backend.dse.persistence;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.*;
import org.hibernate.proxy.HibernateProxy;

import java.io.Serializable;
import java.util.Objects;

@Entity
@Table(name = "dse_profile", schema = "public")
@Data
@EqualsAndHashCode
@Getter
@Setter
@ToString
@RequiredArgsConstructor
public class DseProfile implements Serializable {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
@Column(name = "id", nullable = false)
private int id;
private Long id;
@Basic
@Column(name = "url", nullable = false, length = -1)
private String url;
@Basic
@Column(name = "entry", columnDefinition = "json", nullable = false)
private String entry;

@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
if (thisEffectiveClass != oEffectiveClass) return false;
DseProfile that = (DseProfile) o;

Check warning on line 35 in src/main/java/de/numcodex/feasibility_gui_backend/dse/persistence/DseProfile.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/de/numcodex/feasibility_gui_backend/dse/persistence/DseProfile.java#L35

Added line #L35 was not covered by tests
return getId() != null && Objects.equals(getId(), that.getId());
}

@Override
public final int hashCode() {
return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package de.numcodex.feasibility_gui_backend.query.persistence;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToOne;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.proxy.HibernateProxy;

import java.sql.Timestamp;
import lombok.Data;
import java.util.Objects;

@Data
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
public class Query {

Expand All @@ -29,8 +26,25 @@ public class Query {

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(referencedColumnName = "id", name = "query_content_id")
@ToString.Exclude
private QueryContent queryContent;

@OneToOne(mappedBy = "query", cascade = CascadeType.ALL)
private SavedQuery savedQuery;

@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
if (thisEffectiveClass != oEffectiveClass) return false;
Query query = (Query) o;

Check warning on line 42 in src/main/java/de/numcodex/feasibility_gui_backend/query/persistence/Query.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/de/numcodex/feasibility_gui_backend/query/persistence/Query.java#L42

Added line #L42 was not covered by tests
return getId() != null && Objects.equals(getId(), query.getId());
}

@Override
public final int hashCode() {
return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package de.numcodex.feasibility_gui_backend.query.persistence;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Entity
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.proxy.HibernateProxy;

import java.util.Objects;

@Getter
@Setter
@ToString
@NoArgsConstructor
@Entity
public class QueryContent {

@Id
Expand All @@ -26,4 +26,20 @@ public class QueryContent {
public QueryContent(String queryContent) {
this.queryContent = queryContent;
}

@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
if (thisEffectiveClass != oEffectiveClass) return false;
QueryContent that = (QueryContent) o;

Check warning on line 37 in src/main/java/de/numcodex/feasibility_gui_backend/query/persistence/QueryContent.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/de/numcodex/feasibility_gui_backend/query/persistence/QueryContent.java#L37

Added line #L37 was not covered by tests
return getId() != null && Objects.equals(getId(), that.getId());
}

@Override
public final int hashCode() {
return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package de.numcodex.feasibility_gui_backend.query.persistence;

import static jakarta.persistence.FetchType.LAZY;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.proxy.HibernateProxy;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Embeddable;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.MapsId;
import java.io.Serializable;
import java.sql.Timestamp;
import lombok.Data;
import java.util.Objects;

import static jakarta.persistence.FetchType.LAZY;

@Data
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
public class QueryDispatch {

Expand All @@ -24,6 +23,7 @@ public class QueryDispatch {
@MapsId("queryId")
@JoinColumn(referencedColumnName = "id", name = "query_id", nullable = false)
@ManyToOne(fetch = LAZY)
@ToString.Exclude
private Query query;

@Column(name = "dispatched_at", insertable = false, updatable = false)
Expand All @@ -42,4 +42,20 @@ public static class QueryDispatchId implements Serializable {
@Column(name = "broker_type")
private BrokerClientType brokerType;
}

@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
if (thisEffectiveClass != oEffectiveClass) return false;
QueryDispatch that = (QueryDispatch) o;

Check warning on line 53 in src/main/java/de/numcodex/feasibility_gui_backend/query/persistence/QueryDispatch.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/de/numcodex/feasibility_gui_backend/query/persistence/QueryDispatch.java#L53

Added line #L53 was not covered by tests
return getId() != null && Objects.equals(getId(), that.getId());
}

@Override
public final int hashCode() {
return Objects.hash(id);

Check warning on line 59 in src/main/java/de/numcodex/feasibility_gui_backend/query/persistence/QueryDispatch.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/de/numcodex/feasibility_gui_backend/query/persistence/QueryDispatch.java#L59

Added line #L59 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package de.numcodex.feasibility_gui_backend.query.persistence;

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.proxy.HibernateProxy;

import java.sql.Timestamp;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.Data;

@Data
import java.util.Objects;

@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
public class QueryTemplate {

Expand All @@ -21,6 +20,7 @@ public class QueryTemplate {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(referencedColumnName = "id", name = "query_id")
@ToString.Exclude
private Query query;

@Column(name = "label", nullable = false)
Expand All @@ -31,4 +31,20 @@ public class QueryTemplate {

@Column(name = "last_modified", insertable = false)
private Timestamp lastModified;

@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
if (thisEffectiveClass != oEffectiveClass) return false;
QueryTemplate that = (QueryTemplate) o;

Check warning on line 42 in src/main/java/de/numcodex/feasibility_gui_backend/query/persistence/QueryTemplate.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/de/numcodex/feasibility_gui_backend/query/persistence/QueryTemplate.java#L42

Added line #L42 was not covered by tests
return getId() != null && Objects.equals(getId(), that.getId());
}

@Override
public final int hashCode() {
return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package de.numcodex.feasibility_gui_backend.query.persistence;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import lombok.Data;

@Data
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.proxy.HibernateProxy;

import java.util.Objects;

@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
public class SavedQuery {

Expand All @@ -20,6 +19,7 @@ public class SavedQuery {

@JoinColumn(referencedColumnName = "id", name = "query_id", nullable = false)
@OneToOne(fetch = FetchType.LAZY)
@ToString.Exclude
private Query query;

@Column(name = "label", nullable = false)
Expand All @@ -30,4 +30,20 @@ public class SavedQuery {

@Column(name = "result_size")
private Long resultSize;

@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
if (thisEffectiveClass != oEffectiveClass) return false;
SavedQuery that = (SavedQuery) o;

Check warning on line 41 in src/main/java/de/numcodex/feasibility_gui_backend/query/persistence/SavedQuery.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/de/numcodex/feasibility_gui_backend/query/persistence/SavedQuery.java#L41

Added line #L41 was not covered by tests
return getId() != null && Objects.equals(getId(), that.getId());
}

@Override
public final int hashCode() {
return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package de.numcodex.feasibility_gui_backend.query.persistence;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.proxy.HibernateProxy;

import java.sql.Timestamp;
import lombok.Data;
import java.util.Objects;

@Data
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
public class UserBlacklist {

Expand All @@ -21,4 +23,20 @@ public class UserBlacklist {

@Column(name = "blacklisted_at", insertable = false)
private Timestamp blacklistedAt;

@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
if (thisEffectiveClass != oEffectiveClass) return false;
UserBlacklist that = (UserBlacklist) o;

Check warning on line 34 in src/main/java/de/numcodex/feasibility_gui_backend/query/persistence/UserBlacklist.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/de/numcodex/feasibility_gui_backend/query/persistence/UserBlacklist.java#L34

Added line #L34 was not covered by tests
return getId() != null && Objects.equals(getId(), that.getId());
}

@Override
public final int hashCode() {
return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
}
}
Loading

0 comments on commit 3bde47b

Please sign in to comment.