Package org.conserve.objects

Examples of org.conserve.objects.Author


   */
  @Test
  public void testAuthorBookSimple() throws Exception
  {
    // create one author
    Author asimov = new Author();
    asimov.setBirthYear(1920);
    asimov.setFirstName("Isaac");
    asimov.setLastName("Asimov");

    // create some books
    Book foundation = new Book("Foundation");
    foundation.setPublishedYear(1951);
    foundation.addKeyWord("science fiction");
    foundation.addKeyWord("psychohistory");
    asimov.addBook(foundation);
    Book cavesofsteel = new Book("The Caves of Steel");
    cavesofsteel.setPublishedYear(1954);
    cavesofsteel.addKeyWord("science fiction");
    cavesofsteel.addKeyWord("robot");
    cavesofsteel.addKeyWord("crime");
    asimov.addBook(cavesofsteel);

    // save everything
    PersistenceManager persist = new PersistenceManager(driver, database, login, password);
    persist.saveObject(asimov);
    persist.close();

    // open a new connection
    persist = new PersistenceManager(driver, database, login, password);

    // find all books with the authors last name 'Asimov'.
    asimov = new Author();
    asimov.setLastName("Asimov");
    Book seekBook = new Book();
    seekBook.addAuthor(asimov);
    List<Book> asimovBooks = persist.getObjects(Book.class, new Equal(seekBook));
    assertEquals(2, asimovBooks.size());
    // print the title of the scifi books
View Full Code Here


  private void createAuthors() throws SQLException
  {

    // create some authors
    Author dickens = new Author();
    dickens.setBirthYear(1812);
    dickens.setFirstName("Charles");
    dickens.setLastName("Dickens");
    Author asimov = new Author();
    asimov.setBirthYear(1920);
    asimov.setFirstName("Isaac");
    asimov.setLastName("Asimov");
    Author verne = new Author();
    verne.setBirthYear(1828);
    verne.setFirstName("Jules");
    verne.setLastName("Verne");

    // create some books
    Book twocities = new Book("A Tale of Two Cities");
    twocities.setPublishedYear(1859);
    twocities.addKeyWord("London");
    twocities.addKeyWord("Paris");
    twocities.addKeyWord("revolution");
    dickens.addBook(twocities);
    Book olivertwist = new Book("Oliver Twist");
    olivertwist.setPublishedYear(1838);
    olivertwist.addKeyWord("crime");
    olivertwist.addKeyWord("London");
    dickens.addBook(olivertwist);
    Book foundation = new Book("Foundation");
    foundation.setPublishedYear(1951);
    foundation.addKeyWord("science fiction");
    foundation.addKeyWord("psychohistory");
    asimov.addBook(foundation);
    Book cavesofsteel = new Book("The Caves of Steel");
    cavesofsteel.setPublishedYear(1954);
    cavesofsteel.addKeyWord("science fiction");
    cavesofsteel.addKeyWord("robot");
    cavesofsteel.addKeyWord("crime");
    asimov.addBook(cavesofsteel);
    Book centerofearth = new Book("A Journey to the Center of the Earth");
    centerofearth.setPublishedYear(1864);
    centerofearth.addKeyWord("science fiction");
    centerofearth.addKeyWord("cave");
    verne.addBook(centerofearth);
    Book leagues = new Book("Twenty Thousand Leagues under the Sea");
    leagues.setPublishedYear(1869);
    leagues.addKeyWord("science fiction");
    leagues.addKeyWord("submarine");
    leagues.addKeyWord("ocean");
    verne.addBook(leagues);

    // save everything
    PersistenceManager persist = new PersistenceManager(driver, database, login, password);
    persist.saveObject(dickens);
    persist.saveObject(asimov);
View Full Code Here

    {
      System.out.println(book.getTitle());
    }

    // find all authors with the first name 'Isaac'.
    Author asimov = new Author();
    asimov.setFirstName("Isaac");
    List<Author> asimovAuthors = persist.getObjects(Author.class, new Equal(asimov));
    assertEquals(1, asimovAuthors.size());

    persist.close();
  }
View Full Code Here

TOP

Related Classes of org.conserve.objects.Author

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.