- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/wediscussmovies/project/model/Discussion.java
r2a5d6a3 r2d57cad 1 1 package com.wediscussmovies.project.model; 2 3 import lombok.Data;4 2 5 3 import javax.persistence.*; 6 4 import java.sql.Date; 7 import java.util.List; 5 import java.util.Collection; 6 import java.util.Objects; 8 7 9 @Data10 8 @Entity 11 @Table (name="discussions")9 @Table(name = "discussions", schema = "project", catalog = "db_202122z_va_prj_wediscussmovies") 12 10 public class Discussion { 11 @GeneratedValue(strategy = GenerationType.IDENTITY) 13 12 @Id 14 @GeneratedValue 15 private int discussion_id; 13 @Column(name = "discussion_id") 14 private int discussionId; 15 @Basic 16 @Column(name = "type") 17 private String type; 18 @Basic 19 @Column(name = "text") 20 private String text; 21 @Basic 22 @Column(name = "title") 23 private String title; 24 @Basic 25 @Column(name = "date") 26 private Date date; 27 @Basic 28 @Column(name = "user_id") 29 private int userId; 30 @Basic 31 @Column(name = "movie_id") 32 private Integer movieId; 33 @Basic 34 @Column(name = "person_id") 35 private Integer personId; 16 36 17 37 @ManyToOne 18 @Column(name = "movie_id") 19 private Movie movie; 38 @JoinColumn(name = "user_id", referencedColumnName = "user_id", nullable = false,insertable = false, updatable = false) 39 private User usersByUserId; 40 @ManyToOne 41 @JoinColumn(name = "movie_id", referencedColumnName = "movie_id",insertable = false, updatable = false) 42 private Movie moviesByMovieId; 43 @ManyToOne 44 @JoinColumn(name = "person_id", referencedColumnName = "person_id",insertable = false, updatable = false) 45 private Person personsByPersonId; 46 @OneToMany(mappedBy = "discussionsByDiscussionId") 47 private Collection<Reply> repliesByDiscussionId; 20 48 21 @ManyToOne()22 @Column(name = "person_id")23 private Person person;49 public int getDiscussionId() { 50 return discussionId; 51 } 24 52 25 @ManyToOne26 @Column(name = "user_id")27 private User user;53 public void setDiscussionId(int discussionId) { 54 this.discussionId = discussionId; 55 } 28 56 29 @Column(name = "text", length = 1000, nullable = false) 30 private String text; 57 public String getType() { 58 return type; 59 } 31 60 32 @Column(name = "title", length = 1000, nullable = false) 33 private String title; 61 public void setType(String type) { 62 this.type = type; 63 } 34 64 35 @Column(name = "date", nullable = false) 36 private Date date; 65 public String getText() { 66 return text; 67 } 37 68 38 @Column(name = "type", nullable = false) 39 private DiscussionType type; 40 @OneToMany 41 private List<Reply> replies; 69 public void setText(String text) { 70 this.text = text; 71 } 72 73 public String getTitle() { 74 return title; 75 } 76 77 public void setTitle(String title) { 78 this.title = title; 79 } 80 81 public Date getDate() { 82 return date; 83 } 84 85 public void setDate(Date date) { 86 this.date = date; 87 } 88 89 public int getUserId() { 90 return userId; 91 } 92 93 public void setUserId(int userId) { 94 this.userId = userId; 95 } 96 97 public Integer getMovieId() { 98 return movieId; 99 } 100 101 public void setMovieId(Integer movieId) { 102 this.movieId = movieId; 103 } 104 105 public Integer getPersonId() { 106 return personId; 107 } 108 109 public void setPersonId(Integer personId) { 110 this.personId = personId; 111 } 112 113 @Override 114 public boolean equals(Object o) { 115 if (this == o) return true; 116 if (o == null || getClass() != o.getClass()) return false; 117 118 Discussion that = (Discussion) o; 119 120 if (discussionId != that.discussionId) return false; 121 if (userId != that.userId) return false; 122 if (!Objects.equals(type, that.type)) return false; 123 if (!Objects.equals(text, that.text)) return false; 124 if (!Objects.equals(title, that.title)) return false; 125 if (!Objects.equals(date, that.date)) return false; 126 if (!Objects.equals(movieId, that.movieId)) return false; 127 if (!Objects.equals(personId, that.personId)) return false; 128 129 return true; 130 } 131 132 @Override 133 public int hashCode() { 134 int result = discussionId; 135 result = 31 * result + (type != null ? type.hashCode() : 0); 136 result = 31 * result + (text != null ? text.hashCode() : 0); 137 result = 31 * result + (title != null ? title.hashCode() : 0); 138 result = 31 * result + (date != null ? date.hashCode() : 0); 139 result = 31 * result + userId; 140 result = 31 * result + (movieId != null ? movieId.hashCode() : 0); 141 result = 31 * result + (personId != null ? personId.hashCode() : 0); 142 return result; 143 } 144 145 public User getUsersByUserId() { 146 return usersByUserId; 147 } 148 149 public void setUsersByUserId(User usersByUserId) { 150 this.usersByUserId = usersByUserId; 151 } 152 153 public Movie getMoviesByMovieId() { 154 return moviesByMovieId; 155 } 156 157 public void setMoviesByMovieId(Movie moviesByMovieId) { 158 this.moviesByMovieId = moviesByMovieId; 159 } 160 161 public Person getPersonsByPersonId() { 162 return personsByPersonId; 163 } 164 165 public void setPersonsByPersonId(Person personsByPersonId) { 166 this.personsByPersonId = personsByPersonId; 167 } 168 169 public Collection<Reply> getRepliesByDiscussionId() { 170 return repliesByDiscussionId; 171 } 172 173 public void setRepliesByDiscussionId(Collection<Reply> repliesByDiscussionId) { 174 this.repliesByDiscussionId = repliesByDiscussionId; 175 } 42 176 43 177 public Discussion() { 44 178 } 45 179 46 public Discussion(String title, String text, User user, Movie movie, Date valueOf) { 180 public Discussion(String type, String text, String title, Date date, int userId, Integer movieId, Integer personId) { 181 this.type = type; 182 this.text = text; 47 183 this.title = title; 48 this.text = text; 49 this.user = user; 50 this.date = valueOf; 51 this.movie = movie; 52 this.type = DiscussionType.M; 184 this.date = date; 185 this.userId = userId; 186 this.movieId = movieId; 187 this.personId = personId; 53 188 } 54 55 public Discussion(String title, String text, User user, Person person, Date valueOf) {56 this.title = title;57 this.text = text;58 this.user = user;59 this.date = valueOf;60 this.person = person;61 this.type = DiscussionType.P;62 }63 64 65 189 } 66 67 68 /*69 create table discussions(70 discussion_id serial primary key,71 type char(1) not null,72 text varchar(1000) not null,73 title varchar(250) not null,74 date date not null,75 user_id integer not null,76 movie_id integer,77 person_id integer,78 constraint fk_user_created foreign key (user_id) references users(user_id)79 on delete cascade on update cascade,80 constraint ck_type_discussion check( (type = 'M' and movie_id notnull and person_id isnull)81 or (type='P' and person_id notnull and movie_id isnull)),82 constraint fk_discussion_movie foreign key (movie_id) references movies(movie_id)83 on delete cascade on update cascade,84 constraint fk_discussion_person foreign key (person_id) references persons(person_id)85 on delete cascade on update cascade86 );87 88 */
Note:
See TracChangeset
for help on using the changeset viewer.