HTML and CSS Reference
In-Depth Information
try {
query.getSingleResult();
throw new BookAlreadyExists();
} catch (NoResultException exception) {
Logger.getLogger(BookManager.class.getName()).log(Level.FINER, "No similar books found");
}
em.persist(book);
em.flush();
return book;
}
@Override
public Book updateBook(Book book) throws BookNotFound {
Book updatableBook = em.find(Book.class, book.getId());
if (updatableBook == null) {
throw new BookNotFound();
}
mergeBookAttrs(book, updatableBook);
em.merge(updatableBook);
em.flush();
return book;
}
private void mergeBookAttrs(Book book, Book updatableBook) {
if (book.getAuthor() != null) {
updatableBook.setAuthor(book.getAuthor());
}
if (book.getContent() != null) {
updatableBook.setContent(book.getContent());
}
if (book.getIsbn() != null) {
updatableBook.setIsbn(book.getIsbn());
}
if (book.getLang() != null) {
updatableBook.setLang(book.getLang());
}
if (book.getPublisher() != null) {
updatableBook.setPublisher(book.getPublisher());
}
 
Search WWH ::




Custom Search