@Override public List<CommentImpl> getComments(BookPOJO pojo) { try { return bTable.getComments(pojo); } catch (SQLException e) { Logger.getLogger(EmbeddedDB.class.getName()).log(Level.SEVERE, e.getMessage(), e); } return Collections.emptyList(); }
@Override public boolean addComment(BookPOJO book, String author, int rate, String content) { try { return bTable.insertComment(book, author, rate, content); } catch (SQLException e) { Logger.getLogger(EmbeddedDB.class.getName()).log(Level.SEVERE, e.getMessage(), e); } return false; }
@Override public int getBookRateNumber(BookPOJO book) { try { return bTable.getRateNumber(book); } catch (SQLException e) { Logger.getLogger(EmbeddedDB.class.getName()).log(Level.SEVERE, e.getMessage(), e); } return 0; }
@Override public List<BookPOJO> getBooksFromPastAndBorrowed(int nbYear, int limit) { try { return bTable.selectBookAddedAtLeast(getPreviousYears(nbYear), limit); } catch (SQLException e) { Logger.getLogger(EmbeddedDB.class.getName()).log(Level.SEVERE, e.getMessage(), e); } return Collections.emptyList(); }
@Override public boolean rateBook(BookPOJO book, UserPOJO user, int value) { try { return bTable.rate(user, book, value); } catch (SQLException e) { Logger.getLogger(EmbeddedDB.class.getName()).log(Level.SEVERE, e.getMessage(), e); } return false; }
@Override public float getBookRate(BookPOJO book) { try { return (float) bTable.getRate(book.getId()); } catch (SQLException e) { Logger.getLogger(EmbeddedDB.class.getName()).log(Level.SEVERE, e.getMessage(), e); } return 0f; }
@Override public boolean addToQueue(UserPOJO user, BookPOJO book) { try { return bTable.addToQueue(book, user); } catch (SQLException e) { Logger.getLogger(EmbeddedDB.class.getName()).log(Level.SEVERE, e.getMessage(), e); } return false; }
@Override public List<UserPOJO> getQueue(BookPOJO book, int limit) { try { return bTable.getQueue(book, limit); } catch (SQLException e) { Logger.getLogger(EmbeddedDB.class.getName()).log(Level.SEVERE, e.getMessage(), e); } return Collections.emptyList(); }
@Override public List<BookPOJO> getBookBestRate(int number) { try { return bTable.selectMostRated(number); } catch (SQLException e) { Logger.getLogger(EmbeddedDB.class.getName()).log(Level.SEVERE, e.getMessage(), e); } return Collections.emptyList(); }
@Override public List<BookPOJO> searchBookFromKeywords(String... keywords) { try { return bTable.search(keywords); } catch (SQLException e) { Logger.getLogger(EmbeddedDB.class.getName()).log(Level.SEVERE, e.getMessage(), e); } return Collections.emptyList(); }
@Override public boolean addBook(BookPOJO book) { try { return bTable.insert(book); } catch (SQLException e) { Logger.getLogger(EmbeddedDB.class.getName()).log(Level.SEVERE, e.getMessage(), e); } return false; }
@Override public List<BookPOJO> hasBookInWait(UserPOJO user) { try { return bTable.hasBookInWait(user); } catch (SQLException e) { Logger.getLogger(EmbeddedDB.class.getName()).log(Level.SEVERE, e.getMessage(), e); } return Collections.emptyList(); }
@Override public List<BookPOJO> getBookMostSimilar(BookPOJO book, int number) { try { return bTable.mostSimilar(book, number); } catch (SQLException e) { Logger.getLogger(EmbeddedDB.class.getName()).log(Level.SEVERE, e.getMessage(), e); } return Collections.emptyList(); }
@Override public boolean clear() { try { boolean bDelete = bTable.delete(); boolean uDelete = uTable.delete(); boolean cDelete = cTable.delete(); return bDelete && uDelete && cDelete; } catch (SQLException e) { Logger.getLogger(EmbeddedDB.class.getName()).log(Level.SEVERE, e.getMessage(), e); } return false; }
@Override public boolean borrow(BookPOJO book, UserPOJO user) { try { if (bTable.hasAlreadyBorrowed(book, user)) return false; // Book is not available. Add in queue if not if (!isAvailable(book)) { if (!bTable.isAlreadyInQueue(book, user)) addToQueue(user, book); return false; } return bTable.borrow(book, user); } catch (SQLException e) { Logger.getLogger(EmbeddedDB.class.getName()).log(Level.SEVERE, e.getMessage(), e); } return false; }