@Override public void updateBook(BookModel bookModel) { create .update(BOOK) .set(BOOK.TITLE, bookModel.getTitle()) .set(BOOK.DATE_PUBLISH, bookModel.getDatePublish()) .set(BOOK.SHORT_DESCRIPTION, bookModel.getShortDescription()) .where(BOOK.ID_BOOK.equal(bookModel.getIdBook())) .execute(); List<Integer> existsAuthors = create .select(AUTHOR_BOOK.ID_AUTHOR) .from(AUTHOR_BOOK) .where(AUTHOR_BOOK.ID_BOOK.equal(bookModel.getIdBook())) .fetchInto(Integer.class); logger.debug("Existing authors: " + existsAuthors); List<Integer> newAuthors = new ArrayList<>(); List<Integer> authors = new ArrayList<>(); /** */ for (String idAuthor : bookModel.getAuthors()) { int id = Integer.valueOf(idAuthor); authors.add(id); if (!existsAuthors.contains(id)) { newAuthors.add(id); } } existsAuthors.removeAll(authors); logger.debug("New authors: " + newAuthors); if (!newAuthors.isEmpty()) { InsertValuesStep2<AuthorBookRecord, Integer, Integer> insertStep = create.insertInto(AUTHOR_BOOK, AUTHOR_BOOK.ID_AUTHOR, AUTHOR_BOOK.ID_BOOK); InsertValuesStep2<AuthorBookRecord, Integer, Integer> valuesStep = null; for (Integer idAuthor : newAuthors) { valuesStep = insertStep.values(idAuthor, bookModel.getIdBook()); } valuesStep.execute(); } logger.debug("Old authors: " + existsAuthors); if (!existsAuthors.isEmpty()) { create.delete(AUTHOR_BOOK).where(AUTHOR_BOOK.ID_AUTHOR.in(existsAuthors)).execute(); } }
@After public void teardown() { // Delete all books that were created in any test dsl.delete(BOOK).where(BOOK.ID.gt(4)).execute(); }
private void deleteChargePointInternal(DSLContext ctx, int chargeBoxPk) { ctx.delete(CHARGE_BOX).where(CHARGE_BOX.CHARGE_BOX_PK.equal(chargeBoxPk)).execute(); }
@Override public void unsubscribe(int userId, int newsSourceId) { dsl.delete(SUBSCRIPTIONS) .where(SUBSCRIPTIONS.USER_ID.eq(userId).and(SUBSCRIPTIONS.NEWS_SOURCE_ID.eq(newsSourceId))) .execute(); }