From 3e57102a6dc9f7333a0d3febc2bee4c7080b738b Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Mon, 10 Apr 2023 22:02:08 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=A03=20=D0=B4=D0=BE=D0=BF=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data.mv.db | Bin 32768 -> 40960 bytes .../is/lab1/DataBase/service/FilmService.java | 7 ++++ .../ru/ulstu/is/lab1/JpaCollectionTests.java | 22 +++++----- .../java/ru/ulstu/is/lab1/JpaFilmTests.java | 39 +++++++++++++----- 4 files changed, 46 insertions(+), 22 deletions(-) diff --git a/data.mv.db b/data.mv.db index ccb25d8954576990440eb2d795f2f3ec3330e1fa..1f39d16cfaaac63691b96eddd83240fdec43dd7c 100644 GIT binary patch literal 40960 zcmeHQ%WoUU87FDlVddC)JI>P^#)+*|VRvTVJQSuVN}?rEGD$s*q80Wro4AohRi<4# z=%I(6irxz3P!vUb?+YkUpoboV-ikC0&|7;bdg>q1emk>|;gU;H4 z=9_P4_WR~Hi&Z@1?DX7^qGRXQ$E1p6S)Oq}yu15RRmC&zKC%16t0GhP2$4Oa*fV}_ z|F+$SMEA)4om;)#;5mPX^xY51eiiG6W+LoN<;0&rKp-Fx5C{ka1Ofs9fq+0jARrJB z2nYlO0*?R!i_yG4I*R%KBhV^B1c87+Kp-Fx5C{ka1Ofs9fq+0jARrJB2%Ibev6DXv z0@xwDRWx(k-mB^|9PU?b2nE_=@5SeB;=e@y-`gX*-FsyLjBud0TuTIOIbX<$?|&4h`SdN?P|vUOWFlJcOx(Wi**5E&ax zZ535fuw#0xa$$GP&Mc1$*e@t@K|uut=dHY+H}gtfD`2yLtpaum*ezg^Hwv0x(B)k2 z)XQhe`CKViq87NK*wKj}o~Uwkf}Xlf`gY}(cP22r6~qph9kgHOnGJ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03mZPjV>ozo1RjGRG4ck)c&gwNaTUZ%`bZ- z_P~UcK#$(;fgXFnuM`PnkhBB%3b%+Ax(C^LeLp+dJ(@P!U|)2LhAzVq&o@9-5w*+_ zSH#nwJ0ouJZ|p!%lB9V_QZDgPlH^~Odd~0=Yi|zECRrT?bAS|Aqn74Sp4BH=yO?3O zTDjNa=ma3};MDDVj!}GT9Do!-PwbeW6ORa*w6Xw*hy_vaD@{iL+t3Q^!Y!}sE-Z1 z+!=21%nX=u2brNFOMPbevxn4ss>OH5)Rze)F1no=Enx-=W~hM%nBmX|=4c9Qb|%M= z#y^|DkG8_E`S6cuG5mymedaLGJa(&lu;uc@gK!%IhS~Zc?5Uzc5<`hFw1kWSLpixY z?Fh*gv<{LxzAd^pGXmX&!xTh`$d#~bA*Yl^cT@{sNE7J#p*T7oALixDFQRTq{*AYnWLCKN6#MN^oSD@|bwx zmqXdBqc`Q9_ku7`FLYnki}!+h&+fj#!iP{{Z@JHk1GW 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 f0bdd14..d77db55 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 @@ -93,4 +93,11 @@ public class FilmService { } //сделать запрос отбора фильмов по жанру + @Transactional + public List findFilmOnGenre(Genre genre){ + List filmList = em.createQuery("SELECT DISTINCT f FROM Film f where :filmsGenres MEMBER OF f.genres") + .setParameter("filmsGenres", genre) + .getResultList(); + return filmList; + } } diff --git a/src/test/java/ru/ulstu/is/lab1/JpaCollectionTests.java b/src/test/java/ru/ulstu/is/lab1/JpaCollectionTests.java index 0f5dfef..86a3129 100644 --- a/src/test/java/ru/ulstu/is/lab1/JpaCollectionTests.java +++ b/src/test/java/ru/ulstu/is/lab1/JpaCollectionTests.java @@ -29,11 +29,11 @@ public class JpaCollectionTests { filmService.deleteAllFilms(); final Film film1 = filmService.addFilm("Джокер"); final Film film2 = filmService.addFilm("Учитель на замену"); - final Collection collection1 = collectionService.addCollection("Грустное"); - collection1.addFilm(film1); - collection1.addFilm(film2); - final Collection collection2 = collectionService.addCollection("Об антигерое"); - collection2.addFilm(film1); + Collection collection1 = collectionService.addCollection("Грустное"); + collection1 = collectionService.addFilm(collection1.getId(), film1.getId()); + collection1 = collectionService.addFilm(collection1.getId(), film2.getId()); + Collection collection2 = collectionService.addCollection("Об антигерое"); + collection2 = collectionService.addFilm(collection2.getId(), film1.getId()); log.info("testCreateCollection " + collection1.toString()); log.info("testCreateCollection " + collection2.toString()); Assertions.assertNotNull(collection1.getId()); @@ -44,8 +44,8 @@ public class JpaCollectionTests { collectionService.deleteAllCollections(); filmService.deleteAllFilms(); final Film film = filmService.addFilm("Астрал"); - final Collection collection = collectionService.addCollection("Пугающее"); - collection.addFilm(film); + Collection collection = collectionService.addCollection("Пугающее"); + collection = collectionService.addFilm(collection.getId(), film.getId()); log.info("testCollectionRead[0]: " + collection.toString()); final Collection findCollection = collectionService.findCollection(collection.getId()); log.info("testCollectionRead[1]: " + findCollection.toString()); @@ -58,10 +58,10 @@ public class JpaCollectionTests { final Film film1 = filmService.addFilm("Начало"); final Film film2 = filmService.addFilm("Пункт назначения"); final Film film3 = filmService.addFilm("День сурка"); - final Collection collection = collectionService.addCollection("Избранное"); - collection.addFilm(film1); - collection.addFilm(film2); - collection.addFilm(film3); + Collection collection = collectionService.addCollection("Избранное"); + collection = collectionService.addFilm(collection.getId(), film1.getId()); + collection = collectionService.addFilm(collection.getId(), film2.getId()); + collection = collectionService.addFilm(collection.getId(), film3.getId()); log.info("testAddFilms[0]: " + collection.toString()); Assertions.assertEquals(collection.getFilms().size(), 3); } diff --git a/src/test/java/ru/ulstu/is/lab1/JpaFilmTests.java b/src/test/java/ru/ulstu/is/lab1/JpaFilmTests.java index eaf84e1..782291b 100644 --- a/src/test/java/ru/ulstu/is/lab1/JpaFilmTests.java +++ b/src/test/java/ru/ulstu/is/lab1/JpaFilmTests.java @@ -28,11 +28,11 @@ public class JpaFilmTests { genreService.deleteAllGenres(); final Genre genre1 = genreService.addGenre("Фантастика"); final Genre genre2 = genreService.addGenre("Комедия"); - final Film film1 = filmService.addFilm("Сапожник"); - film1.addGenre(genre1); - film1.addGenre(genre2); - final Film film2 = filmService.addFilm("Маска"); - film2.addGenre(genre1); + Film film1 = filmService.addFilm("Сапожник"); + film1 = filmService.addGenre(film1.getId(), genre1.getId()); + film1 = filmService.addGenre(film1.getId(), genre2.getId()); + Film film2 = filmService.addFilm("Маска"); + film2 = filmService.addGenre(film2.getId(), genre1.getId()); log.info("testCreateFilm " + film1.toString()); log.info("testCreateFilm " + film2.toString()); Assertions.assertNotNull(film1.getId()); @@ -43,8 +43,8 @@ public class JpaFilmTests { filmService.deleteAllFilms(); genreService.deleteAllGenres(); final Genre genre = genreService.addGenre("Ужасы"); - final Film film = filmService.addFilm("Оно"); - film.addGenre(genre); + Film film = filmService.addFilm("Оно"); + film = filmService.addGenre(film.getId(), genre.getId()); log.info("testFilmRead[0]: " + film.toString()); final Film findFilm = filmService.findFilm(film.getId()); log.info("testFilmRead[1]: " + findFilm.toString()); @@ -57,10 +57,10 @@ public class JpaFilmTests { final Genre genre1 = genreService.addGenre("Драма"); final Genre genre2 = genreService.addGenre("Триллер"); final Genre genre3 = genreService.addGenre("Боевик"); - final Film film = filmService.addFilm("Брат"); - film.addGenre(genre1); - film.addGenre(genre2); - film.addGenre(genre3); + Film film = filmService.addFilm("Брат"); + film = filmService.addGenre(film.getId(), genre1.getId()); + film = filmService.addGenre(film.getId(), genre2.getId()); + film = filmService.addGenre(film.getId(), genre3.getId()); log.info("testAddGenres[0]: " + film.toString()); Assertions.assertEquals(film.getGenres().size(), 3); } @@ -76,4 +76,21 @@ public class JpaFilmTests { log.info("testFilmReadAllEmpty: " + films.toString()); Assertions.assertEquals(films.size(), 0); } + @Test + void testSelect() { + filmService.deleteAllFilms(); + genreService.deleteAllGenres(); + final Genre genre1 = genreService.addGenre("Драма"); + final Genre genre2 = genreService.addGenre("Триллер"); + final Genre genre3 = genreService.addGenre("Боевик"); + Film film = filmService.addFilm("Брат"); + Film film2 = filmService.addFilm("Маска"); + film = filmService.addGenre(film.getId(), genre1.getId()); + film = filmService.addGenre(film.getId(), genre2.getId()); + film = filmService.addGenre(film.getId(), genre3.getId()); + film2 = filmService.addGenre(film2.getId(), genre1.getId()); + List list = filmService.findFilmOnGenre(genre1); + log.info("findFilmOnGenre: " + list.toString()); + Assertions.assertEquals(list.size(), 2); + } }