task/3382: Harmonisera tabellnamn #6
@ -1,26 +1,44 @@
|
||||
package se.su.dsv.scipro.forum.notifications;
|
||||
|
||||
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 jakarta.persistence.Table;
|
||||
import se.su.dsv.scipro.forum.dataobjects.ForumPost;
|
||||
import se.su.dsv.scipro.notifications.dataobject.NotificationEvent;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Table(name = "forum_notification")
|
||||
class ForumNotification {
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Embedded JPA-mapping
|
||||
// ----------------------------------------------------------------------------------
|
||||
@EmbeddedId
|
||||
private Id id = new Id();
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// JPA-mappings of foreign keys in this table (forum_notification) referencing other
|
||||
// tables.
|
||||
// ----------------------------------------------------------------------------------
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "forum_post_id", referencedColumnName = "id")
|
||||
@MapsId("forumPostId")
|
||||
private ForumPost forumPost;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "notification_data_id")
|
||||
@MapsId("notificationEventId")
|
||||
private NotificationEvent notificationEvent;
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Constructors
|
||||
// ----------------------------------------------------------------------------------
|
||||
protected ForumNotification() { } // JPA
|
||||
|
||||
ForumNotification(final ForumPost forumPost, final NotificationEvent notificationEvent) {
|
||||
@ -28,6 +46,9 @@ class ForumNotification {
|
||||
this.notificationEvent = notificationEvent;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Properties (Getters)
|
||||
// ----------------------------------------------------------------------------------
|
||||
public ForumPost getForumPost() {
|
||||
return forumPost;
|
||||
}
|
||||
@ -36,6 +57,9 @@ class ForumNotification {
|
||||
return notificationEvent;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Methods Common To All Objects
|
||||
// ----------------------------------------------------------------------------------
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (o == this) return true;
|
||||
@ -47,10 +71,6 @@ class ForumNotification {
|
||||
&& Objects.equals(this.getNotificationEvent(), other.getNotificationEvent());
|
||||
}
|
||||
|
||||
protected boolean canEqual(final Object other) {
|
||||
return other instanceof ForumNotification;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.id, this.getForumPost(), this.getNotificationEvent());
|
||||
@ -58,9 +78,20 @@ class ForumNotification {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ForumNotification(id=" + this.id + ", forumPost=" + this.getForumPost() + ", notificationEvent=" + this.getNotificationEvent() + ")";
|
||||
return "ForumNotification(id=" + this.id + ", forumPost=" + this.getForumPost() +
|
||||
", notificationEvent=" + this.getNotificationEvent() + ")";
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Other method
|
||||
// ----------------------------------------------------------------------------------
|
||||
protected boolean canEqual(final Object other) {
|
||||
return other instanceof ForumNotification;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Nested type
|
||||
// ----------------------------------------------------------------------------------
|
||||
@Embeddable
|
||||
static class Id implements Serializable {
|
||||
private Long forumPostId;
|
||||
@ -103,7 +134,8 @@ class ForumNotification {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ForumNotification.Id(forumPostId=" + this.getForumPostId() + ", notificationEventId=" + this.getNotificationEventId() + ")";
|
||||
return "ForumNotification.Id(forumPostId=" + this.getForumPostId() + ", notificationEventId=" +
|
||||
this.getNotificationEventId() + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,41 +1,59 @@
|
||||
package se.su.dsv.scipro.notifications.dataobject;
|
||||
|
||||
import jakarta.persistence.Basic;
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
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.Table;
|
||||
import se.su.dsv.scipro.project.Project;
|
||||
import se.su.dsv.scipro.system.DomainObject;
|
||||
import se.su.dsv.scipro.system.User;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "notification")
|
||||
public class Notification extends DomainObject {
|
||||
|
||||
|
||||
public enum Type {
|
||||
PROJECT, IDEA, FINAL_SEMINAR, PEER, MILESTONE,
|
||||
GROUP, FORUM, CUSTOM
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Basic JPA-mappings
|
||||
// ----------------------------------------------------------------------------------
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Basic(optional = false)
|
||||
private boolean unread = true;
|
||||
|
||||
@Basic(optional = false)
|
||||
@Column(name = "mailed")
|
||||
private boolean mailed = false;
|
||||
|
||||
@Basic(optional = false)
|
||||
@Column(name = "unread")
|
||||
private boolean unread = true;
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// JPA-mappings of foreign keys in this table (notification) referencing other
|
||||
// tables.
|
||||
// ----------------------------------------------------------------------------------
|
||||
@ManyToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "notificationData_id")
|
||||
@JoinColumn(name = "notification_data_id", referencedColumnName = "id")
|
||||
private NotificationEvent notificationEvent;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "user_id", referencedColumnName = "id")
|
||||
private User user;
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Constructor
|
||||
// ----------------------------------------------------------------------------------
|
||||
public Notification() {
|
||||
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Properties (Getters and Setters)
|
||||
// ----------------------------------------------------------------------------------
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
@ -45,6 +63,14 @@ public class Notification extends DomainObject {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public boolean isMailed() {
|
||||
return mailed;
|
||||
}
|
||||
|
||||
public void setMailed(boolean mailed) {
|
||||
this.mailed = mailed;
|
||||
}
|
||||
|
||||
public boolean isUnread() {
|
||||
return unread;
|
||||
}
|
||||
@ -69,14 +95,9 @@ public class Notification extends DomainObject {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public boolean isMailed() {
|
||||
return mailed;
|
||||
}
|
||||
|
||||
public void setMailed(boolean mailed) {
|
||||
this.mailed = mailed;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Other methods
|
||||
// ----------------------------------------------------------------------------------
|
||||
public String getTitle() {
|
||||
return getNotificationEvent().getTitle();
|
||||
}
|
||||
@ -108,4 +129,12 @@ public class Notification extends DomainObject {
|
||||
public User getCausedBy() {
|
||||
return getNotificationEvent().getCausedBy();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Nested type
|
||||
// ----------------------------------------------------------------------------------
|
||||
public enum Type {
|
||||
PROJECT, IDEA, FINAL_SEMINAR, PEER, MILESTONE,
|
||||
GROUP, FORUM, CUSTOM
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +1,103 @@
|
||||
package se.su.dsv.scipro.notifications.dataobject;
|
||||
|
||||
import jakarta.persistence.Basic;
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.DiscriminatorColumn;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Inheritance;
|
||||
import jakarta.persistence.InheritanceType;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import se.su.dsv.scipro.project.Project;
|
||||
import se.su.dsv.scipro.system.DomainObject;
|
||||
import se.su.dsv.scipro.system.User;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.util.Collection;
|
||||
|
||||
@Entity
|
||||
@Table(name = "notification_data")
|
||||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||
@Table(name = "NotificationData")
|
||||
@DiscriminatorColumn(name = "subclass")
|
||||
public abstract class NotificationEvent extends DomainObject {
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Basic JPA-mappings
|
||||
// ----------------------------------------------------------------------------------
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
protected long id;
|
||||
|
||||
@Basic
|
||||
@Column(name = "type")
|
||||
@Enumerated(EnumType.STRING)
|
||||
protected Notification.Type type;
|
||||
|
||||
@OneToMany(mappedBy = "notificationEvent", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private Collection<Notification> notifications;
|
||||
|
||||
@Basic(optional = true)
|
||||
@Column(name = "source")
|
||||
private String source;
|
||||
|
||||
@Basic(optional = true)
|
||||
@Column(name = "additional_source")
|
||||
private String additionalSource;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// JPA-mappings of foreign keys in this table (notification_data) referencing other
|
||||
// tables.
|
||||
// ----------------------------------------------------------------------------------
|
||||
@ManyToOne(optional = true)
|
||||
@JoinColumn(name = "caused_by_user_id", referencedColumnName = "id")
|
||||
private User causedBy;
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// JPA-mappings of other tables referencing to this table "notification_data"
|
||||
// ----------------------------------------------------------------------------------
|
||||
@OneToMany(mappedBy = "notificationEvent", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private Collection<Notification> notifications;
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Constructors
|
||||
// ----------------------------------------------------------------------------------
|
||||
protected NotificationEvent() {
|
||||
|
||||
}
|
||||
|
||||
protected NotificationEvent(Notification.Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Properties (Getters and Setters)
|
||||
// ----------------------------------------------------------------------------------
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public abstract Enum getEvent();
|
||||
|
||||
public Notification.Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Notification.Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The title of the entity this event is about.
|
||||
*
|
||||
@ -50,30 +113,10 @@ public abstract class NotificationEvent extends DomainObject {
|
||||
|
||||
public abstract DomainObject getEntity();
|
||||
|
||||
protected NotificationEvent() {
|
||||
|
||||
}
|
||||
|
||||
protected NotificationEvent(Notification.Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Notification.Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Notification.Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Collection<Notification> getNotifications() {
|
||||
return notifications;
|
||||
|
@ -3069,6 +3069,138 @@ alter table `project_group_thread`
|
||||
foreign key (thread_id) references thread (id)
|
||||
on delete cascade on update cascade;
|
||||
|
||||
/*
|
||||
* Step 24: forum_notification, Notification, NotificationData
|
||||
*/
|
||||
|
||||
-- table: forum_notification,
|
||||
|
||||
alter table `forum_notification` drop foreign key `FK_forum_notification_notification_event`;
|
||||
alter table `forum_notification` drop foreign key `FK_forum_notification_forum_post`;
|
||||
|
||||
alter table `forum_notification` drop key `FK_forum_notification_notification_event`;
|
||||
|
||||
alter table `forum_notification` drop primary key;
|
||||
|
||||
alter table `forum_notification` change `forumPost_id` `forum_post_id` bigint(20) not null;
|
||||
alter table `forum_notification` change `notificationEvent_id` `notification_data_id` bigint(20) not null;
|
||||
|
||||
alter table `forum_notification` add primary key (forum_post_id, notification_data_id);
|
||||
|
||||
alter table `forum_notification`
|
||||
add constraint fk_forum_notification_forum_post_id
|
||||
foreign key (forum_post_id) references forum_post (id)
|
||||
on delete cascade on update cascade;
|
||||
|
||||
-- table: Notification
|
||||
|
||||
alter table `Notification` drop foreign key `FK_notification_user`;
|
||||
alter table `Notification` drop foreign key `FK2D45DD0B599425F6`;
|
||||
|
||||
alter table `Notification` drop key `FK2D45DD0B599425F6`;
|
||||
alter table `Notification` drop key `FK2D45DD0B895349BF`;
|
||||
|
||||
rename table `Notification` to `notification`;
|
||||
|
||||
alter table `notification` change `mailed` `mailed` bit(1) not null after `version`;
|
||||
alter table `notification` change `notificationData_id` `notification_data_id` bigint(20) default null;
|
||||
|
||||
alter table `notification`
|
||||
add constraint fk_notification_user_id
|
||||
foreign key (user_id) references user (id)
|
||||
on delete cascade on update cascade;
|
||||
|
||||
-- table: NotificationData
|
||||
|
||||
alter table `NotificationData` drop foreign key `FK_notification_data_user_caused_by`;
|
||||
alter table `NotificationData` drop foreign key `FK_notification_data_project`;
|
||||
alter table `NotificationData` drop foreign key `FK_notification_data_peer_review`;
|
||||
alter table `NotificationData` drop foreign key `FK_notification_data_milestone`;
|
||||
alter table `NotificationData` drop foreign key `FK_notification_data_group`;
|
||||
alter table `NotificationData` drop foreign key `FK2DCAC355FCDADF61`;
|
||||
alter table `NotificationData` drop foreign key `FK2DCAC3558D40D1B9`;
|
||||
alter table `NotificationData` drop foreign key `FK2DCAC3554D07E0A9`;
|
||||
|
||||
alter table `NotificationData` drop key `FK_notification_data_group`;
|
||||
alter table `NotificationData` drop key `FK_sqjaj3jb6t9lsw1l2p8ex8jnb`;
|
||||
alter table `NotificationData` drop key `FK2DCAC355FCDADF61`;
|
||||
alter table `NotificationData` drop key `FK2DCAC355B2E2AD78`;
|
||||
alter table `NotificationData` drop key `FK2DCAC3558D40D1B9`;
|
||||
alter table `NotificationData` drop key `FK2DCAC35542E9AC7B`;
|
||||
alter table `NotificationData` drop key `FK2DCAC355C1813915`;
|
||||
alter table `NotificationData` drop key `FK2DCAC3554D07E0A9`;
|
||||
|
||||
rename table `NotificationData` to `notification_data`;
|
||||
|
||||
alter table `notification_data` change `type` `type` varchar(255) default null after `event`;
|
||||
alter table `notification_data` change `source` `source` longtext default null after `type`;
|
||||
alter table `notification_data` change `additionalSource` `additional_source` longtext default null after `source`;
|
||||
alter table `notification_data` change `DTYPE` `subclass` varchar(31) not null after `additional_source`;
|
||||
|
||||
alter table `notification_data` change `seminar_id` `final_seminar_id` bigint(20) default null after `subclass`;
|
||||
alter table `notification_data` change `idea_id` `idea_id` bigint(20) default null after `final_seminar_id`;
|
||||
alter table `notification_data` change `mileStone_id` `milestone_id` bigint(20) default null after `idea_id`;
|
||||
alter table `notification_data` change `request_id` `peer_request_id` bigint(20) default null after `milestone_id`;
|
||||
alter table `notification_data` change `review_id` `peer_review_id` bigint(20) default null after `peer_request_id`;
|
||||
alter table `notification_data` change `project_id` `project_id` bigint(20) default null after `peer_review_id`;
|
||||
alter table `notification_data` change `group_id` `project_group_id` bigint(20) default null after `project_id`;
|
||||
alter table `notification_data` change `causedBy_id` `caused_by_user_id` bigint(20) default null after `project_group_id`;
|
||||
|
||||
alter table `notification_data`
|
||||
add constraint fk_notification_data_final_seminar_id
|
||||
foreign key (final_seminar_id) references final_seminar (id)
|
||||
on delete cascade on update cascade;
|
||||
|
||||
alter table `notification_data`
|
||||
add constraint fk_notification_data_idea_id
|
||||
foreign key (idea_id) references idea (id)
|
||||
on delete cascade on update cascade;
|
||||
|
||||
alter table `notification_data`
|
||||
add constraint fk_notification_data_milestone_id
|
||||
foreign key (milestone_id) references milestone (id)
|
||||
on delete cascade on update cascade;
|
||||
|
||||
alter table `notification_data`
|
||||
add constraint fk_notification_data_peer_request_id
|
||||
foreign key (peer_request_id) references peer_request (id)
|
||||
on delete set null on update cascade;
|
||||
|
||||
alter table `notification_data`
|
||||
add constraint fk_notification_data_peer_review_id
|
||||
foreign key (peer_review_id) references peer_review (id)
|
||||
on delete cascade on update cascade;
|
||||
|
||||
alter table `notification_data`
|
||||
add constraint fk_notification_data_project_id
|
||||
foreign key (project_id) references project (id)
|
||||
on delete cascade on update cascade;
|
||||
|
||||
alter table `notification_data`
|
||||
add constraint fk_notification_data_project_group_id
|
||||
foreign key (project_group_id) references project_group (id)
|
||||
on delete cascade on update cascade;
|
||||
|
||||
alter table `notification_data`
|
||||
add constraint fk_notification_data_caused_by_user_id
|
||||
foreign key (caused_by_user_id) references user (id)
|
||||
on delete set null on update cascade;
|
||||
|
||||
-- add foreign key from notification to notification_data
|
||||
|
||||
alter table `notification`
|
||||
add constraint fk_notification_notification_data_id
|
||||
foreign key (notification_data_id) references notification_data (id)
|
||||
on delete cascade on update cascade;
|
||||
|
||||
-- add foreign key from forum_notification to notification_data
|
||||
|
||||
alter table `forum_notification`
|
||||
add constraint fk_forum_notification_notification_data_id
|
||||
foreign key (notification_data_id) references notification_data (id)
|
||||
on delete cascade on update cascade;
|
||||
|
||||
-- todo: NotificationEvent, JPA-mapping
|
||||
|
||||
/* Useful SQL
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user