Package com.sun.bookstore.database

Examples of com.sun.bookstore.database.Book


    /**
     * <p>Remove the item from the shopping cart.</p>
     */
    public String remove() {
        Book book = (Book) item()
                               .getItem();
        cart()
            .remove(book.getBookId());
        message(
            null,
            "ConfirmRemove",
            new Object[] { book.getTitle() });

        return (null);
    }
View Full Code Here


    /**
     * <p>Remove the item from the shopping cart.</p>
     */
    public String remove() {
        Book book = (Book) item()
                               .getItem();
        cart()
            .remove(book.getBookId());
        message(
            null,
            "ConfirmRemove",
            new Object[] { book.getTitle() });

        return (null);
    }
View Full Code Here

    /**
     * <p>Return the currently selected <code>Book</code> instance
     * from the user request.</p>
     */
    protected Book book() {
        Book book = (Book) context()
                               .getExternalContext()
                               .getRequestMap()
                               .get("book");

        return (book);
View Full Code Here

    /**
     * <p>Return the explicitly selected <code>Book</code> instance
     * from the user request.</p>
     */
    protected Book selected() {
        Book selected = (Book) context()
                                   .getExternalContext()
                                   .getSessionMap()
                                   .get("selected");

        return (selected);
View Full Code Here

    /**
     * <p>Return the currently selected <code>Book</code> instance
     * from the user request.</p>
     */
    protected Book book() {
        Book book = (Book) context()
                               .getExternalContext()
                               .getRequestMap()
                               .get("book");

        return (book);
View Full Code Here

    /**
     * <p>Return the explicitly selected <code>Book</code> instance
     * from the user request.</p>
     */
    protected Book selected() {
        Book selected = (Book) context()
                                   .getExternalContext()
                                   .getSessionMap()
                                   .get("selected");

        return (selected);
View Full Code Here

    /**
     * <p>Add the selected item to our shopping cart.</p>
     */
    public String add() {
        Book book = getFeatured();
        cart()
            .add(
            book.getBookId(),
            book);
        message(
            null,
            "ConfirmAdd",
            new Object[] { book.getTitle() });

        return ("catalog");
    }
View Full Code Here

                    "Could not get books: " + ex.getMessage());
        }
    }

    public Book getBook(String bookId) throws BookNotFoundException {
        Book requestedBook = em.find(Book.class, bookId);

        if (requestedBook == null) {
            throw new BookNotFoundException("Couldn't find book: " + bookId);
        }
View Full Code Here

        Iterator i = items.iterator();

        try {
            while (i.hasNext()) {
                ShoppingCartItem sci = (ShoppingCartItem) i.next();
                Book bd = (Book) sci.getItem();
                String id = bd.getBookId();
                int quantity = sci.getQuantity();
                buyBook(id, quantity);
            }
        } catch (Exception ex) {
            throw new OrderException("Commit failed: " + ex.getMessage());
View Full Code Here

    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.");
                }
View Full Code Here

TOP

Related Classes of com.sun.bookstore.database.Book

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.