Bael 7452 fixes (#15729)

* BAEL-7452: Renamed service getter

* BAEL-7452: Delombok and cleanup
This commit is contained in:
Eugene Kovko 2024-01-25 18:30:04 +01:00 committed by GitHub
parent 8154f89f17
commit 450e82b2ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
40 changed files with 1406 additions and 90 deletions

View File

@ -57,11 +57,6 @@
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
</dependencies>
<build>
@ -81,7 +76,6 @@
<db.util.version>1.0.7</db.util.version>
<hypersistence-utils.version>3.7.0</hypersistence-utils.version>
<jackson.version>2.16.0</jackson.version>
<lombok.version>1.18.28</lombok.version>
</properties>
</project>

View File

@ -50,7 +50,7 @@ public class Service<S> extends ParametrizationAware<S> {
public int getUserByIdWithFunction(Long id, ToIntFunction<S> function) {
Optional<S> optionalUser = repository.findById(id);
if(optionalUser.isPresent()) {
if (optionalUser.isPresent()) {
return function.applyAsInt(optionalUser.get());
} else {
return 0;

View File

@ -4,9 +4,8 @@ import com.fasterxml.jackson.annotation.JsonBackReference;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import lombok.Data;
import java.util.Objects;
@Data
@Entity
public class Comment {
@ -22,4 +21,63 @@ public class Comment {
@ManyToOne
private Post post;
public Comment() {
}
public Long getId() {
return this.id;
}
public String getText() {
return this.text;
}
public User getAuthor() {
return this.author;
}
public Post getPost() {
return this.post;
}
public void setId(Long id) {
this.id = id;
}
public void setText(String text) {
this.text = text;
}
public void setAuthor(User author) {
this.author = author;
}
public void setPost(Post post) {
this.post = post;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Comment comment = (Comment) o;
return Objects.equals(id, comment.id);
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "Comment(id=" + this.getId() + ", text=" + this.getText() + ", author=" + this.getAuthor() + ", post=" + this.getPost()
+ ")";
}
}

View File

@ -6,9 +6,8 @@ import jakarta.persistence.Id;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.Table;
import java.util.List;
import lombok.Data;
import java.util.Objects;
@Data
@Entity(name = "interest_group")
@Table(name = "interest_group")
public class Group {
@ -20,4 +19,54 @@ public class Group {
@ManyToMany(fetch = FetchType.EAGER)
private List<User> members;
public Group() {
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public List<User> getMembers() {
return this.members;
}
public void setId(Long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setMembers(List<User> members) {
this.members = members;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Group group = (Group) o;
return Objects.equals(id, group.id);
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "Group(id=" + this.getId() + ", name=" + this.getName() + ", members=" + this.getMembers() + ")";
}
}

View File

@ -10,10 +10,9 @@ import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import java.util.List;
import lombok.Data;
import java.util.Objects;
@Entity
@Data
public class Post {
@Id
@ -29,4 +28,63 @@ public class Post {
@JsonBackReference
@ManyToOne
private User author;
public Post() {
}
public Long getId() {
return this.id;
}
public String getContent() {
return this.content;
}
public List<Comment> getComments() {
return this.comments;
}
public User getAuthor() {
return this.author;
}
public void setId(Long id) {
this.id = id;
}
public void setContent(String content) {
this.content = content;
}
public void setComments(List<Comment> comments) {
this.comments = comments;
}
public void setAuthor(User author) {
this.author = author;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Post post = (Post) o;
return Objects.equals(id, post.id);
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "Post(id=" + this.getId() + ", content=" + this.getContent() + ", comments=" + this.getComments() + ", author="
+ this.getAuthor() + ")";
}
}

View File

@ -6,10 +6,9 @@ import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;
import jakarta.persistence.OneToOne;
import lombok.Data;
import java.util.Objects;
@Entity
@Data
public class Profile {
@Id
@ -24,5 +23,72 @@ public class Profile {
@OneToOne(mappedBy = "profile")
@JoinColumn(unique = true)
private User user;
public Profile() {
}
public Long getId() {
return this.id;
}
public String getBiography() {
return this.biography;
}
public String getWebsite() {
return this.website;
}
public String getProfilePictureUrl() {
return this.profilePictureUrl;
}
public User getUser() {
return this.user;
}
public void setId(Long id) {
this.id = id;
}
public void setBiography(String biography) {
this.biography = biography;
}
public void setWebsite(String website) {
this.website = website;
}
public void setProfilePictureUrl(String profilePictureUrl) {
this.profilePictureUrl = profilePictureUrl;
}
public void setUser(User user) {
this.user = user;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Profile profile = (Profile) o;
return Objects.equals(id, profile.id);
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "Profile(id=" + this.getId() + ", biography=" + this.getBiography() + ", website=" + this.getWebsite()
+ ", profilePictureUrl=" + this.getProfilePictureUrl() + ", user=" + this.getUser() + ")";
}
}

View File

@ -10,9 +10,8 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import java.util.List;
import lombok.Data;
import java.util.Objects;
@Data
@Entity(name = "simple_user")
@Table(name = "simple_user")
public class User {
@ -33,4 +32,79 @@ public class User {
@ManyToMany(mappedBy = "members", fetch = FetchType.EAGER)
private List<Group> groups;
public User() {
}
public Long getId() {
return this.id;
}
public String getUsername() {
return this.username;
}
public String getEmail() {
return this.email;
}
public Profile getProfile() {
return this.profile;
}
public List<Post> getPosts() {
return this.posts;
}
public List<Group> getGroups() {
return this.groups;
}
public void setId(Long id) {
this.id = id;
}
public void setUsername(String username) {
this.username = username;
}
public void setEmail(String email) {
this.email = email;
}
public void setProfile(Profile profile) {
this.profile = profile;
}
public void setPosts(List<Post> posts) {
this.posts = posts;
}
public void setGroups(List<Group> groups) {
this.groups = groups;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
User user = (User) o;
return Objects.equals(id, user.id);
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "User(id=" + this.getId() + ", username=" + this.getUsername() + ", email=" + this.getEmail() + ", profile="
+ this.getProfile() + ", posts=" + this.getPosts() + ", groups=" + this.getGroups() + ")";
}
}

View File

@ -6,9 +6,8 @@ import jakarta.persistence.Id;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.Table;
import java.util.List;
import lombok.Data;
import java.util.Objects;
@Data
@Entity(name = "interest_group")
@Table(name = "interest_group")
public class Group {
@ -20,4 +19,54 @@ public class Group {
@ManyToMany(fetch = FetchType.EAGER)
private List<User> members;
public Group() {
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public List<User> getMembers() {
return this.members;
}
public void setId(Long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setMembers(List<User> members) {
this.members = members;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Group group = (Group) o;
return Objects.equals(id, group.id);
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "Group(id=" + this.getId() + ", name=" + this.getName() + ", members=" + this.getMembers() + ")";
}
}

View File

@ -5,10 +5,9 @@ import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import lombok.Data;
import java.util.Objects;
@Entity
@Data
public class Post {
@Id
@ -20,4 +19,55 @@ public class Post {
@JsonBackReference
@ManyToOne
private User author;
public Post() {
}
public Long getId() {
return this.id;
}
public String getContent() {
return this.content;
}
public User getAuthor() {
return this.author;
}
public void setId(Long id) {
this.id = id;
}
public void setContent(String content) {
this.content = content;
}
public void setAuthor(User author) {
this.author = author;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Post post = (Post) o;
return Objects.equals(id, post.id);
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "Post(id=" + this.getId() + ", content=" + this.getContent() + ", author=" + this.getAuthor() + ")";
}
}

View File

@ -9,9 +9,7 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.List;
import java.util.Objects;
import lombok.Data;
@Data
@Entity(name = "simple_user")
@Table(name = "simple_user")
public class User {
@ -25,6 +23,41 @@ public class User {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "author", fetch = FetchType.EAGER)
protected List<Post> posts;
public User() {
}
public Long getId() {
return this.id;
}
public String getUsername() {
return this.username;
}
public String getEmail() {
return this.email;
}
public List<Post> getPosts() {
return this.posts;
}
public void setId(Long id) {
this.id = id;
}
public void setUsername(String username) {
this.username = username;
}
public void setEmail(String email) {
this.email = email;
}
public void setPosts(List<Post> posts) {
this.posts = posts;
}
@Override
public boolean equals(Object o) {
if (this == o) {
@ -43,4 +76,9 @@ public class User {
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "User(id=" + this.getId() + ", username=" + this.getUsername() + ", email=" + this.getEmail() + ", posts=" + this.getPosts()
+ ")";
}
}

View File

@ -5,10 +5,9 @@ import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import lombok.Data;
import java.util.Objects;
@Entity
@Data
public class Post {
@Id
@ -20,4 +19,54 @@ public class Post {
@JsonBackReference
@ManyToOne
private User author;
public Post() {
}
public Long getId() {
return this.id;
}
public String getContent() {
return this.content;
}
public User getAuthor() {
return this.author;
}
public void setId(Long id) {
this.id = id;
}
public void setContent(String content) {
this.content = content;
}
public void setAuthor(User author) {
this.author = author;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Post post = (Post) o;
return Objects.equals(id, post.id);
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "Post(id=" + this.getId() + ", content=" + this.getContent() + ", author=" + this.getAuthor() + ")";
}
}

View File

@ -8,9 +8,8 @@ import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.List;
import lombok.Data;
import java.util.Objects;
@Data
@Entity(name = "simple_user")
@Table(name = "simple_user")
public class User {
@ -23,4 +22,63 @@ public class User {
@JsonManagedReference
@OneToMany(cascade = CascadeType.ALL, mappedBy = "author", fetch = FetchType.EAGER)
protected List<Post> posts;
public User() {
}
public Long getId() {
return this.id;
}
public String getUsername() {
return this.username;
}
public String getEmail() {
return this.email;
}
public List<Post> getPosts() {
return this.posts;
}
public void setId(Long id) {
this.id = id;
}
public void setUsername(String username) {
this.username = username;
}
public void setEmail(String email) {
this.email = email;
}
public void setPosts(List<Post> posts) {
this.posts = posts;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
User user = (User) o;
return Objects.equals(id, user.id);
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "User(id=" + this.getId() + ", username=" + this.getUsername() + ", email=" + this.getEmail() + ", posts=" + this.getPosts()
+ ")";
}
}

View File

@ -5,9 +5,7 @@ import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import java.util.Objects;
import lombok.Data;
@Data
@Entity
public class Comment {
@ -23,6 +21,41 @@ public class Comment {
@ManyToOne
private Post post;
public Comment() {
}
public Long getId() {
return this.id;
}
public String getText() {
return this.text;
}
public User getAuthor() {
return this.author;
}
public Post getPost() {
return this.post;
}
public void setId(Long id) {
this.id = id;
}
public void setText(String text) {
this.text = text;
}
public void setAuthor(User author) {
this.author = author;
}
public void setPost(Post post) {
this.post = post;
}
@Override
public boolean equals(Object o) {
if (this == o) {
@ -41,4 +74,9 @@ public class Comment {
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "Comment(id=" + this.getId() + ", text=" + this.getText() + ", author=" + this.getAuthor() + ", post=" + this.getPost()
+ ")";
}
}

View File

@ -7,9 +7,7 @@ import jakarta.persistence.ManyToMany;
import jakarta.persistence.Table;
import java.util.Objects;
import java.util.Set;
import lombok.Data;
@Data
@Entity(name = "interest_group")
@Table(name = "interest_group")
public class Group {
@ -22,6 +20,33 @@ public class Group {
@ManyToMany(fetch = FetchType.EAGER)
private Set<User> members;
public Group() {
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public Set<User> getMembers() {
return this.members;
}
public void setId(Long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setMembers(Set<User> members) {
this.members = members;
}
@Override
public boolean equals(Object o) {
if (this == o) {
@ -40,4 +65,8 @@ public class Group {
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "Group(id=" + this.getId() + ", name=" + this.getName() + ", members=" + this.getMembers() + ")";
}
}

View File

@ -11,10 +11,8 @@ import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import java.util.Objects;
import java.util.Set;
import lombok.Data;
@Entity
@Data
public class Post {
@Id
@ -31,6 +29,41 @@ public class Post {
@ManyToOne
private User author;
public Post() {
}
public Long getId() {
return this.id;
}
public String getContent() {
return this.content;
}
public Set<Comment> getComments() {
return this.comments;
}
public User getAuthor() {
return this.author;
}
public void setId(Long id) {
this.id = id;
}
public void setContent(String content) {
this.content = content;
}
public void setComments(Set<Comment> comments) {
this.comments = comments;
}
public void setAuthor(User author) {
this.author = author;
}
@Override
public boolean equals(Object o) {
if (this == o) {
@ -49,4 +82,9 @@ public class Post {
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "Post(id=" + this.getId() + ", content=" + this.getContent() + ", comments=" + this.getComments() + ", author="
+ this.getAuthor() + ")";
}
}

View File

@ -6,10 +6,9 @@ import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Lob;
import jakarta.persistence.OneToOne;
import lombok.Data;
import java.util.Objects;
@Entity
@Data
public class Profile {
@Id
@ -24,5 +23,72 @@ public class Profile {
@OneToOne(mappedBy = "profile")
@JoinColumn(unique = true)
private User user;
public Profile() {
}
public Long getId() {
return this.id;
}
public String getBiography() {
return this.biography;
}
public String getWebsite() {
return this.website;
}
public String getProfilePictureUrl() {
return this.profilePictureUrl;
}
public User getUser() {
return this.user;
}
public void setId(Long id) {
this.id = id;
}
public void setBiography(String biography) {
this.biography = biography;
}
public void setWebsite(String website) {
this.website = website;
}
public void setProfilePictureUrl(String profilePictureUrl) {
this.profilePictureUrl = profilePictureUrl;
}
public void setUser(User user) {
this.user = user;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Profile profile = (Profile) o;
return Objects.equals(id, profile.id);
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "Profile(id=" + this.getId() + ", biography=" + this.getBiography() + ", website=" + this.getWebsite()
+ ", profilePictureUrl=" + this.getProfilePictureUrl() + ", user=" + this.getUser() + ")";
}
}

View File

@ -11,9 +11,7 @@ import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import java.util.Objects;
import java.util.Set;
import lombok.Data;
@Data
@Entity(name = "simple_user")
@Table(name = "simple_user")
public class User {
@ -35,6 +33,57 @@ public class User {
@ManyToMany(mappedBy = "members", fetch = FetchType.EAGER)
private Set<Group> groups;
public User() {
}
public Long getId() {
return this.id;
}
public String getUsername() {
return this.username;
}
public String getEmail() {
return this.email;
}
public Profile getProfile() {
return this.profile;
}
public Set<Post> getPosts() {
return this.posts;
}
public Set<Group> getGroups() {
return this.groups;
}
public void setId(Long id) {
this.id = id;
}
public void setUsername(String username) {
this.username = username;
}
public void setEmail(String email) {
this.email = email;
}
public void setProfile(Profile profile) {
this.profile = profile;
}
public void setPosts(Set<Post> posts) {
this.posts = posts;
}
public void setGroups(Set<Group> groups) {
this.groups = groups;
}
@Override
public boolean equals(Object o) {
if (this == o) {
@ -53,4 +102,9 @@ public class User {
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "User(id=" + this.getId() + ", username=" + this.getUsername() + ", email=" + this.getEmail() + ", profile="
+ this.getProfile() + ", posts=" + this.getPosts() + ", groups=" + this.getGroups() + ")";
}
}

View File

@ -4,10 +4,9 @@ import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.Table;
import java.util.Objects;
import java.util.Set;
import lombok.Data;
@Data
@Entity(name = "interest_group")
@Table(name = "interest_group")
public class Group {
@ -19,4 +18,54 @@ public class Group {
@ManyToMany
private Set<User> members;
public Group() {
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public Set<User> getMembers() {
return this.members;
}
public void setId(Long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setMembers(Set<User> members) {
this.members = members;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Group group = (Group) o;
return Objects.equals(id, group.id);
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "Group(id=" + this.getId() + ", name=" + this.getName() + ", members=" + this.getMembers() + ")";
}
}

View File

@ -6,10 +6,8 @@ import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import java.util.Objects;
import lombok.Data;
@Entity
@Data
public class Post {
@Id
@ -22,6 +20,33 @@ public class Post {
@ManyToOne
private User author;
public Post() {
}
public Long getId() {
return this.id;
}
public String getContent() {
return this.content;
}
public User getAuthor() {
return this.author;
}
public void setId(Long id) {
this.id = id;
}
public void setContent(String content) {
this.content = content;
}
public void setAuthor(User author) {
this.author = author;
}
@Override
public boolean equals(Object o) {
if (this == o) {
@ -40,4 +65,8 @@ public class Post {
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "Post(id=" + this.getId() + ", content=" + this.getContent() + ", author=" + this.getAuthor() + ")";
}
}

View File

@ -8,9 +8,7 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.Objects;
import java.util.Set;
import lombok.Data;
@Data
@Entity(name = "simple_user")
@Table(name = "simple_user")
public class User {
@ -24,6 +22,41 @@ public class User {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "author")
protected Set<Post> posts;
public User() {
}
public Long getId() {
return this.id;
}
public String getUsername() {
return this.username;
}
public String getEmail() {
return this.email;
}
public Set<Post> getPosts() {
return this.posts;
}
public void setId(Long id) {
this.id = id;
}
public void setUsername(String username) {
this.username = username;
}
public void setEmail(String email) {
this.email = email;
}
public void setPosts(Set<Post> posts) {
this.posts = posts;
}
@Override
public boolean equals(Object o) {
if (this == o) {
@ -42,4 +75,9 @@ public class User {
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "User(id=" + this.getId() + ", username=" + this.getUsername() + ", email=" + this.getEmail() + ", posts=" + this.getPosts()
+ ")";
}
}

View File

@ -5,10 +5,9 @@ import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.Table;
import java.util.Objects;
import java.util.Set;
import lombok.Data;
@Data
@Entity(name = "interest_group")
@Table(name = "interest_group")
public class Group {
@ -20,4 +19,54 @@ public class Group {
@ManyToMany(fetch = FetchType.EAGER)
private Set<User> members;
public Group() {
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public Set<User> getMembers() {
return this.members;
}
public void setId(Long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setMembers(Set<User> members) {
this.members = members;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Group group = (Group) o;
return Objects.equals(id, group.id);
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "Group(id=" + this.getId() + ", name=" + this.getName() + ", members=" + this.getMembers() + ")";
}
}

View File

@ -6,10 +6,8 @@ import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import java.util.Objects;
import lombok.Data;
@Entity
@Data
public class Post {
@Id
@ -22,6 +20,33 @@ public class Post {
@ManyToOne
private User author;
public Post() {
}
public Long getId() {
return this.id;
}
public String getContent() {
return this.content;
}
public User getAuthor() {
return this.author;
}
public void setId(Long id) {
this.id = id;
}
public void setContent(String content) {
this.content = content;
}
public void setAuthor(User author) {
this.author = author;
}
@Override
public boolean equals(Object o) {
if (this == o) {
@ -40,4 +65,8 @@ public class Post {
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "Post(id=" + this.getId() + ", content=" + this.getContent() + ", author=" + this.getAuthor() + ")";
}
}

View File

@ -9,9 +9,7 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.Objects;
import java.util.Set;
import lombok.Data;
@Data
@Entity(name = "simple_user")
@Table(name = "simple_user")
public class User {
@ -25,6 +23,41 @@ public class User {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "author", fetch = FetchType.EAGER)
protected Set<Post> posts;
public User() {
}
public Long getId() {
return this.id;
}
public String getUsername() {
return this.username;
}
public String getEmail() {
return this.email;
}
public Set<Post> getPosts() {
return this.posts;
}
public void setId(Long id) {
this.id = id;
}
public void setUsername(String username) {
this.username = username;
}
public void setEmail(String email) {
this.email = email;
}
public void setPosts(Set<Post> posts) {
this.posts = posts;
}
@Override
public boolean equals(Object o) {
if (this == o) {
@ -43,4 +76,9 @@ public class User {
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "User(id=" + this.getId() + ", username=" + this.getUsername() + ", email=" + this.getEmail() + ", posts=" + this.getPosts()
+ ")";
}
}

View File

@ -6,10 +6,8 @@ import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import java.util.Objects;
import lombok.Data;
@Entity
@Data
public class Post {
@Id
@ -22,6 +20,33 @@ public class Post {
@ManyToOne
private User author;
public Post() {
}
public Long getId() {
return this.id;
}
public String getContent() {
return this.content;
}
public User getAuthor() {
return this.author;
}
public void setId(Long id) {
this.id = id;
}
public void setContent(String content) {
this.content = content;
}
public void setAuthor(User author) {
this.author = author;
}
@Override
public boolean equals(Object o) {
if (this == o) {
@ -40,4 +65,8 @@ public class Post {
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "Post(id=" + this.getId() + ", content=" + this.getContent() + ", author=" + this.getAuthor() + ")";
}
}

View File

@ -7,10 +7,9 @@ import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.Objects;
import java.util.Set;
import lombok.Data;
@Data
@Entity(name = "simple_user")
@Table(name = "simple_user")
public class User {
@ -24,4 +23,63 @@ public class User {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "author", fetch = FetchType.EAGER)
protected Set<Post> posts;
public User() {
}
public Long getId() {
return this.id;
}
public String getUsername() {
return this.username;
}
public String getEmail() {
return this.email;
}
public Set<Post> getPosts() {
return this.posts;
}
public void setId(Long id) {
this.id = id;
}
public void setUsername(String username) {
this.username = username;
}
public void setEmail(String email) {
this.email = email;
}
public void setPosts(Set<Post> posts) {
this.posts = posts;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
User user = (User) o;
return Objects.equals(id, user.id);
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "User(id=" + this.getId() + ", username=" + this.getUsername() + ", email=" + this.getEmail() + ", posts=" + this.getPosts()
+ ")";
}
}

View File

@ -5,9 +5,8 @@ import jakarta.persistence.Id;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.Table;
import java.util.List;
import lombok.Data;
import java.util.Objects;
@Data
@Entity(name = "interest_group")
@Table(name = "interest_group")
public class Group {
@ -19,4 +18,54 @@ public class Group {
@ManyToMany
private List<User> members;
public Group() {
}
public Long getId() {
return this.id;
}
public String getName() {
return this.name;
}
public List<User> getMembers() {
return this.members;
}
public void setId(Long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setMembers(List<User> members) {
this.members = members;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Group group = (Group) o;
return Objects.equals(id, group.id);
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "Group(id=" + this.getId() + ", name=" + this.getName() + ", members=" + this.getMembers() + ")";
}
}

View File

@ -25,6 +25,7 @@ public class GroupService {
public List<Group> findAll() {
return groupRepository.findAll();
}
public int countNumberOfRequestsWithFunction(ToIntFunction<List<Group>> function) {
return function.applyAsInt(groupRepository.findAll());
}

View File

@ -5,10 +5,9 @@ import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import lombok.Data;
import java.util.Objects;
@Entity
@Data
public class Post {
@Id
@ -20,4 +19,54 @@ public class Post {
@JsonBackReference
@ManyToOne
private User author;
public Post() {
}
public Long getId() {
return this.id;
}
public String getContent() {
return this.content;
}
public User getAuthor() {
return this.author;
}
public void setId(Long id) {
this.id = id;
}
public void setContent(String content) {
this.content = content;
}
public void setAuthor(User author) {
this.author = author;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Post post = (Post) o;
return Objects.equals(id, post.id);
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public String toString() {
return "Post(id=" + this.getId() + ", content=" + this.getContent() + ", author=" + this.getAuthor() + ")";
}
}

View File

@ -8,9 +8,7 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.List;
import java.util.Objects;
import lombok.Data;
@Data
@Entity(name = "simple_user")
@Table(name = "simple_user")
public class User {
@ -24,6 +22,9 @@ public class User {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "author")
protected List<Post> posts;
public User() {
}
@Override
public boolean equals(Object o) {
if (this == o) {
@ -42,4 +43,41 @@ public class User {
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
public Long getId() {
return this.id;
}
public String getUsername() {
return this.username;
}
public String getEmail() {
return this.email;
}
public List<Post> getPosts() {
return this.posts;
}
public void setId(Long id) {
this.id = id;
}
public void setUsername(String username) {
this.username = username;
}
public void setEmail(String email) {
this.email = email;
}
public void setPosts(List<Post> posts) {
this.posts = posts;
}
public String toString() {
return "User(id=" + this.getId() + ", username=" + this.getUsername() + ", email=" + this.getEmail() + ", posts=" + this.getPosts()
+ ")";
}
}

View File

@ -5,10 +5,9 @@ import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne;
import lombok.Data;
import java.util.Objects;
@Entity
@Data
public class Post {
@Id
@ -20,4 +19,47 @@ public class Post {
@JsonBackReference
@ManyToOne
private User author;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public User getAuthor() {
return author;
}
public void setAuthor(User author) {
this.author = author;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Post post = (Post) o;
return Objects.equals(id, post.id);
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
}

View File

@ -7,9 +7,8 @@ import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.util.List;
import lombok.Data;
import java.util.Objects;
@Data
@Entity(name = "simple_user")
@Table(name = "simple_user")
public class User {
@ -21,5 +20,56 @@ public class User {
@JsonManagedReference
@OneToMany(cascade = CascadeType.ALL, mappedBy = "author")
protected List<Post> posts;
private List<Post> posts;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public List<Post> getPosts() {
return posts;
}
public void setPosts(List<Post> posts) {
this.posts = posts;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
User user = (User) o;
return Objects.equals(id, user.id);
}
@Override
public int hashCode() {
return id != null ? id.hashCode() : 0;
}
}

View File

@ -58,16 +58,16 @@ abstract public class BaseNPlusOneIntegrationTest<T> extends ParametrizationAwar
@Test
void givenCorrectConfigurationWhenStartContextThenRepositoryIsPresent() {
assertThat(getService()).isNotNull();
assertThat(getUserService()).isNotNull();
}
@Test
void givenCorrectDatabaseWhenStartThenDatabaseIsNotEmpty() {
List<?> result = getService().findAll();
List<?> result = getUserService().findAll();
assertThat(result).isNotEmpty();
}
protected Service<T> getService() {
protected Service<T> getUserService() {
Class<T> parametrization = getParametrizationClass().get(0);
return (Service<T>) serviceMap.get(parametrization);
}

View File

@ -31,14 +31,14 @@ class NPlusOneLazyModerateDomainIntegrationTest extends BaseNPlusOneIntegrationT
@Test
void givenLazyListBasedUser_whenFetchingAllUsers_thenIssueOneRequest() {
getService().findAll();
getUserService().findAll();
assertSelectCount(1);
}
@ParameterizedTest
@ValueSource(longs = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
void givenLazyListBasedUser_whenFetchingOneUser_thenIssueOneRequest(Long id) {
getService().getUserById(id);
getUserService().getUserById(id);
assertSelectCount(1);
}

View File

@ -22,13 +22,13 @@ class NPlusOneLazySimpleDomainIntegrationTest extends BaseNPlusOneIntegrationTes
@Test
void givenLazyListBasedUser_WhenFetchingAllUsers_ThenIssueOneRequests() {
getService().findAll();
getUserService().findAll();
assertSelectCount(1);
}
@Test
void givenLazyListBasedUser_WhenFetchingAllUsersCheckingPosts_ThenIssueNPlusOneRequests() {
int numberOfRequests = getService().countNumberOfRequestsWithFunction(users -> {
int numberOfRequests = getUserService().countNumberOfRequestsWithFunction(users -> {
List<List<Post>> usersWithPosts
= users.stream()
.map(User::getPosts)
@ -42,7 +42,7 @@ class NPlusOneLazySimpleDomainIntegrationTest extends BaseNPlusOneIntegrationTes
@ParameterizedTest
@ValueSource(longs = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
void givenLazyListBasedUser_WhenFetchingOneUser_ThenIssueTwoRequest(Long id) {
getService().getUserByIdWithPredicate(id, user -> !user.getPosts().isEmpty());
getUserService().getUserByIdWithPredicate(id, user -> !user.getPosts().isEmpty());
assertSelectCount(2);
}

View File

@ -37,7 +37,7 @@ class NPlusOneEagerFullDomainIntegrationTest extends BaseNPlusOneIntegrationTest
@ParameterizedTest
@MethodSource
void givenEagerListBasedUser_WhenFetchingAllUsers_ThenIssueNPlusOneRequests(ToIntFunction<List<User>> function) {
int numberOfRequests = getService().countNumberOfRequestsWithFunction(function);
int numberOfRequests = getUserService().countNumberOfRequestsWithFunction(function);
assertSelectCount(numberOfRequests);
}
@ -58,7 +58,7 @@ class NPlusOneEagerFullDomainIntegrationTest extends BaseNPlusOneIntegrationTest
@ParameterizedTest
@ValueSource(longs = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
void givenEagerListBasedUser_WhenFetchingOneUser_ThenUseDFS(Long id) {
int numberOfRequests = getService().getUserByIdWithFunction(id, this::countNumberOfRequests);
int numberOfRequests = getUserService().getUserByIdWithFunction(id, this::countNumberOfRequests);
assertSelectCount(numberOfRequests);
}

View File

@ -34,14 +34,14 @@ class NPlusOneEagerModerateDomainIntegrationTest extends BaseNPlusOneIntegration
@Test
void givenEagerListBasedUser_whenFetchingAllUsers_thenIssueNPlusOneRequests() {
List<User> users = getService().findAll();
List<User> users = getUserService().findAll();
assertSelectCount(users.size() + 1);
}
@ParameterizedTest
@ValueSource(longs = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
void givenEagerListBasedUser_whenFetchingOneUser_thenIssueOneRequest(Long id) {
getService().getUserById(id);
getUserService().getUserById(id);
assertSelectCount(1);
}

View File

@ -26,21 +26,21 @@ class NPlusOneEagerSimpleDomainIntegrationTest extends BaseNPlusOneIntegrationTe
@Test
void givenEagerListBasedUser_WhenFetchingAllUsers_ThenIssueNPlusOneRequests() {
List<User> users = getService().findAll();
List<User> users = getUserService().findAll();
assertSelectCount(users.size() + 1);
}
@ParameterizedTest
@ValueSource(longs = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
void givenEagerListBasedUser_WhenFetchingOneUser_ThenIssueOneRequest(Long id) {
getService().getUserById(id);
getUserService().getUserById(id);
assertSelectCount(1);
}
@ParameterizedTest
@ValueSource(longs = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
void givenEagerListBasedUser_whenDeletePost_ThenIssueSingleUpdate(Long id) {
Optional<User> optionalUser = getService().getUserById(id);
Optional<User> optionalUser = getUserService().getUserById(id);
assertSelectCount(1);
optionalUser.ifPresent(user -> {
List<Post> posts = user.getPosts();
@ -48,10 +48,10 @@ class NPlusOneEagerSimpleDomainIntegrationTest extends BaseNPlusOneIntegrationTe
reset();
if (!posts.isEmpty()) {
posts.get(0).setAuthor(null);
getService().save(user);
getUserService().save(user);
assertSelectCount(1);
assertUpdateCount(1);
getService().getUserById(id).ifPresent(updatedUser -> {
getUserService().getUserById(id).ifPresent(updatedUser -> {
assertThat(updatedUser.getPosts()).hasSize(originalNumberOfPosts - 1);
});
}

View File

@ -33,7 +33,7 @@ class NPlusOneEagerFullDomainJoinIntegrationTest extends BaseNPlusOneIntegration
@Test
void givenEagerSetBasedUser_WhenFetchingAllUsers_ThenIssueNPlusOneRequests() {
List<User> users = getService().findAll();
List<User> users = getUserService().findAll();
assertSelectCount(users.size() + 1);
}
@ -43,7 +43,7 @@ class NPlusOneEagerFullDomainJoinIntegrationTest extends BaseNPlusOneIntegration
HashMap<String, Set<Long>> visitedMap = new HashMap<>();
visitedMap.put(POSTS, new HashSet<>());
visitedMap.put(USERS, new HashSet<>());
int numberOfRequests = getService()
int numberOfRequests = getUserService()
.getUserByIdWithFunction(id, user -> {
int result = 1;
visitedMap.get(USERS).add(user.getId());

View File

@ -33,14 +33,14 @@ class NPlusOneEagerModerateDomainIntegrationTest extends BaseNPlusOneIntegration
@Test
void givenEagerSetBasedUser_whenFetchingAllUsers_thenIssueNPlusOneRequests() {
List<User> users = getService().findAll();
List<User> users = getUserService().findAll();
assertSelectCount(users.size() + 1);
}
@ParameterizedTest
@ValueSource(longs = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
void givenEagerSetBasedUser_whenFetchingOneUser_thenIssueOneRequest(Long id) {
getService().getUserById(id);
getUserService().getUserById(id);
assertSelectCount(1);
}

View File

@ -27,21 +27,21 @@ class NPlusOneEagerSimpleDomainIntegrationTest extends BaseNPlusOneIntegrationTe
@Test
void givenEagerSetBasedUser_WhenFetchingAllUsers_ThenIssueNPlusOneRequests() {
List<User> users = getService().findAll();
List<User> users = getUserService().findAll();
assertSelectCount(users.size() + 1);
}
@ParameterizedTest
@ValueSource(longs = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
void givenEagerSetBasedUser_WhenFetchingOneUser_ThenIssueOneRequest(Long id) {
getService().getUserById(id);
getUserService().getUserById(id);
assertSelectCount(1);
}
@ParameterizedTest
@ValueSource(longs = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
void givenEagerListBasedUser_whenDeletePost_ThenIssueSingleUpdate(Long id) {
Optional<User> optionalUser = getService().getUserById(id);
Optional<User> optionalUser = getUserService().getUserById(id);
assertSelectCount(1);
optionalUser.ifPresent(user -> {
Set<Post> posts = user.getPosts();
@ -49,10 +49,10 @@ class NPlusOneEagerSimpleDomainIntegrationTest extends BaseNPlusOneIntegrationTe
reset();
if (!posts.isEmpty()) {
posts.iterator().next().setAuthor(null);
getService().save(user);
getUserService().save(user);
assertSelectCount(1);
assertUpdateCount(1);
getService().getUserById(id).ifPresent(updatedUser -> {
getUserService().getUserById(id).ifPresent(updatedUser -> {
assertThat(updatedUser.getPosts()).hasSize(originalNumberOfPosts - 1);
});
}