ЛР3 без доп задания
This commit is contained in:
parent
de105ade49
commit
8baede6bca
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -42,9 +42,13 @@ public class Collection {
|
||||
if (films == null){
|
||||
films = new ArrayList<>();
|
||||
}
|
||||
this.films.add(film);
|
||||
if (!this.films.contains(film)) {
|
||||
this.films.add(film);
|
||||
film.addCollections(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void removeFilm(Film film){
|
||||
if(films != null){
|
||||
films.remove(film);
|
||||
|
@ -1,5 +1,8 @@
|
||||
package ru.ulstu.is.lab1.DataBase.model;
|
||||
|
||||
import org.hibernate.annotations.LazyCollection;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
import java.util.List;
|
||||
@ -12,12 +15,15 @@ public class Film {
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
private String name;
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
@ManyToMany
|
||||
@LazyCollection(LazyCollectionOption.FALSE)
|
||||
@JoinTable(name="films_genres",
|
||||
joinColumns = @JoinColumn(name="film_id"),
|
||||
inverseJoinColumns = @JoinColumn(name="genre_id")
|
||||
)
|
||||
private List<Genre> genres;
|
||||
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "films")
|
||||
private List<Collection> collections;
|
||||
|
||||
public Film() {
|
||||
}
|
||||
@ -42,7 +48,8 @@ public class Film {
|
||||
if (genres == null){
|
||||
genres = new ArrayList<>();
|
||||
}
|
||||
this.genres.add(genre);
|
||||
if (!this.genres.contains(genre))
|
||||
this.genres.add(genre);
|
||||
}
|
||||
|
||||
public void removeGenre(Genre genre){
|
||||
@ -55,6 +62,16 @@ public class Film {
|
||||
return genres;
|
||||
}
|
||||
|
||||
public List<Collection> getCollections() {
|
||||
return collections;
|
||||
}
|
||||
|
||||
public void addCollections(Collection collection) {
|
||||
if(this.collections==null)
|
||||
collections=new ArrayList<>();
|
||||
collections.add(collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -11,8 +11,6 @@ public class Genre {
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
private String name;
|
||||
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "genres")
|
||||
private List<Film> films;
|
||||
|
||||
public Genre() {
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@ -89,4 +91,6 @@ public class FilmService {
|
||||
public void deleteAllFilms() {
|
||||
em.createQuery("delete from Film").executeUpdate();
|
||||
}
|
||||
|
||||
//сделать запрос отбора фильмов по жанру
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
|
Loading…
Reference in New Issue
Block a user