// UPDATE
  public void update(Author author) throws Exception {
    Query query = new Query();
    query.addCriteria(Criteria.where("_id").is(author.getAuthorId()));

    Update update = new Update();
    update.set("authorName", author.getAuthorName());

    // FindAndModifyOptions().returnNew(true) = newly updated document
    // FindAndModifyOptions().returnNew(false) = old document (not update yet)
    mongoOps.findAndModify(
        query, update, new FindAndModifyOptions().returnNew(true), Author.class, AUTHOR_COLLECTION);
  }
 /** *************************************************************************************** */
 public void DeleteAuthor(Author author) throws Exception {
   ConnectionUtil c = new ConnectionUtil();
   Connection conn = c.createConnection();
   try {
     if (author == null
         || author.getAuthorName() == null
         || author.getAuthorName().length() == 0
         || author.getAuthorName().length() > 45) {
       throw new Exception("The Author cannot be null");
     } else {
       AuthorDAO adao = new AuthorDAO(conn);
       adao.delete(author);
       conn.commit();
     }
   } catch (Exception e) {
     e.printStackTrace();
     conn.rollback();
   } finally {
     conn.close();
   }
 }
Esempio n. 3
0
 public void update(Author author) throws Exception {
   save(
       "update tbl_author set authorName = ? where authorId = ?",
       new Object[] {author.getAuthorName(), author.getAuthorId()});
 }
Esempio n. 4
0
 public void create(Author author) throws Exception {
   save("insert into tbl_author (authorName) values(?)", new Object[] {author.getAuthorName()});
 }