示例#1
0
 /**
  * Creates new book in book storage. If book with the isbn as in new book is already exists,
  * updates count of books with appropriate isbn. Doesn't allow to create more than 5 copies of
  * books with the same isbn.
  *
  * @param book for creation
  * @throws LibraryProviderException in case of LibraryProviderException
  * @throws RemoteException in case of RemoteException
  */
 public synchronized void createBook(Book book) throws LibraryProviderException, RemoteException {
   checkISBNCount(book);
   Book sameBook = isbnCash.get(book.getIsbn());
   if (sameBook == null) {
     try {
       bookDAO.createBook(book);
     } catch (LibraryDAOException e) {
       throw new LibraryProviderException(e.getMessage(), e);
     }
     addBookToSearchCash(book);
     addToISBNCash(book);
   } else {
     book.setCount(sameBook.getCount() + book.getCount());
     book.setId(sameBook.getId());
     try {
       bookDAO.updateBook(sameBook.getId(), book);
     } catch (LibraryDAOException e) {
       throw new LibraryProviderException(e.getMessage(), e);
     }
     updateISBNCash(sameBook, book);
     updateSearchCash(sameBook, book);
   }
 }
示例#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);
   }
 }