Changeset 2d57cad in Git for src/main/java/com/wediscussmovies/project/model/Discussion.java
- Timestamp:
- 01/16/22 17:12:01 (3 years ago)
- Branches:
- main
- Children:
- 7fafead
- Parents:
- 839f96a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/wediscussmovies/project/model/Discussion.java
r839f96a r2d57cad 3 3 import javax.persistence.*; 4 4 import java.sql.Date; 5 import java.util.List; 5 import java.util.Collection; 6 import java.util.Objects; 6 7 7 8 @Entity 9 @Table(name = "discussions", schema = "project", catalog = "db_202122z_va_prj_wediscussmovies") 8 10 public class Discussion { 11 @GeneratedValue(strategy = GenerationType.IDENTITY) 9 12 @Id 10 @GeneratedValue 11 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; 12 36 13 37 @ManyToOne 14 @Column(name = "movie_id") 15 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; 16 48 17 @ManyToOne()18 @Column(name = "person_id")19 private Person person;49 public int getDiscussionId() { 50 return discussionId; 51 } 20 52 21 @ManyToOne22 @Column(name = "user_id")23 private User user;53 public void setDiscussionId(int discussionId) { 54 this.discussionId = discussionId; 55 } 24 56 25 @Column(name = "text", length = 1000, nullable = false) 26 private String text; 57 public String getType() { 58 return type; 59 } 27 60 28 @Column(name = "title", length = 1000, nullable = false) 29 private String title; 61 public void setType(String type) { 62 this.type = type; 63 } 30 64 31 @Column(name = "date", nullable = false) 32 private Date date; 65 public String getText() { 66 return text; 67 } 33 68 34 @OneToMany 35 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 } 176 177 public Discussion() { 178 } 179 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; 183 this.title = title; 184 this.date = date; 185 this.userId = userId; 186 this.movieId = movieId; 187 this.personId = personId; 188 } 36 189 } 37 38 39 /*40 create table discussions(41 discussion_id serial primary key,42 type char(1) not null,43 text varchar(1000) not null,44 title varchar(250) not null,45 date date not null,46 user_id integer not null,47 movie_id integer,48 person_id integer,49 constraint fk_user_created foreign key (user_id) references users(user_id)50 on delete cascade on update cascade,51 constraint ck_type_discussion check( (type = 'M' and movie_id notnull and person_id isnull)52 or (type='P' and person_id notnull and movie_id isnull)),53 constraint fk_discussion_movie foreign key (movie_id) references movies(movie_id)54 on delete cascade on update cascade,55 constraint fk_discussion_person foreign key (person_id) references persons(person_id)56 on delete cascade on update cascade57 );58 59 */
Note:
See TracChangeset
for help on using the changeset viewer.