Ejemplo n.º 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.");
   }
 }
Ejemplo n.º 2
0
 private void checkDeletionChance(Book book, int deleteCount)
     throws LibraryProviderException, RemoteException {
   int bookCount = getBookCount(book);
   int reservedCount = recordProvider.getReservedBookCount(book.getId());
   int availableCount = bookCount - reservedCount;
   if (availableCount < deleteCount) {
     throw new LibraryProviderException(
         "Can't delete"
             + deleteCount
             + " book(s) with ISBN '"
             + book.getIsbn()
             + "'. There are "
             + reservedCount
             + " book(s) reserved and "
             + availableCount
             + " book(s) available.");
   }
 }