Package com.force.samples.entity

Examples of com.force.samples.entity.Book


   
    Author author = new Author();
    author.setFirstName("JRR");
    author.setLastName("Tolkein");

    Book hobbit = new Book();
    hobbit.setAuthor(author);
    hobbit.setTitle("The Hobbit");
    hobbit.setPublicationDate(new GregorianCalendar(1937, 11, 1).getTime());
    em.persist(hobbit);
   
    Book fotr = new Book();
    fotr.setAuthor(author);
    fotr.setTitle("Fellowship of the Ring");
    fotr.setPublicationDate(new GregorianCalendar(1954, 06, 24).getTime());
    em.persist(fotr);
   
    Book twoTowers = new Book();
    twoTowers.setAuthor(author);
    twoTowers.setTitle("The Two Towers");
    twoTowers.setPublicationDate(new GregorianCalendar(1954, 10, 11).getTime());
    em.persist(twoTowers);
   
    Book rotk = new Book();
    rotk.setAuthor(author);
    rotk.setTitle("Return of the King");
    rotk.setPublicationDate(new GregorianCalendar(1955, 9, 20).getTime());
    em.persist(rotk);
   
    Author rowling = new Author();
    rowling.setFirstName("J.K");
    rowling.setLastName("Rowling");
   
    Book hpps = new Book();
    hpps.setAuthor(rowling);
    hpps.setTitle("Harry Potter and the Philosophers Stone");
    hpps.setPublicationDate(new GregorianCalendar(1997, 5, 30).getTime());
    em.persist(hpps);
   
    Book hpcs = new Book();
    hpcs.setAuthor(rowling);
    hpcs.setTitle("Harry Potter and the Chamber of Secrets");
    hpcs.setPublicationDate(new GregorianCalendar(1998, 6, 2).getTime());
    em.persist(hpcs);
   
    Book hppa = new Book();
    hppa.setAuthor(rowling);
    hppa.setTitle("Harry Potter and the Prisoner of Azkaban");
    hppa.setPublicationDate(new GregorianCalendar(1999, 6, 8).getTime());
    em.persist(hppa);
  }
View Full Code Here


  @RequestMapping(method=RequestMethod.GET, value="/book/{bookId}")
  public @ResponseBody Book getBook (@PathVariable(value="bookId") long bookId, Model model) {
   
    log.info("Searching for book with id = " + bookId);
   
    Book book = bookDAO.getBookById(bookId);
    return book;
  }
View Full Code Here

   
    Author author = new Author();
    author.setFirstName("JRR");
    author.setLastName("Tolkein");

    Book book = new Book();
    book.setAuthor(author);
    book.setTitle("Fellowship of the Ring");
    book.setPublicationDate(new GregorianCalendar(1954, 06, 24).getTime());
   
    em.persist(book);
   
    tx.commit();
   
    // Now read it back and verify
    log.info("Reading back from database and verifying...");
    EntityTransaction readTx = em.getTransaction();
    readTx.begin();
   
    Book fellowship = em.find(Book.class, book.getId());
    Assert.assertNotNull(fellowship);
    Assert.assertEquals("Fellowship of the Ring", fellowship.getTitle());
    Assert.assertEquals("JRR", fellowship.getAuthor().getFirstName());
    Assert.assertEquals("Tolkein", fellowship.getAuthor().getLastName());
   
    readTx.commit();
   
    // Cleanup the entities
    log.info("Cleaning up created entity...");
    EntityTransaction delTx = em.getTransaction();
    delTx.begin();
   
    em.remove(fellowship);
    em.remove(fellowship.getAuthor());
   
    delTx.commit();
  }
View Full Code Here

TOP

Related Classes of com.force.samples.entity.Book

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.