Ejemplo n.º 1
0
  public static int editBook(Book book) throws Exception {
    int intStat = 0;

    String sql =
        "UPDATE Books SET ISBN10 = ?, ISBN13 = ?, "
            + "Title = ?, Author = ?, Edition = ?, Publisher = ?, "
            + "Description = ?, YearPublish = ?, Copies = ? "
            + "WHERE ID = ?";

    PreparedStatement ps = Connector.getConnection().prepareStatement(sql);

    ps.setString(1, book.getIsbn10());
    ps.setString(2, book.getIsbn13());
    ps.setString(3, book.getTitle());
    ps.setString(4, book.getAuthor());
    ps.setString(5, book.getEdition());
    ps.setString(6, book.getPublisher());
    ps.setString(7, book.getDescription());
    ps.setInt(8, book.getYearPublish());
    ps.setInt(9, book.getCopies());
    ps.setInt(10, book.getBookId());

    intStat = ps.executeUpdate();

    Connector.close();

    return intStat;
  }
Ejemplo n.º 2
0
 @Override
 public boolean checkoutBook(String memberId, String isbn) throws LibrarySystemException {
   Book currentBook = searchBook(isbn);
   BookCopy[] book = currentBook.getCopies();
   for (BookCopy bc : book) {
     if (computeStatus(bc)) {
       DataAccessFacade dc = new DataAccessFacade();
       LocalDate currentDate = LocalDate.now();
       LocalDate dueDate = currentDate.plusDays(bc.getBook().getMaxCheckoutLength());
       CheckoutRecordEntry newCheckoutRecordEntry =
           new CheckoutRecordEntry(currentDate, dueDate, bc);
       LibraryMember member = search(memberId);
       CheckoutRecord rc = member.getCheckoutRecord();
       if (rc.getCheckoutRecordEntries() == null) {
         List<CheckoutRecordEntry> entries = new ArrayList<>();
         entries.add(newCheckoutRecordEntry);
         member.getCheckoutRecord().setCheckoutRecordEntries(entries);
       } else {
         member.getCheckoutRecord().getCheckoutRecordEntries().add(newCheckoutRecordEntry);
       }
       bc.changeAvailability();
       dc.updateMember(member);
       dc.saveNewBook(currentBook);
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 3
0
  public static int addBook(Book book) throws Exception {
    int intStat = 0;

    if (null != book.getIsbn10()) {
      book.setIsbn13(IsbnUtil.convert(book.getIsbn10()));
    } else {
      book.setIsbn10(IsbnUtil.convert(book.getIsbn13()));
    }

    String sql =
        "INSERT INTO Books (ISBN10, ISBN13, Title, Author, "
            + "Edition, Publisher, Description, YearPublish, "
            + "Copies) VALUES (?,?,?,?,?,?,?,?,?)";

    PreparedStatement ps = Connector.getConnection().prepareStatement(sql);
    ps.setString(1, book.getIsbn10());
    ps.setString(2, book.getIsbn13());
    ps.setString(3, book.getTitle());
    ps.setString(4, book.getAuthor());
    ps.setString(5, book.getEdition());
    ps.setString(6, book.getPublisher());
    ps.setString(7, book.getDescription());
    ps.setInt(8, book.getYearPublish());
    ps.setInt(9, book.getCopies());

    intStat = ps.executeUpdate();

    Connector.close();

    return intStat;
  }
Ejemplo n.º 4
0
  public boolean availableForCheckout(String memberId, String isbn) throws LibrarySystemException {

    if (search(memberId) != null) {
      if (searchBook(isbn) != null) {
        Book currentBook = searchBook(isbn);
        BookCopy[] book = currentBook.getCopies();
        for (BookCopy bc : book) {
          if (computeStatus(bc)) {
            return true;
          }
        }
        throw new LibrarySystemException(
            "No book copy with isbn " + isbn + " is in the library collection!");
      } else {
        throw new LibrarySystemException(
            "No book with isbn " + isbn + " is in the library collection!");
      }
    } else {
      throw new LibrarySystemException(
          "No member with id " + memberId + " is in the library system!");
    }
  }