Package my.edu.tarc.dco.bookrentalpos
Class 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 booleanadd(Book book)Add new book entry to the databaseintgetBookCount()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 0ArrayList<Book>getBooksRentedByMember(Member mem)This function returns an array list of reference to the books record where it is currently rented by specifed memberBookgetById(int bookID)Get the reference to the book object with specified IDBookgetByName(String name)Get the reference to the book object with specified NameBook[]getCache()Get a copy of the booklist array
For now, you should use BookManager.getBookCount() to get the array sizevoidreload()Reload all the data from databasebooleanremove(Book book)Remove the book from the database
NOTE: All the related table will have this book removed as wellbooleanupdate(Book bk)Update the book entry into database
-
Constructor Details
-
Method Details
-
reload
public void reload()Reload all the data from database -
getById
Get the reference to the book object with specified ID -
getByName
Get the reference to the book object with specified Name -
getCache
Get a copy of the booklist array
For now, you should use BookManager.getBookCount() to get the array size- Specified by:
getCachein classManager<Book>- Returns:
- Book array with constant size of ARRAY_SIZE
- See Also:
getBookCount(),ARRAY_SIZE
-
add
Add new book entry to the database- Specified by:
addin classManager<Book>- Parameters:
book- Book object (without ID)- Returns:
- True if the book is added to database successfully
- See Also:
Book(String, String, double)
-
update
Update the book entry into database -
remove
Remove the book from the database
NOTE: All the related table will have this book removed as well -
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
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
-