Package com.jcasey.model

Examples of com.jcasey.model.Book


  }
 
  public Book deleteBook(Long id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();
    Book book = (Book) session.load(Book.class, id);
    if(null != book) {
      session.delete(book);
    }
    session.getTransaction().commit();
    return book;
View Full Code Here


    controller = new Manager();
  }
 
  public String add()
  {
    Book book = new Book();
   
    book.setAuthor(author);
    book.setTitle(title);
    book.setBlurb(blurb);
    book.setIsbn(isbn);
   
    //TODO split incoming data up based on commas
   
    List <BookGenre> mapping = new LinkedList <BookGenre>();
   
    //TODO delete any previous mappings - and recreate them later (yes a little bit nasty).
   
    controller.addBook(book); // save the book record
   
    //TODO save mapping between book and genre
    for(BookGenre bookGenre: book.getBookGenre())
    {
      controller.addBookGenre(bookGenre);
    }
   
    return Action.SUCCESS;
View Full Code Here

    return Action.SUCCESS;
  }
 
  public String delete()
  {
    Book book = controller.getBook(getBookId());
   
    //TODO delete the dependent objects first   
    //TODO delete the primary book record

    return Action.SUCCESS;
View Full Code Here

  }
 
  public String update()
  {
    // get the current book
    Book book = controller.getBook(getBookId());
   
    // update the book setters based on new form data
    book.setAuthor(author);
   
    //TODO split incoming data up based on commas
    String genreData[] = StringUtils.split(genre, ",");
   
    if(genreData.length >0)
    {
      //TODO delete associations - a bit of a nasty way to do things...
   
    }
    List <BookGenre> mapping = new LinkedList <BookGenre>();
    final LinkedList <Genre> genres = controller.listGenres(); // get a list of genres already in the database
   
   
    // actually update the book using the linkController
    controller.update(book);
   
    // save mapping between book and genre
    for(BookGenre bookGenre: book.getBookGenre())
    {
      controller.addBookGenre(bookGenre);
    }
   
    return "success";
View Full Code Here

    return "success";
  }
 
  public String execute()
  {
    Book book = controller.getBook(getBookId());
   
    if(book !=  null)
    {
      this.author = book.getAuthor();
      this.title = book.getTitle();

      bookGenre = book.getBookGenre();
     
      //TODO split genre data up for the view
      for(BookGenre data: bookGenre)
      {

      }
     
      this.blurb = book.getBlurb();
      this.isbn = book.getIsbn();
     
      return "update";
    }
    else
    {
View Full Code Here

    controller = new Manager();
  }
 
  public String add()
  {
    Book book = new Book();
   
    book.setAuthor(author);
    book.setTitle(title);
    book.setBlurb(blurb);
   
    // split incoming data up based on commas
    String genreData[] = StringUtils.split(genre, ",");
   
    List <BookGenre> association = new LinkedList <BookGenre>();
   
    final LinkedList <Genre> genres = controller.listGenres(); // get a list of genres already in the database
   
    for(String data: genreData)
    {
      if(StringUtils.isNotBlank(StringUtils.trimToEmpty(data)))
      {
        Genre newGenre = new Genre();
        newGenre.setGenre(data);
       
        if (!genres.contains(newGenre)) // is this a new genre?
        {
          controller.addGenre(newGenre)
        }
        else
        {
          int idx = genres.indexOf(newGenre);
          newGenre = genres.get(idx);
        }
       
        BookGenre bookGenre = new BookGenre(); // setup the associative entity
       
        bookGenre.setGenre(newGenre);
        bookGenre.setBook(book);
       
        association.add(bookGenre);
      }
    }
   
    book.setBookGenre(association);
    book.setIsbn(isbn);
    controller.addBook(book); // save the book record
   
    // save mapping between book and genre
    for(BookGenre bookGenre: association)
    {
View Full Code Here

    return Action.SUCCESS;
  }
 
  public String delete()
  {
    Book book = controller.getBook(getBookId());
   
    // delete the dependent objects first

    for(BookGenre bookGenre: book.getBookGenre())
    {
     
      controller.deleteBookGenre(bookGenre.getId());
    }
   
    // delete the primary book record
    controller.deleteBook(book.getBookId());
    return Action.SUCCESS;
  }
View Full Code Here

  }
 
  public String update()
  {
    // get the current book
    Book book = controller.getBook(getBookId());
   
    // update the book setters based on new form data
    book.setAuthor(author);

    // split incoming data up based on commas
      String genreData[] = StringUtils.split(genre, ",");
     
      if(genreData.length >0)
      {
        // delete associations - a bit of a nasty way to do things...
        for(BookGenre bookGenre: book.getBookGenre())
        {
          controller.deleteBookGenre(bookGenre.getId());
        }
    }
    List <BookGenre> mapping = new LinkedList <BookGenre>();
    final LinkedList <Genre> genres = controller.listGenres(); // get a list of genres already in the database
   
   
    for(String data: genreData)
    {
      if(StringUtils.isNotBlank(StringUtils.trimToEmpty(data)))
        {
        Genre newGenre = new Genre();
        newGenre.setGenre(data);

        if (!genres.contains(newGenre)) // is this a new genre?
        {
          controller.addGenre(newGenre)
        }
        else
        {
          int idx = genres.indexOf(newGenre);
          newGenre = genres.get(idx);
        }
         
        BookGenre bookGenre = new BookGenre(); // setup the associative entity
       
        bookGenre.setGenre(newGenre);
          bookGenre.setBook(book);
         
        mapping.add(bookGenre);
      }
    }
   
    book.setBookGenre(mapping);
   
    // save mapping between book and genre
    for(BookGenre bookGenre: book.getBookGenre())
    {
      controller.addBookGenre(bookGenre);
    }
   
    // actually update the book using the linkController
View Full Code Here

    return "success";
  }
 
  public String execute()
  {
    Book book = controller.getBook(getBookId());
   
    if(book !=  null)
    {
      this.author = book.getAuthor();
      this.title = book.getTitle();

      bookGenre = book.getBookGenre();
     
      for(BookGenre data: bookGenre)
      {
        genre = genre + data.getGenre().getGenre() + ",";
      }
     
      this.blurb = book.getBlurb();
      this.isbn = book.getIsbn();
     
      return "update";
    }
    else
    {
View Full Code Here

    controller = new Manager();
  }
 
  public String add()
  {
    Book book = new Book();
   
    book.setAuthor(author);
    book.setTitle(title);
    book.setBlurb(blurb);
   
    // split incoming data up based on commas
    String genreData[] = StringUtils.split(genre, ",");
   
    List <BookGenre> mapping = new LinkedList <BookGenre>();
    final LinkedList <Genre> genres = controller.listGenres(); // get a list of genres already in the database
   
    for(String data: genreData)
    {
      if(StringUtils.isNotBlank(StringUtils.trimToEmpty(data)))
      {
        Genre newGenre = new Genre();
        newGenre.setGenre(data);
       
        if (!genres.contains(newGenre)) // is this a new genre?
        {
          controller.addGenre(newGenre)
        }
        else
        {
          int idx = genres.indexOf(newGenre);
          newGenre = genres.get(idx);
        }
       
        BookGenre bookGenre = new BookGenre(); // setup the associative entity
       
        bookGenre.setGenre(newGenre);
        bookGenre.setBook(book);
       
        mapping.add(bookGenre);
      }
    }
   
    book.setBookGenre(mapping);
    book.setIsbn(isbn);
   
    controller.addBook(book); // save the book record
   
    // save mapping between book and genre
    for(BookGenre bookGenre: book.getBookGenre())
    {
      controller.addBookGenre(bookGenre);
    }
   
    return Action.SUCCESS;
View Full Code Here

TOP

Related Classes of com.jcasey.model.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.