From 8a0fbbd35c13054a947ea0d27ca117542bc452b9 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 18 May 2018 15:33:38 +0300 Subject: JPA WIP --- .../juick/service/data/entities/MessageEntity.java | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 juick-server/src/main/java/com/juick/service/data/entities/MessageEntity.java (limited to 'juick-server/src/main/java/com/juick/service/data/entities/MessageEntity.java') 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; + } +} -- cgit v1.2.3