diff options
Diffstat (limited to 'src/main/java/com/juick/data/entities')
10 files changed, 65 insertions, 117 deletions
diff --git a/src/main/java/com/juick/data/entities/BaseMessagePropertyEntity.java b/src/main/java/com/juick/data/entities/BaseMessagePropertyEntity.java index 934cce923..90c26dbb3 100644 --- a/src/main/java/com/juick/data/entities/BaseMessagePropertyEntity.java +++ b/src/main/java/com/juick/data/entities/BaseMessagePropertyEntity.java @@ -21,7 +21,7 @@ import jakarta.persistence.*; @MappedSuperclass public class BaseMessagePropertyEntity { - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne @JoinColumn(name = "message_id") private MessageEntity message; public MessageEntity getMessage() { diff --git a/src/main/java/com/juick/data/entities/EmailEntity.java b/src/main/java/com/juick/data/entities/EmailEntity.java index 4e71adc5f..e13ca7723 100644 --- a/src/main/java/com/juick/data/entities/EmailEntity.java +++ b/src/main/java/com/juick/data/entities/EmailEntity.java @@ -24,7 +24,7 @@ import jakarta.persistence.*; public class EmailEntity extends BaseUserPropertyEntity { @Id @Column(name = "email") - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.IDENTITY) private String email; public String getEmail() { diff --git a/src/main/java/com/juick/data/entities/FacebookEntity.java b/src/main/java/com/juick/data/entities/FacebookEntity.java index 75bee8d80..744848d99 100644 --- a/src/main/java/com/juick/data/entities/FacebookEntity.java +++ b/src/main/java/com/juick/data/entities/FacebookEntity.java @@ -23,8 +23,8 @@ import jakarta.persistence.*; @Table(name = "facebook") public class FacebookEntity extends BaseUserPropertyEntity { @Id - @Column(name = "fb_id", columnDefinition = "bigint(20)") - @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "fb_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long facebookId; public Long getFacebookId() { diff --git a/src/main/java/com/juick/data/entities/MessageEntity.java b/src/main/java/com/juick/data/entities/MessageEntity.java index 416334d69..21896fb96 100644 --- a/src/main/java/com/juick/data/entities/MessageEntity.java +++ b/src/main/java/com/juick/data/entities/MessageEntity.java @@ -30,24 +30,24 @@ public class MessageEntity implements Serializable { @Column(name = "message_id") @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; - @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "message") + @ManyToMany + @JoinTable(name = "messages_tags", + joinColumns = @JoinColumn(name = "message_id"), + inverseJoinColumns = @JoinColumn(name = "tag_id") + ) private Set<TagEntity> tags = new HashSet<>(); - @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "message") - private Set<ReplyEntity> replies = new HashSet<>(); - @OneToOne(cascade = CascadeType.ALL) - @PrimaryKeyJoinColumn - private TextEntity textEntity; + @OneToMany(mappedBy = "message") + private Set<ReplyEntity> replies = new HashSet<>(); - @ManyToOne(cascade = CascadeType.ALL) + @ManyToOne(cascade = CascadeType.MERGE) private UserEntity user; @Column(name = "ts") private Instant ts; - public MessageEntity() { - this.textEntity = new TextEntity(); - } + @Column(name = "txt") + private String text; public Integer getId() { return id; @@ -74,11 +74,11 @@ public class MessageEntity implements Serializable { } public String getText() { - return textEntity.getText(); + return text; } public void setText(String text) { - this.textEntity.setText(text); + this.text = text; } public UserEntity getUser() { diff --git a/src/main/java/com/juick/data/entities/ReplyEntity.java b/src/main/java/com/juick/data/entities/ReplyEntity.java index e7f3d0537..bc0795cfa 100644 --- a/src/main/java/com/juick/data/entities/ReplyEntity.java +++ b/src/main/java/com/juick/data/entities/ReplyEntity.java @@ -24,11 +24,12 @@ import jakarta.persistence.*; public class ReplyEntity extends BaseMessagePropertyEntity { @Id @Column(name = "reply_id") - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long replyId; @Column(name = "txt") - private - String text; + private String text; + @ManyToOne(cascade = CascadeType.MERGE) + private UserEntity user; public String getText() { return text; @@ -45,4 +46,12 @@ public class ReplyEntity extends BaseMessagePropertyEntity { public void setReplyId(Long replyId) { this.replyId = replyId; } + + public UserEntity getUser() { + return user; + } + + public void setUser(UserEntity user) { + this.user = user; + } } diff --git a/src/main/java/com/juick/data/entities/TagEntity.java b/src/main/java/com/juick/data/entities/TagEntity.java index 6fbc69871..e5c5266d0 100644 --- a/src/main/java/com/juick/data/entities/TagEntity.java +++ b/src/main/java/com/juick/data/entities/TagEntity.java @@ -19,14 +19,42 @@ package com.juick.data.entities; import jakarta.persistence.*; +import java.util.Set; + @Entity -@Table(name = "messages_tags") -public class TagEntity extends BaseMessagePropertyEntity { +@Table(name = "tags") +public class TagEntity { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "tag_id") - @GeneratedValue(strategy = GenerationType.AUTO) private int id; - @OneToOne(cascade = CascadeType.ALL) - @PrimaryKeyJoinColumn - private TagNameEntity tagName; + @Column(name = "name") + private String name; + + @ManyToMany(mappedBy = "tags") + private Set<MessageEntity> messages; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Set<MessageEntity> getMessages() { + return messages; + } + + public void setMessages(Set<MessageEntity> messages) { + this.messages = messages; + } } diff --git a/src/main/java/com/juick/data/entities/TagNameEntity.java b/src/main/java/com/juick/data/entities/TagNameEntity.java deleted file mode 100644 index 98d3bbea7..000000000 --- a/src/main/java/com/juick/data/entities/TagNameEntity.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2008-2024, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick.data.entities; - -import jakarta.persistence.*; - -@Entity -@Table(name = "tags") -public class TagNameEntity { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "tag_id") - private int id; - @Column(name = "name") - private String name; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} diff --git a/src/main/java/com/juick/data/entities/TelegramEntity.java b/src/main/java/com/juick/data/entities/TelegramEntity.java index a592f6352..453b8c112 100644 --- a/src/main/java/com/juick/data/entities/TelegramEntity.java +++ b/src/main/java/com/juick/data/entities/TelegramEntity.java @@ -24,7 +24,7 @@ import jakarta.persistence.*; public class TelegramEntity extends BaseUserPropertyEntity { @Id @Column(name = "tg_id") - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long identifier; public Long getIdentifier() { diff --git a/src/main/java/com/juick/data/entities/TextEntity.java b/src/main/java/com/juick/data/entities/TextEntity.java deleted file mode 100644 index c96adb96a..000000000 --- a/src/main/java/com/juick/data/entities/TextEntity.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2008-2024, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -package com.juick.data.entities; - -import jakarta.persistence.*; -import java.io.Serializable; - -@Entity -@Table(name = "messages_txt") -public class TextEntity implements Serializable { - - @Id - @Column(name = "message_id") - @GeneratedValue(strategy = GenerationType.AUTO) - private int id; - - @Column(name = "txt") - private String text; - - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } -} diff --git a/src/main/java/com/juick/data/entities/VKEntity.java b/src/main/java/com/juick/data/entities/VKEntity.java index 04aa55eba..5388c855a 100644 --- a/src/main/java/com/juick/data/entities/VKEntity.java +++ b/src/main/java/com/juick/data/entities/VKEntity.java @@ -23,8 +23,8 @@ import jakarta.persistence.*; @Table(name = "vk") public class VKEntity extends BaseUserPropertyEntity { @Id - @Column(name = "vk_id", columnDefinition = "bigint(20)") - @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "vk_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long vkId; public Long getVkId() { |