Exemplo n.º 1
0
  @Override
  public Book createBook(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.createEntry(doc, values);
      __wrapper.commit(doc);
    } catch (Exception e) {
      e.printStackTrace();
      __wrapper.rollback(original);
      return null;
    }

    return book;
  }
Exemplo n.º 2
0
  // load initial settings
  static {
    try {
      Properties dbProperties = new Properties();
      dbProperties.load(
          AuthorDAORdbmsImpl.class.getClassLoader().getResourceAsStream("xml.properties"));

      String contextPath = System.getProperty("catalina.home");
      String relativePath = dbProperties.getProperty("relativePath");
      __fileName = contextPath + "/" + relativePath + "_book.xml";
      __wrapper = new XmlWrapper(__fileName, "book", Book.getAttributeNames());

    } catch (Throwable t) {
      t.printStackTrace();
    }
  }
Exemplo n.º 3
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;
   }
 }