From 8a0fbbd35c13054a947ea0d27ca117542bc452b9 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 18 May 2018 15:33:38 +0300 Subject: JPA WIP --- .../data/entities/BaseMessagePropertyEntity.java | 20 ++++ .../data/entities/BaseUserPropertyEntity.java | 20 ++++ .../juick/service/data/entities/EmailEntity.java | 20 ++++ .../service/data/entities/FacebookEntity.java | 20 ++++ .../juick/service/data/entities/LoginEntity.java | 19 ++++ .../juick/service/data/entities/MessageEntity.java | 81 +++++++++++++++ .../juick/service/data/entities/ReplyEntity.java | 31 ++++++ .../com/juick/service/data/entities/TagEntity.java | 15 +++ .../juick/service/data/entities/TagNameEntity.java | 30 ++++++ .../service/data/entities/TelegramEntity.java | 20 ++++ .../juick/service/data/entities/TextEntity.java | 42 ++++++++ .../juick/service/data/entities/UserEntity.java | 109 +++++++++++++++++++++ .../com/juick/service/data/entities/VKEntity.java | 20 ++++ 13 files changed, 447 insertions(+) create mode 100644 juick-server/src/main/java/com/juick/service/data/entities/BaseMessagePropertyEntity.java create mode 100644 juick-server/src/main/java/com/juick/service/data/entities/BaseUserPropertyEntity.java create mode 100644 juick-server/src/main/java/com/juick/service/data/entities/EmailEntity.java create mode 100644 juick-server/src/main/java/com/juick/service/data/entities/FacebookEntity.java create mode 100644 juick-server/src/main/java/com/juick/service/data/entities/LoginEntity.java create mode 100644 juick-server/src/main/java/com/juick/service/data/entities/MessageEntity.java create mode 100644 juick-server/src/main/java/com/juick/service/data/entities/ReplyEntity.java create mode 100644 juick-server/src/main/java/com/juick/service/data/entities/TagEntity.java create mode 100644 juick-server/src/main/java/com/juick/service/data/entities/TagNameEntity.java create mode 100644 juick-server/src/main/java/com/juick/service/data/entities/TelegramEntity.java create mode 100644 juick-server/src/main/java/com/juick/service/data/entities/TextEntity.java create mode 100644 juick-server/src/main/java/com/juick/service/data/entities/UserEntity.java create mode 100644 juick-server/src/main/java/com/juick/service/data/entities/VKEntity.java (limited to 'juick-server/src/main/java/com/juick/service/data/entities') diff --git a/juick-server/src/main/java/com/juick/service/data/entities/BaseMessagePropertyEntity.java b/juick-server/src/main/java/com/juick/service/data/entities/BaseMessagePropertyEntity.java new file mode 100644 index 00000000..d9407f84 --- /dev/null +++ b/juick-server/src/main/java/com/juick/service/data/entities/BaseMessagePropertyEntity.java @@ -0,0 +1,20 @@ +package com.juick.service.data.entities; + +import javax.persistence.FetchType; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.MappedSuperclass; + +@MappedSuperclass +public class BaseMessagePropertyEntity { + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "message_id") + private MessageEntity message; + public MessageEntity getMessage() { + return message; + } + + public void setMessage(MessageEntity message) { + this.message = message; + } +} diff --git a/juick-server/src/main/java/com/juick/service/data/entities/BaseUserPropertyEntity.java b/juick-server/src/main/java/com/juick/service/data/entities/BaseUserPropertyEntity.java new file mode 100644 index 00000000..a5b1909d --- /dev/null +++ b/juick-server/src/main/java/com/juick/service/data/entities/BaseUserPropertyEntity.java @@ -0,0 +1,20 @@ +package com.juick.service.data.entities; + +import javax.persistence.FetchType; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.MappedSuperclass; + +@MappedSuperclass +public class BaseUserPropertyEntity { + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private UserEntity user; + public UserEntity getUser() { + return user; + } + + public void setUser(UserEntity user) { + this.user = user; + } +} diff --git a/juick-server/src/main/java/com/juick/service/data/entities/EmailEntity.java b/juick-server/src/main/java/com/juick/service/data/entities/EmailEntity.java new file mode 100644 index 00000000..d65b5da6 --- /dev/null +++ b/juick-server/src/main/java/com/juick/service/data/entities/EmailEntity.java @@ -0,0 +1,20 @@ +package com.juick.service.data.entities; + +import javax.persistence.*; + +@Entity +@Table(name = "emails") +public class EmailEntity extends BaseUserPropertyEntity { + @Id + @Column(name = "email", columnDefinition = "char(64)") + @GeneratedValue(strategy = GenerationType.AUTO) + private String email; + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } +} diff --git a/juick-server/src/main/java/com/juick/service/data/entities/FacebookEntity.java b/juick-server/src/main/java/com/juick/service/data/entities/FacebookEntity.java new file mode 100644 index 00000000..587651d9 --- /dev/null +++ b/juick-server/src/main/java/com/juick/service/data/entities/FacebookEntity.java @@ -0,0 +1,20 @@ +package com.juick.service.data.entities; + +import javax.persistence.*; + +@Entity +@Table(name = "facebook") +public class FacebookEntity extends BaseUserPropertyEntity { + @Id + @Column(name = "fb_id", columnDefinition = "bigint(20)") + @GeneratedValue(strategy = GenerationType.AUTO) + private Long facebookId; + + public Long getFacebookId() { + return facebookId; + } + + public void setFacebookId(Long facebookId) { + this.facebookId = facebookId; + } +} diff --git a/juick-server/src/main/java/com/juick/service/data/entities/LoginEntity.java b/juick-server/src/main/java/com/juick/service/data/entities/LoginEntity.java new file mode 100644 index 00000000..6799073f --- /dev/null +++ b/juick-server/src/main/java/com/juick/service/data/entities/LoginEntity.java @@ -0,0 +1,19 @@ +package com.juick.service.data.entities; + +import javax.persistence.*; + +@Entity +@Table(name = "logins") +public class LoginEntity extends BaseUserPropertyEntity { + @Id + @Column(name = "hash", columnDefinition = "char(16)") + private String hash; + + public String getHash() { + return hash; + } + + public void setHash(String hash) { + this.hash = hash; + } +} diff --git a/juick-server/src/main/java/com/juick/service/data/entities/MessageEntity.java b/juick-server/src/main/java/com/juick/service/data/entities/MessageEntity.java new file mode 100644 index 00000000..fdbdbdc0 --- /dev/null +++ b/juick-server/src/main/java/com/juick/service/data/entities/MessageEntity.java @@ -0,0 +1,81 @@ +package com.juick.service.data.entities; + +import javax.persistence.*; +import java.io.Serializable; +import java.time.Instant; +import java.util.HashSet; +import java.util.Set; + +@Entity +@Table(name = "messages") +public class MessageEntity implements Serializable { + @Id + @Column(name = "message_id", columnDefinition = "int(10) unsigned auto_increment", nullable = false, unique = true) + @GeneratedValue(strategy = GenerationType.AUTO) + private Integer id; + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "message") + private Set tags = new HashSet<>(); + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "message") + private Set replies = new HashSet<>(); + + @OneToOne(cascade = CascadeType.ALL, mappedBy = "message") + private TextEntity textEntity; + + @ManyToOne(cascade = CascadeType.ALL) + private UserEntity user; + + @Column(name = "ts") + private Instant ts; + + public MessageEntity() { + this.textEntity = new TextEntity(this); + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Set getTags() { + return tags; + } + + public void setTags(Set tags) { + this.tags = tags; + } + + public Set getReplies() { + return replies; + } + + public void setReplies(Set replies) { + this.replies = replies; + } + + public String getText() { + return textEntity.getText(); + } + + public void setText(String text) { + this.textEntity.setText(text); + } + + public UserEntity getUser() { + return user; + } + + public void setUser(UserEntity user) { + this.user = user; + } + + public Instant getTimestamp() { + return ts; + } + + public void setTimestamp(Instant ts) { + this.ts = ts; + } +} diff --git a/juick-server/src/main/java/com/juick/service/data/entities/ReplyEntity.java b/juick-server/src/main/java/com/juick/service/data/entities/ReplyEntity.java new file mode 100644 index 00000000..65a38576 --- /dev/null +++ b/juick-server/src/main/java/com/juick/service/data/entities/ReplyEntity.java @@ -0,0 +1,31 @@ +package com.juick.service.data.entities; + +import javax.persistence.*; + +@Entity +@Table(name = "replies") +public class ReplyEntity extends BaseMessagePropertyEntity { + @Id + @Column(name = "reply_id", columnDefinition = "smallint") + @GeneratedValue(strategy = GenerationType.AUTO) + private Long replyId; + @Column(name = "txt", columnDefinition = "clob") + private + String text; + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public Long getReplyId() { + return replyId; + } + + public void setReplyId(Long replyId) { + this.replyId = replyId; + } +} diff --git a/juick-server/src/main/java/com/juick/service/data/entities/TagEntity.java b/juick-server/src/main/java/com/juick/service/data/entities/TagEntity.java new file mode 100644 index 00000000..22196562 --- /dev/null +++ b/juick-server/src/main/java/com/juick/service/data/entities/TagEntity.java @@ -0,0 +1,15 @@ +package com.juick.service.data.entities; + +import javax.persistence.*; + +@Entity +@Table(name = "messages_tags") +public class TagEntity extends BaseMessagePropertyEntity { + @Id + @Column(name = "tag_id", columnDefinition = "int(10)") + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + @OneToOne(cascade = CascadeType.ALL) + @PrimaryKeyJoinColumn + private TagNameEntity tagName; +} diff --git a/juick-server/src/main/java/com/juick/service/data/entities/TagNameEntity.java b/juick-server/src/main/java/com/juick/service/data/entities/TagNameEntity.java new file mode 100644 index 00000000..4540a45e --- /dev/null +++ b/juick-server/src/main/java/com/juick/service/data/entities/TagNameEntity.java @@ -0,0 +1,30 @@ +package com.juick.service.data.entities; + +import javax.persistence.*; + +@Entity +@Table(name = "tags") +public class TagNameEntity { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "tag_id") + private int id; + @Column(name = "name", columnDefinition = "varchar(70)") + 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/juick-server/src/main/java/com/juick/service/data/entities/TelegramEntity.java b/juick-server/src/main/java/com/juick/service/data/entities/TelegramEntity.java new file mode 100644 index 00000000..e851b00e --- /dev/null +++ b/juick-server/src/main/java/com/juick/service/data/entities/TelegramEntity.java @@ -0,0 +1,20 @@ +package com.juick.service.data.entities; + +import javax.persistence.*; + +@Entity +@Table(name = "telegram") +public class TelegramEntity extends BaseUserPropertyEntity { + @Id + @Column(name = "tg_id", columnDefinition = "bigint(20)") + @GeneratedValue(strategy = GenerationType.AUTO) + private Long identifier; + + public Long getIdentifier() { + return identifier; + } + + public void setIdentifier(Long identifier) { + this.identifier = identifier; + } +} diff --git a/juick-server/src/main/java/com/juick/service/data/entities/TextEntity.java b/juick-server/src/main/java/com/juick/service/data/entities/TextEntity.java new file mode 100644 index 00000000..ba4b9146 --- /dev/null +++ b/juick-server/src/main/java/com/juick/service/data/entities/TextEntity.java @@ -0,0 +1,42 @@ +package com.juick.service.data.entities; + +import javax.persistence.*; +import java.io.Serializable; + +@Entity +@Table(name = "messages_txt") +public class TextEntity implements Serializable { + + @Id + @Column(name = "message_id", columnDefinition = "int(10)") + private Integer id; + + @Column(name = "txt", columnDefinition = "clob") + private String text; + + @OneToOne(fetch = FetchType.LAZY) + @MapsId + @JoinColumn(name = "message_id", foreignKey = @ForeignKey(name = "message_id")) + private MessageEntity message; + + public TextEntity() { + super(); + } + + public TextEntity(MessageEntity message) { + this(); + this.message = message; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public MessageEntity getMessage() { + return message; + } +} diff --git a/juick-server/src/main/java/com/juick/service/data/entities/UserEntity.java b/juick-server/src/main/java/com/juick/service/data/entities/UserEntity.java new file mode 100644 index 00000000..50a72bdb --- /dev/null +++ b/juick-server/src/main/java/com/juick/service/data/entities/UserEntity.java @@ -0,0 +1,109 @@ +package com.juick.service.data.entities; + +import javax.persistence.*; +import java.util.HashSet; +import java.util.Set; + +@Entity +@Table(name = "users") +public class UserEntity { + @Id + @Column(name = "id", columnDefinition = "int(10) unsigned", nullable = false, unique = true) + @GeneratedValue(strategy = GenerationType.AUTO) + private Integer id; + + @Column(name = "nick", columnDefinition = "char(64)") + private String name; + + @Column(name = "passw", columnDefinition = "char(32)") + private String password; + + @Column(name = "banned", columnDefinition = "tinyint(1)") + private boolean banned; + + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "user") + private Set emails = new HashSet<>(); + + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "user") + private Set facebookIds = new HashSet<>(); + + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "user") + private Set vkIds = new HashSet<>(); + + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "user") + private Set logins = new HashSet<>(); + @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "user") + private Set tgIds = new HashSet<>(); + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public Integer getId() { + return id; + } + + public void setId(Integer uid) { + this.id = uid; + } + + public boolean isBanned() { + return banned; + } + + public void setBanned(boolean banned) { + this.banned = banned; + } + + public Set getEmails() { + return emails; + } + + public void setEmails(Set emails) { + this.emails = emails; + } + + public Set getFacebookIds() { + return facebookIds; + } + + public void setFacebookIds(Set facebookIds) { + this.facebookIds = facebookIds; + } + + public Set getVkIds() { + return vkIds; + } + + public void setVkIds(Set vkIds) { + this.vkIds = vkIds; + } + + public Set getLogins() { + return logins; + } + + public void setLogins(Set logins) { + this.logins = logins; + } + + public Set getTgIds() { + return tgIds; + } + + public void setTgIds(Set tgIds) { + this.tgIds = tgIds; + } +} diff --git a/juick-server/src/main/java/com/juick/service/data/entities/VKEntity.java b/juick-server/src/main/java/com/juick/service/data/entities/VKEntity.java new file mode 100644 index 00000000..47b5c969 --- /dev/null +++ b/juick-server/src/main/java/com/juick/service/data/entities/VKEntity.java @@ -0,0 +1,20 @@ +package com.juick.service.data.entities; + +import javax.persistence.*; + +@Entity +@Table(name = "vk") +public class VKEntity extends BaseUserPropertyEntity { + @Id + @Column(name = "vk_id", columnDefinition = "bigint(20)") + @GeneratedValue(strategy = GenerationType.AUTO) + private Long vkId; + + public Long getVkId() { + return vkId; + } + + public void setVkId(Long vkId) { + this.vkId = vkId; + } +} -- cgit v1.2.3