Ignore:
Timestamp:
01/16/22 17:12:01 (3 years ago)
Author:
Test <matonikolov77@…>
Branches:
main
Children:
7fafead
Parents:
839f96a
Message:

Initial model part

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/wediscussmovies/project/model/Movie.java

    r839f96a r2d57cad  
    33import javax.persistence.*;
    44import java.sql.Date;
    5 import java.util.List;
     5import java.util.Collection;
     6import java.util.Objects;
    67
    7 @Entity(name="movies")
     8@Entity
     9@Table(name = "movies", schema = "project", catalog = "db_202122z_va_prj_wediscussmovies")
    810public class Movie {
     11    @GeneratedValue(strategy = GenerationType.IDENTITY)
    912    @Id
    10     @GeneratedValue
    11     @Column(name="movie_id", nullable = false)
    12     private int movie_id;
     13    @Column(name = "movie_id")
     14    private int movieId;
     15    @Basic
     16    @Column(name = "title")
     17    private String title;
     18    @Basic
     19    @Column(name = "description")
     20    private String description;
     21    @Basic
     22    @Column(name = "image_url")
     23    private String imageUrl;
     24    @Basic
     25    @Column(name = "airing_date")
     26    private Date airingDate;
     27    @Basic
     28    @Column(name = "imdb_rating")
     29    private Double imdbRating;
     30    @Basic
     31    @Column(name = "director_id")
     32    private Integer directorId;
     33    @OneToMany(mappedBy = "moviesByMovieId")
     34    private Collection<Discussion> discussionsByMovieId;
     35    @OneToMany(mappedBy = "moviesByMovieId")
     36    private Collection<MovieActorsEntity> movieActorsByMovieId;
     37    @OneToMany(mappedBy = "moviesByMovieId")
     38    private Collection<MovieGenresEntity> movieGenresByMovieId;
     39    @OneToMany(mappedBy = "moviesByMovieId")
     40    private Collection<MovieLikesEntity> movieLikesByMovieId;
     41    @OneToMany(mappedBy = "moviesByMovieId")
     42    private Collection<MovieRatesEntity> movieRatesByMovieId;
     43    @ManyToOne
     44    @JoinColumn(name = "director_id", referencedColumnName = "person_id",insertable = false, updatable = false)
     45    private Person personsByDirectorId;
    1346
    14     @Column(name="title", length = 150, unique = true, nullable = false)
    15     private String Title;
     47    public int getMovieId() {
     48        return movieId;
     49    }
    1650
    17     @Column(name="description", nullable = false, length = 1000)
    18     private String description;
     51    public void setMovieId(int movieId) {
     52        this.movieId = movieId;
     53    }
    1954
    20     @Column(name="image_url", length = 300, nullable = false)
    21     private String image_url;
     55    public String getTitle() {
     56        return title;
     57    }
    2258
    23     @Column(name="airing_date")
    24     private Date airing_date;
     59    public void setTitle(String title) {
     60        this.title = title;
     61    }
    2562
    26     @Column(name="imdb_rating")
    27     private float imdb_rating;
     63    public String getDescription() {
     64        return description;
     65    }
    2866
    29     @Column(name="director_id")
    30     @ManyToOne
    31     private Person director;
     67    public void setDescription(String description) {
     68        this.description = description;
     69    }
    3270
    33     @ManyToMany(mappedBy = "movie_actors")
    34     private List<Person> actors;
     71    public String getImageUrl() {
     72        return imageUrl;
     73    }
    3574
    36     @ManyToMany(mappedBy = "movie_genres")
    37     private List<Genre> genres;
     75    public void setImageUrl(String imageUrl) {
     76        this.imageUrl = imageUrl;
     77    }
     78
     79    public Date getAiringDate() {
     80        return airingDate;
     81    }
     82
     83    public void setAiringDate(Date airingDate) {
     84        this.airingDate = airingDate;
     85    }
     86
     87    public Double getImdbRating() {
     88        return imdbRating;
     89    }
     90
     91    public void setImdbRating(Double imdbRating) {
     92        this.imdbRating = imdbRating;
     93    }
     94
     95    public Integer getDirectorId() {
     96        return directorId;
     97    }
     98
     99    public void setDirectorId(Integer directorId) {
     100        this.directorId = directorId;
     101    }
     102
     103    @Override
     104    public boolean equals(Object o) {
     105        if (this == o) return true;
     106        if (o == null || getClass() != o.getClass()) return false;
     107
     108        Movie that = (Movie) o;
     109
     110        if (movieId != that.movieId) return false;
     111        if (!Objects.equals(title, that.title)) return false;
     112        if (!Objects.equals(description, that.description)) return false;
     113        if (!Objects.equals(imageUrl, that.imageUrl)) return false;
     114        if (!Objects.equals(airingDate, that.airingDate)) return false;
     115        if (!Objects.equals(imdbRating, that.imdbRating)) return false;
     116        if (!Objects.equals(directorId, that.directorId)) return false;
     117
     118        return true;
     119    }
     120
     121    public Movie(String title, String description, String imageUrl, Date airingDate, Double imdbRating, Integer directorId) {
     122        this.title = title;
     123        this.description = description;
     124        this.imageUrl = imageUrl;
     125        this.airingDate = airingDate;
     126        this.imdbRating = imdbRating;
     127        this.directorId = directorId;
     128    }
     129
     130    public Movie() {
     131    }
     132
     133    @Override
     134    public int hashCode() {
     135        int result = movieId;
     136        result = 31 * result + (title != null ? title.hashCode() : 0);
     137        result = 31 * result + (description != null ? description.hashCode() : 0);
     138        result = 31 * result + (imageUrl != null ? imageUrl.hashCode() : 0);
     139        result = 31 * result + (airingDate != null ? airingDate.hashCode() : 0);
     140        result = 31 * result + (imdbRating != null ? imdbRating.hashCode() : 0);
     141        result = 31 * result + (directorId != null ? directorId.hashCode() : 0);
     142        return result;
     143    }
     144
     145    public Collection<Discussion> getDiscussionsByMovieId() {
     146        return discussionsByMovieId;
     147    }
     148
     149    public void setDiscussionsByMovieId(Collection<Discussion> discussionsByMovieId) {
     150        this.discussionsByMovieId = discussionsByMovieId;
     151    }
     152
     153    public Collection<MovieActorsEntity> getMovieActorsByMovieId() {
     154        return movieActorsByMovieId;
     155    }
     156
     157    public void setMovieActorsByMovieId(Collection<MovieActorsEntity> movieActorsByMovieId) {
     158        this.movieActorsByMovieId = movieActorsByMovieId;
     159    }
     160
     161    public Collection<MovieGenresEntity> getMovieGenresByMovieId() {
     162        return movieGenresByMovieId;
     163    }
     164
     165    public void setMovieGenresByMovieId(Collection<MovieGenresEntity> movieGenresByMovieId) {
     166        this.movieGenresByMovieId = movieGenresByMovieId;
     167    }
     168
     169    public Collection<MovieLikesEntity> getMovieLikesByMovieId() {
     170        return movieLikesByMovieId;
     171    }
     172
     173    public void setMovieLikesByMovieId(Collection<MovieLikesEntity> movieLikesByMovieId) {
     174        this.movieLikesByMovieId = movieLikesByMovieId;
     175    }
     176
     177    public Collection<MovieRatesEntity> getMovieRatesByMovieId() {
     178        return movieRatesByMovieId;
     179    }
     180
     181    public void setMovieRatesByMovieId(Collection<MovieRatesEntity> movieRatesByMovieId) {
     182        this.movieRatesByMovieId = movieRatesByMovieId;
     183    }
     184
     185    public Person getPersonsByDirectorId() {
     186        return personsByDirectorId;
     187    }
     188
     189    public void setPersonsByDirectorId(Person personsByDirectorId) {
     190        this.personsByDirectorId = personsByDirectorId;
     191    }
    38192}
    39 
    40 
    41 /*
    42 
    43     create table movies(
    44         movie_id serial primary key,
    45         title varchar(150) not null unique,
    46         description varchar(1000) not null,
    47         image_url varchar(300) not null,
    48         airing_date date not null,
    49         imdb_rating float,
    50         director_id integer,
    51         constraint fk_movie_director foreign key (director_id) references persons(person_id)
    52         on delete cascade on update cascade,
    53         constraint ck_person_is_director check( check_constraint_person(director_id) = 'D')
    54     );
    55  */
Note: See TracChangeset for help on using the changeset viewer.