@Override public Book save(BookDto bookDto) { Book book = bookDao.get(bookDto.getId()); updateBookFields(book, bookDto); return save(book); }
@Override public Book save(Book book) { bookDao.add(book); deleteBookFromCategories(book.getId()); if (book.getCategory() != null && categoryDao.get(book.getCategory()) != null) { Category category = categoryDao.get(book.getCategory()); HashSet<String> booksSet = category.getBooks(); if (booksSet == null) booksSet = new HashSet<String>(); booksSet.add(book.getId()); category.setBooks(booksSet); categoryDao.add(category); } bookDao.add(book); return get(book.getId()); }
@Override public void delete(Book book) { deleteBookFromCategories(book.getId()); bookDao.delete(book); }
@Override public void delete(String id) { deleteBookFromCategories(id); bookDao.delete(id); }
@Override public List<Book> getByAuthor(String author) { return bookDao.getByAuthor(author); }
@Override public List<Book> getByYear(short year) { return bookDao.getByYear(year); }
@Override public List<Book> getAll() { return bookDao.getAll(); }
@Override public List<Book> getByTitle(String title) { return bookDao.getByTitle(title); }
@Override public Book get(String id) { return bookDao.get(id); }
@Override public void add(Book book) { bookDao.add(book); }
@Override public List<Book> get(int fromIndex, int toIndex) { return bookDao.get(fromIndex, toIndex); }
@Override public long count() { return bookDao.count(); }
@Override public List<Book> find(String... words) { return bookDao.find(words); }