Class BookManager

java.lang.Object
my.edu.tarc.dco.bookrentalpos.Manager<Book>
my.edu.tarc.dco.bookrentalpos.BookManager

public class BookManager
extends Manager<Book>
Class used to load all the Book data from the database
Version:
1.0
Author:
Looz
  • Constructor Summary

    Constructors 
    Constructor Description
    BookManager​(DBManager db)  
  • Method Summary

    Modifier and Type Method Description
    boolean add​(Book book)
    Add new book entry to the database
    int getBookCount()  
    ArrayList<_StockLevelReportTableData> getBookCountInSystem()
    This function returns an arraylist of stockLevelReportTableData
    The idea of this method: I abused the fact that COUNT() only returns the count of not null values.
    So, to actually count the number of rented books, all i have to do is temporary set those not rented books(marked as 0) to null and then execute the query
    After the function ends, the query will update null values back to 0
    ArrayList<Book> getBooksRentedByMember​(Member mem)
    This function returns an array list of reference to the books record where it is currently rented by specifed member
    Book getById​(int bookID)
    Get the reference to the book object with specified ID
    Book getByName​(String name)
    Get the reference to the book object with specified Name
    Book[] getCache()
    Get a copy of the booklist array
    For now, you should use BookManager.getBookCount() to get the array size
    void reload()
    Reload all the data from database
    boolean remove​(Book book)
    Remove the book from the database
    NOTE: All the related table will have this book removed as well
    boolean update​(Book bk)
    Update the book entry into database

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • reload

      public void reload()
      Reload all the data from database
      Specified by:
      reload in class Manager<Book>
    • getById

      public Book getById​(int bookID)
      Get the reference to the book object with specified ID
      Specified by:
      getById in class Manager<Book>
      Returns:
      Reference to the book object in this class. Will return null if book of specified ID was not found
    • getByName

      public Book getByName​(String name)
      Get the reference to the book object with specified Name
      Specified by:
      getByName in class Manager<Book>
      Returns:
      Reference to the book object in this class. Will return null if book of specified Name was not found
    • getCache

      public Book[] getCache()
      Get a copy of the booklist array
      For now, you should use BookManager.getBookCount() to get the array size
      Specified by:
      getCache in class Manager<Book>
      Returns:
      Book array with constant size of ARRAY_SIZE
      See Also:
      getBookCount(), ARRAY_SIZE
    • add

      public boolean add​(Book book)
      Add new book entry to the database
      Specified by:
      add in class Manager<Book>
      Parameters:
      book - Book object (without ID)
      Returns:
      True if the book is added to database successfully
      See Also:
      Book(String, String, double)
    • update

      public boolean update​(Book bk)
      Update the book entry into database
      Specified by:
      update in class Manager<Book>
      Parameters:
      bk - Book Object to be updated (must contain ID)
      Returns:
      True if the book is successfuly updated. Will return false if it failed or the provided Book object dont contain ID
    • remove

      public boolean remove​(Book book)
      Remove the book from the database
      NOTE: All the related table will have this book removed as well
      Specified by:
      remove in class Manager<Book>
      Parameters:
      book - BookID to be removed
      Returns:
      True if the book is removed successfully
    • getBookCountInSystem

      public ArrayList<_StockLevelReportTableData> getBookCountInSystem()
      This function returns an arraylist of stockLevelReportTableData
      The idea of this method: I abused the fact that COUNT() only returns the count of not null values.
      So, to actually count the number of rented books, all i have to do is temporary set those not rented books(marked as 0) to null and then execute the query
      After the function ends, the query will update null values back to 0
      Returns:
      Arraylist of type _stockLevelReportTableData
    • getBooksRentedByMember

      public ArrayList<Book> getBooksRentedByMember​(Member mem)
      This function returns an array list of reference to the books record where it is currently rented by specifed member
      Parameters:
      mem - member object
      Returns:
      arraylist of type Book
    • getBookCount

      public int getBookCount()
      Returns:
      Book count loaded into this instance from database