task/3382: Harmonisera tabellnamn #6

Merged
ansv7779 merged 104 commits from task/3382 into develop 2024-11-12 13:33:44 +01:00
6 changed files with 244 additions and 64 deletions
Showing only changes of commit 9e30f1aa57 - Show all commits

View File

@ -1,14 +1,21 @@
package se.su.dsv.scipro.forum.dataobjects; package se.su.dsv.scipro.forum.dataobjects;
import jakarta.persistence.Basic;
import jakarta.persistence.Column;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import se.su.dsv.scipro.system.User; import se.su.dsv.scipro.system.User;
import jakarta.persistence.*;
import java.io.Serializable; import java.io.Serializable;
@Entity @Entity
@Table(name = "forum_post_read") @Table(name = "forum_post_read_state")
public class ForumPostReadState implements Serializable { public class ForumPostReadState implements Serializable {
// ----------------------------------------------------------------------------------
// Basic and embedded JPA-mappings
// ----------------------------------------------------------------------------------
@EmbeddedId @EmbeddedId
private ForumPostReadStateId id; private ForumPostReadStateId id;
@ -16,6 +23,9 @@ public class ForumPostReadState implements Serializable {
@Column(name = "`read`", nullable = false) @Column(name = "`read`", nullable = false)
private boolean read = false; private boolean read = false;
// ----------------------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------------------
public ForumPostReadState() { public ForumPostReadState() {
} }
@ -23,6 +33,9 @@ public class ForumPostReadState implements Serializable {
id = new ForumPostReadStateId(user, post); id = new ForumPostReadStateId(user, post);
} }
// ----------------------------------------------------------------------------------
// Properties (Getters and Setters)
// ----------------------------------------------------------------------------------
public ForumPostReadStateId getId() { public ForumPostReadStateId getId() {
return id; return id;
} }
@ -39,4 +52,3 @@ public class ForumPostReadState implements Serializable {
this.read = read; this.read = read;
} }
} }

View File

@ -11,11 +11,11 @@ import java.util.Objects;
@Embeddable @Embeddable
public class ForumPostReadStateId implements Serializable { public class ForumPostReadStateId implements Serializable {
@ManyToOne @ManyToOne
@JoinColumn(name = "user", nullable = false) @JoinColumn(name = "user_id", nullable = false)
private User user; private User user;
@ManyToOne @ManyToOne
@JoinColumn(name = "post", nullable = false) @JoinColumn(name = "forum_post_id", nullable = false)
private ForumPost post; private ForumPost post;
public ForumPostReadStateId() { public ForumPostReadStateId() {

View File

@ -1,49 +1,70 @@
package se.su.dsv.scipro.forum.dataobjects; package se.su.dsv.scipro.forum.dataobjects;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
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.Table;
import se.su.dsv.scipro.group.Group; import se.su.dsv.scipro.group.Group;
import jakarta.persistence.*;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
@Entity @Entity
@Table(name = "group_thread") @Table(name = "project_group_thread")
public class GroupThread implements Serializable { public class GroupThread implements Serializable {
// ----------------------------------------------------------------------------------
// Basic JPA-mappings
// ----------------------------------------------------------------------------------
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; private Long id;
// ----------------------------------------------------------------------------------
// JPA-mappings of foreign keys in this table (project_group_thread) referencing other
// tables.
// ----------------------------------------------------------------------------------
@ManyToOne @ManyToOne
@JoinColumn(name = "group_id", nullable = false) @JoinColumn(name = "project_group_id", referencedColumnName = "id", nullable = false)
private Group group; private Group group;
@OneToOne(cascade = CascadeType.ALL, optional = false) @OneToOne(cascade = CascadeType.ALL, optional = false)
@JoinColumn(name = "thread_id") @JoinColumn(name = "thread_id", referencedColumnName = "id")
private ForumThread forumThread; private ForumThread forumThread;
// ----------------------------------------------------------------------------------
// Properties (Getters and Setters)
// ----------------------------------------------------------------------------------
public Long getId() { return id; } public Long getId() { return id; }
public Group getGroup() {
return group;
}
public ForumThread getForumThread() {
return forumThread;
}
public void setId(Long id) { public void setId(Long id) {
this.id = id; this.id = id;
} }
public Group getGroup() {
return group;
}
public void setGroup(Group group) { public void setGroup(Group group) {
this.group = group; this.group = group;
} }
public ForumThread getForumThread() {
return forumThread;
}
public void setForumThread(ForumThread forumThread) { public void setForumThread(ForumThread forumThread) {
this.forumThread = forumThread; this.forumThread = forumThread;
} }
// ----------------------------------------------------------------------------------
// Methods Common To All Objects
// ----------------------------------------------------------------------------------
@Override @Override
public boolean equals(final Object o) { public boolean equals(final Object o) {
if (o == this) return true; if (o == this) return true;
@ -55,10 +76,6 @@ public class GroupThread implements Serializable {
&& Objects.equals(this.getForumThread(), other.getForumThread()); && Objects.equals(this.getForumThread(), other.getForumThread());
} }
protected boolean canEqual(final Object other) {
return other instanceof GroupThread;
}
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(this.getId(), this.getGroup(), this.getForumThread()); return Objects.hash(this.getId(), this.getGroup(), this.getForumThread());
@ -66,6 +83,14 @@ public class GroupThread implements Serializable {
@Override @Override
public String toString() { public String toString() {
return "GroupThread(id=" + this.getId() + ", group=" + this.getGroup() + ", forumThread=" + this.getForumThread() + ")"; return "GroupThread(id=" + this.getId() + ", group=" + this.getGroup() + ", forumThread=" +
this.getForumThread() + ")";
}
// ----------------------------------------------------------------------------------
// Other methods
// ----------------------------------------------------------------------------------
protected boolean canEqual(final Object other) {
return other instanceof GroupThread;
} }
} }

View File

@ -1,50 +1,70 @@
package se.su.dsv.scipro.forum.dataobjects; package se.su.dsv.scipro.forum.dataobjects;
import jakarta.persistence.Entity;
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.Table;
import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.project.Project;
import jakarta.persistence.*;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
@Entity @Entity
@Table(name = "project_thread") @Table(name = "project_thread")
public class ProjectThread implements Serializable { public class ProjectThread implements Serializable {
// ----------------------------------------------------------------------------------
// Basic JPA-mappings
// ----------------------------------------------------------------------------------
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; private Long id;
@OneToOne(optional = false) // ----------------------------------------------------------------------------------
@JoinColumn(name = "thread_id") // JPA-mappings of foreign keys in this table (project_thread) referencing other
private ForumThread forumThread; // tables.
// ----------------------------------------------------------------------------------
@ManyToOne(optional = false) @ManyToOne(optional = false)
@JoinColumn(name = "project_id") @JoinColumn(name = "project_id", referencedColumnName = "id")
private Project project; private Project project;
@OneToOne(optional = false)
@JoinColumn(name = "thread_id", referencedColumnName = "id")
private ForumThread forumThread;
// ----------------------------------------------------------------------------------
// Properties (Getters and Setters)
// ----------------------------------------------------------------------------------
public Long getId() { public Long getId() {
return id; return id;
} }
public Project getProject() {
return project;
}
public ForumThread getForumThread() {
return forumThread;
}
public void setId(Long id) { public void setId(Long id) {
this.id = id; this.id = id;
} }
public void setForumThread(ForumThread forumThread) { public Project getProject() {
this.forumThread = forumThread; return project;
} }
public void setProject(Project project) { public void setProject(Project project) {
this.project = project; this.project = project;
} }
public ForumThread getForumThread() {
return forumThread;
}
public void setForumThread(ForumThread forumThread) {
this.forumThread = forumThread;
}
// ----------------------------------------------------------------------------------
// Methods Common To All Objects
// ----------------------------------------------------------------------------------
@Override @Override
public boolean equals(final Object o) { public boolean equals(final Object o) {
if (o == this) return true; if (o == this) return true;
@ -56,10 +76,6 @@ public class ProjectThread implements Serializable {
&& Objects.equals(this.getProject(), other.getProject()); && Objects.equals(this.getProject(), other.getProject());
} }
protected boolean canEqual(final Object other) {
return other instanceof ProjectThread;
}
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(this.getId(), this.getForumThread(), this.getProject()); return Objects.hash(this.getId(), this.getForumThread(), this.getProject());
@ -67,6 +83,14 @@ public class ProjectThread implements Serializable {
@Override @Override
public String toString() { public String toString() {
return "ProjectThread(id=" + this.getId() + ", forumThread=" + this.getForumThread() + ", project=" + this.getProject() + ")"; return "ProjectThread(id=" + this.getId() + ", forumThread=" + this.getForumThread() +
", project=" + this.getProject() + ")";
}
// ----------------------------------------------------------------------------------
// Other methods
// ----------------------------------------------------------------------------------
protected boolean canEqual(final Object other) {
return other instanceof ProjectThread;
} }
} }

View File

@ -1,50 +1,69 @@
package se.su.dsv.scipro.forum.dataobjects; package se.su.dsv.scipro.forum.dataobjects;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import se.su.dsv.scipro.project.Project; import se.su.dsv.scipro.project.Project;
import jakarta.persistence.*;
import java.util.Objects; import java.util.Objects;
@Entity @Entity
@Table(name = "reviewer_thread") @Table(name = "reviewer_thread")
public class ReviewerThread { public class ReviewerThread {
// ----------------------------------------------------------------------------------
// Basic JPA-mapping
// ----------------------------------------------------------------------------------
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; private Long id;
@OneToOne(optional = false) // ----------------------------------------------------------------------------------
@JoinColumn(name = "thread_id") // JPA-mappings of foreign keys in this table (mail_event) referencing other
private ForumThread forumThread; // tables.
// ----------------------------------------------------------------------------------
@OneToOne @OneToOne
@JoinColumn(name = "project_id", unique = true) @JoinColumn(name = "project_id", referencedColumnName = "id", unique = true)
private Project project; private Project project;
@OneToOne(optional = false)
@JoinColumn(name = "thread_id", referencedColumnName = "id")
private ForumThread forumThread;
// ----------------------------------------------------------------------------------
// Properties (Getters and Setters)
// ----------------------------------------------------------------------------------
public Long getId() { public Long getId() {
return this.id; return this.id;
} }
public ForumThread getForumThread() {
return this.forumThread;
}
public Project getProject() {
return this.project;
}
public void setId(Long id) { public void setId(Long id) {
this.id = id; this.id = id;
} }
public void setForumThread(ForumThread forumThread) { public Project getProject() {
this.forumThread = forumThread; return this.project;
} }
public void setProject(Project project) { public void setProject(Project project) {
this.project = project; this.project = project;
} }
public ForumThread getForumThread() {
return this.forumThread;
}
public void setForumThread(ForumThread forumThread) {
this.forumThread = forumThread;
}
// ----------------------------------------------------------------------------------
// Methods Common To All Objects
// ----------------------------------------------------------------------------------
@Override @Override
public boolean equals(final Object o) { public boolean equals(final Object o) {
if (o == this) return true; if (o == this) return true;
@ -56,10 +75,6 @@ public class ReviewerThread {
&& Objects.equals(this.getProject(), other.getProject()); && Objects.equals(this.getProject(), other.getProject());
} }
protected boolean canEqual(final Object other) {
return other instanceof ReviewerThread;
}
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(this.getId(), this.getForumThread(), this.getProject()); return Objects.hash(this.getId(), this.getForumThread(), this.getProject());
@ -67,6 +82,14 @@ public class ReviewerThread {
@Override @Override
public String toString() { public String toString() {
return "ReviewerThread(id=" + this.getId() + ", forumThread=" + this.getForumThread() + ", project=" + this.getProject() + ")"; return "ReviewerThread(id=" + this.getId() + ", forumThread=" + this.getForumThread() +
", project=" + this.getProject() + ")";
}
// ----------------------------------------------------------------------------------
// Other methods
// ----------------------------------------------------------------------------------
protected boolean canEqual(final Object other) {
return other instanceof ReviewerThread;
} }
} }

View File

@ -2973,6 +2973,102 @@ alter table `forum_post_file_reference`
foreign key (file_reference_id) references file_reference (id) foreign key (file_reference_id) references file_reference (id)
on delete cascade on update cascade; on delete cascade on update cascade;
/*
* Step 23: forum_post_read, project_thread, reviewer_thread and group_thread
*/
-- table: forum_post_read
alter table `forum_post_read` drop foreign key `FK8A5DFC60DD74550D`;
alter table `forum_post_read` drop foreign key `FK8A5DFC60924F477B`;
alter table `forum_post_read` drop key `FK8A5DFC60DD74550D`;
alter table `forum_post_read` drop key `FK8A5DFC60924F477B`;
alter table `forum_post_read` drop primary key;
rename table `forum_post_read` to `forum_post_read_state`;
alter table `forum_post_read_state` change `read` `read` tinyint(1) not null after `post`;
alter table `forum_post_read_state` change `user` `user_id` bigint(20) not null after `post`;
alter table `forum_post_read_state` change `post` `forum_post_id` bigint(20) not null;
alter table `forum_post_read_state` add primary key (forum_post_id, user_id);
alter table `forum_post_read_state`
add constraint fk_forum_post_read_state_forum_post_id
foreign key (forum_post_id) references forum_post (id)
on delete cascade on update cascade;
alter table `forum_post_read_state`
add constraint fk_forum_post_read_state_user_id
foreign key (user_id) references user (id)
on delete cascade on update cascade;
-- table: project_thread
alter table `project_thread` drop foreign key `FK_project_thread_thread`;
alter table `project_thread` drop foreign key `FK_project_thread_project`;
alter table `project_thread` drop key `FK_project_thread_thread`;
alter table `project_thread` drop key `FK_project_thread_project`;
alter table `project_thread` change `project_id` `project_id` bigint(20) not null after `id`;
alter table `project_thread`
add constraint fk_project_thread_project_id
foreign key (project_id) references project (id)
on delete cascade on update cascade;
alter table `project_thread`
add constraint fk_project_thread_thread_id
foreign key (thread_id) references thread (id)
on delete cascade on update cascade;
-- table: reviewer_thread
alter table `reviewer_thread` drop foreign key `FK_reviewer_thread_thread`;
alter table `reviewer_thread` drop foreign key `FK_reviewer_thread_group`;
alter table `reviewer_thread` drop key `FK_reviewer_thread_thread`;
alter table `reviewer_thread` drop key `project_id`;
alter table `reviewer_thread` change `thread_id` `thread_id` bigint(20) not null after `project_id`;
alter table `reviewer_thread` add constraint uk_reviewer_thread_project_id unique(project_id, thread_id);
alter table `reviewer_thread`
add constraint fk_reviewer_thread_project_id
foreign key (project_id) references project (id)
on delete cascade on update cascade;
alter table `reviewer_thread`
add constraint fk_reviewer_thread_thread_id
foreign key (thread_id) references thread (id)
on delete cascade on update cascade;
-- table: group_thread
alter table `group_thread` drop foreign key `FK_project_group_thread_thread`;
alter table `group_thread` drop foreign key `FK_project_group_thread_group`;
alter table `group_thread` drop key `FK_project_group_thread_thread`;
alter table `group_thread` drop key `project_group`;
rename table `group_thread` to `project_group_thread`;
alter table `project_group_thread` change `group_id` `project_group_id` bigint(20) not null after `id`;
alter table `project_group_thread`
add constraint fk_project_group_thread_project_group_id
foreign key (project_group_id) references project_group (id)
on delete cascade on update cascade;
alter table `project_group_thread`
add constraint fk_project_group_thread_thread_id
foreign key (thread_id) references thread (id)
on delete cascade on update cascade;
/* Useful SQL /* Useful SQL