Ejemplo n.º 1
0
  /** {@inheritDoc} */
  @Override
  public Book findByIsbn(final String isbn) {

    BookPrimaryKey bookPrimaryKey = new BookPrimaryKey(isbn);
    BookKey bookKey =
        bookIndexCache.get(
            new ServiceContext<BookKey>() {

              public BookKey execute() {

                Book book = bookStorage.findByIsbn(isbn);

                if (book == null) {
                  return null;
                }

                BookKey bookKey = new BookKey(book);
                exoBookCache.put(bookKey, new BookData(book));
                return bookKey;
              }
            },
            bookPrimaryKey);

    if (bookKey != null) {
      return findById(bookKey.getId());
    }

    return null;
  }
Ejemplo n.º 2
0
  /**
   * Build the book list from the caches Ids.
   *
   * @param data ids
   * @return books
   */
  private List<Book> buildBooks(ListBooksData data) {

    List<Book> books = new ArrayList<Book>();

    for (BookKey k : data.getIds()) {
      Book gotBook = findById(k.getId());
      books.add(gotBook);
    }

    return books;
  }