예제 #1
0
  @Override
  public Book updateBook(Book book) {
    Document original = __wrapper.getDocument();
    Document doc = __wrapper.getDocument();

    try {
      Map<String, String> values = new HashMap<String, String>();
      values.put("isbn", book.getIsbn());
      values.put("publisher", book.getPublisher());
      values.put("title", book.getTitle());
      values.put("year", book.getYear() + "");
      values.put("authorIds", Utility.getInstance().join(",", book.getAuthorIds()));

      doc = __wrapper.updateEntry(doc, values, "isbn", book.getIsbn());
      __wrapper.commit(doc);
    } catch (Exception e) {
      e.printStackTrace();
      __wrapper.rollback(original);
      return null;
    }
    return book;
  }
예제 #2
0
 @Override
 public boolean deleteBook(Book book) {
   Document original = __wrapper.getDocument();
   Document doc = __wrapper.getDocument();
   try {
     doc = __wrapper.deleteEntry(doc, "isbn", book.getIsbn());
     if (doc == null) {
       return false;
     } else {
       __wrapper.commit(doc);
       return true;
     }
   } catch (Exception e) {
     e.printStackTrace();
     __wrapper.rollback(original);
     return false;
   }
 }