From 8baede6bca9a1372dd2fab41e482284c646917bd Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Mon, 3 Apr 2023 16:29:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=A03=20=D0=B1=D0=B5=D0=B7=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=BF=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data.mv.db | Bin 36864 -> 32768 bytes .../is/lab1/DataBase/model/Collection.java | 6 ++++- .../ru/ulstu/is/lab1/DataBase/model/Film.java | 21 ++++++++++++++++-- .../ulstu/is/lab1/DataBase/model/Genre.java | 2 -- .../is/lab1/DataBase/service/FilmService.java | 4 ++++ .../java/ru/ulstu/is/lab1/JpaFilmTests.java | 1 + 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/data.mv.db b/data.mv.db index 8b5e1f9870fe94703b4d54b37478d97eb117ca02..ccb25d8954576990440eb2d795f2f3ec3330e1fa 100644 GIT binary patch literal 32768 zcmeHPNpl;=6$T(ko={f2$&0*>VaXB`7@6*#6(@t>kc0?=6aa3O18bHZS!I%7C`b`q zIrxxMD#uhRl|w42R3(>G%7U-8fQ<2H#QPUxz0Q>mSxQXfq)?Iv`926XmM&l+XF#?hVT!oYy-`m4YRfm#cdng$a zFdjKgOEtvv`y(+0mwtO`wp5l%mk5;&fY?Q47mZzXb}`t+y6BgL^Z~M0kiCL7`_W++ z%q|`+&l*M&{S5(jf%KI^9~4$Xk?C(L{jbsgI{j~4+PC&_W9JIJ+}n5YqXv*tPcZeQ zq@J|YlaYLaAoY}bhrsi+zul2NZ;h?X;lqk`5Z(8&_bUB;bb$AVht~dm%Ndg>j{B_Y z*s^zVBcPN$0K|G^PY@*wrXJ+v8#Vc$B_H$`X#ZopchDW#gtl+f=Lh@ls5`pb0O?1l z`fr=8b2SJ^*$5&}y!xm3sHuAvRG=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O)eMYY1qKAQcD#+GVDM8~hd?9}z7f1+29&v8jZFJT`WAq#X!vb4jSh9KGhhhkyzM zh`3!4z|RK*krO=#hG601%m?U~XS6RuUghT>!pOkSue<_oK5aDao#wV~^nbczHTh^W zpCZbXM^}3Tex;^JJ(8q(7V66>t$k4sw`KPG=Rr%|Tc;|x?!*8%{_r=$qekbq<6jQ% zHow^ZgK6|B7tg9ln)BVW>$A$U>w0+RAZ+l!o;Kn6`*MsqHkr8HGX06}1&NQ!6tadJ zd{P^v!Mx^5CMJau^>lp|m4zddr{fU|Icy@@t`g}+Zvl@A$r@iZ3=a&&E+>n0-jpC9 z3!Eo`oa@6Mki@XB33BvaeZTYVsh@fpeK&_sTI|kvG~fxhz&`tB{AB0Y#BGah_4isR z5q^P^&b`Ul;;#<`dlvQ~aUB}{yhlr1Q8lZiI;7Qs!t|bQqNrjams1-YQ@kj7Yb9R3 xDEVS+E;PKBxDPLHS)C?8;*VM~5g*%{peKg9i@$0C$!iq^zDJ!bt5je%{{n_NbEg0R diff --git a/src/main/java/ru/ulstu/is/lab1/DataBase/model/Collection.java b/src/main/java/ru/ulstu/is/lab1/DataBase/model/Collection.java index 576dabf..e68a352 100644 --- a/src/main/java/ru/ulstu/is/lab1/DataBase/model/Collection.java +++ b/src/main/java/ru/ulstu/is/lab1/DataBase/model/Collection.java @@ -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); diff --git a/src/main/java/ru/ulstu/is/lab1/DataBase/model/Film.java b/src/main/java/ru/ulstu/is/lab1/DataBase/model/Film.java index 20c2a1a..bee65cf 100644 --- a/src/main/java/ru/ulstu/is/lab1/DataBase/model/Film.java +++ b/src/main/java/ru/ulstu/is/lab1/DataBase/model/Film.java @@ -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 genres; + @ManyToMany(fetch = FetchType.EAGER, mappedBy = "films") + private List 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 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; diff --git a/src/main/java/ru/ulstu/is/lab1/DataBase/model/Genre.java b/src/main/java/ru/ulstu/is/lab1/DataBase/model/Genre.java index 71af0ed..382a835 100644 --- a/src/main/java/ru/ulstu/is/lab1/DataBase/model/Genre.java +++ b/src/main/java/ru/ulstu/is/lab1/DataBase/model/Genre.java @@ -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 films; public Genre() { } diff --git a/src/main/java/ru/ulstu/is/lab1/DataBase/service/FilmService.java b/src/main/java/ru/ulstu/is/lab1/DataBase/service/FilmService.java index a91c3cd..f0bdd14 100644 --- a/src/main/java/ru/ulstu/is/lab1/DataBase/service/FilmService.java +++ b/src/main/java/ru/ulstu/is/lab1/DataBase/service/FilmService.java @@ -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(); } + + //сделать запрос отбора фильмов по жанру } diff --git a/src/test/java/ru/ulstu/is/lab1/JpaFilmTests.java b/src/test/java/ru/ulstu/is/lab1/JpaFilmTests.java index 028d7a0..eaf84e1 100644 --- a/src/test/java/ru/ulstu/is/lab1/JpaFilmTests.java +++ b/src/test/java/ru/ulstu/is/lab1/JpaFilmTests.java @@ -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