Example #1
0
 /**
  * Updates book information.
  *
  * @param oldBook book, which parameters should be updated.
  * @param newBook book, which parameters will be set to old book.
  * @throws LibraryProviderException in case of LibraryProviderException
  * @throws RemoteException in case of RemoteException
  */
 public synchronized void updateBook(Book oldBook, Book newBook)
     throws LibraryProviderException, RemoteException {
   Book copyOld = oldBook.copyBook();
   int newBookCount = newBook.getCount();
   int reservedBookCount = recordProvider.getReservedBookCount(oldBook.getId());
   if (newBookCount < reservedBookCount) {
     throw new LibraryProviderException(
         "Can't decrease count of copies of book with ISBN "
             + oldBook.getIsbn()
             + " to "
             + newBookCount
             + ", minimum value is "
             + reservedBookCount);
   }
   if (newBook.getCount() <= 5) {
     try {
       bookDAO.updateBook(oldBook.getId(), newBook);
       newBook.setId(oldBook.getId());
     } catch (LibraryDAOException e) {
       throw new LibraryProviderException(e.getMessage(), e);
     }
     updateISBNCash(copyOld, newBook);
     updateSearchCash(copyOld, newBook);
   } else {
     throw new LibraryProviderException(
         "Count of books with ISBN "
             + newBook.getIsbn()
             + " can't be updated up "
             + "to "
             + newBook.getCount()
             + ", maximum count of "
             + "book copies should be less than 5, you can add no more than 5 books.");
   }
 }
Example #2
0
 public synchronized void deleteBooks(Book book, int deleteCount)
     throws LibraryProviderException, RemoteException {
   int bookCount = getBookCount(book);
   checkDeletionChance(book, deleteCount);
   if (bookCount <= deleteCount) {
     try {
       bookDAO.delete(book.getId());
     } catch (LibraryDAOException e) {
       throw new LibraryProviderException(e.getMessage(), e);
     }
     removeFromISBNCash(book);
     removeBookFromSearchCash(book);
   } else {
     Book copy = book.copyBook();
     book.setCount(bookCount - deleteCount);
     try {
       bookDAO.updateBook(book.getId(), book);
     } catch (LibraryDAOException e) {
       throw new LibraryProviderException(e.getMessage(), e);
     }
     updateISBNCash(copy, book);
     updateSearchCash(copy, book);
   }
 }