Ejemplo n.º 1
0
 public BookLending lendBook(Book book, Customer customer) {
   BookLending bookLending = new BookLending();
   bookLending.setBook(book);
   bookLending.setCustomer(customer);
   bookLending.setLendingDate(new GregorianCalendar().getTime());
   bookLending.setBookIsLended(true);
   em.persist(bookLending);
   return bookLending;
 }
Ejemplo n.º 2
0
 public BookLending returnBook(Book book, Customer customer) {
   Query query = em.createNamedQuery("findLendingByCustomerAndBookId");
   query.setParameter("book", book);
   query.setParameter("customer", customer);
   List<BookLending> bookLendings = query.getResultList();
   if (bookLendings.isEmpty()) return null;
   BookLending bookLending = (BookLending) bookLendings.get(0);
   bookLending.setBookIsLended(false);
   bookLending.setReturnDate(new GregorianCalendar().getTime());
   em.persist(bookLending);
   return bookLending;
 }