public void buyBook(
String bookId,
int quantity) throws OrderException {
try {
Book requestedBook = em.find(Book.class, bookId);
if (requestedBook != null) {
int inventory = requestedBook.getInventory();
if ((inventory - quantity) >= 0) {
int newInventory = inventory - quantity;
requestedBook.setInventory(newInventory);
} else {
throw new OrderException(
"Not enough of " + bookId
+ " in stock to complete order.");
}