The Bookstore Problem
Contents I.Problem Description II.Solution III.Exercise
I. Problem Description ● Develop a GUI application that allows the user to – Search books if info about authors and publishers are given – Change prices of all books from a given publisher. Changing prices for all publishers at once is not allowed ● A sample GUI is given in the next slides
● A book has – A title, – An ISBN (International Standard Book Number), – A price – Info about its publisher, – Info about its author(s) ● A publisher has a name, a URL, and a list of books ● An author has a name, consisting of first name and last name, and the author writes one or more books – In each book, the author has an order of writing
Ex 1: A book is written by one author ● Title: The Mythical Man-Month ● ISBN: ● Price: $29.95 ● Publisher – Name: Addison-Wesley – URL: – Books:... ● Author – First name: Frederick P.; last name: Brooks – Order of authors: 1 – Books:...
Ex 2: A book is written by many authors ● Title: Design Patterns ● ISBN: ● Price: ● Publisher – Name: Addison-Wesley – URL: – Books:... ● Author – First name: Erich; last name: Gamma; Order of authors: 1 – First name: Richard; last name: Helm; Order of authors: 2 – First name: Ralph; last name: Johnson; Order of authors: 3 – First name: John; last name: Vlissides; Order of authors: 4
Ex 3: An author writes many books First name: Donald E.; last name: Knuth Order of authors : 1 Books – Title: The Art of Computer Programming vol. 1; ISBN: ; Price: – Title: The Art of Computer Programming vol. 2; ISBN: ; Price: – Title: The Art of Computer Programming vol. 3; ISBN: ; Price: 59.99
II. Solution 1.The 3-Tier Software Architecture 2.Developing the Data Tier 3.Developing the View 4.Developing Java Code
1. The 3-Tier Software Architecture Presentation Tier Data Tier Business Logic Tier Java Swing Logical Code + Data Manager RDBMS Data Manager
2. Developing the Data Tier 2.1. The Object Model 2.2. The Database Model 2.3. Creating the Database 2.4. Creating the Java Project 2.5 Creating a Connection Profile 2.6. Creating and Running SQL Scripts
2.1. The Object Model
2.2. The Database Model
2.3. Creating the Database ● Database Name: BOOKSTORE
2.4. Creating the Java Project ● File > New Project... ● New Java Project: Bookstore
2.5 Creating a Connection Profile
2.6. Creating and Running SQL Scripts
3. Developing the View
4. Developing Java Code 4.1. Adding the JDBC Driver JAR File to the Project's Libraries 4.2. Creating the Database Configuration File 4.3. Managing the Database Connection 4.4. Declaring a Data Manager to Interact to the Data Tier 4.5. Adding Author' names to the Author Combo Box 4.6. Adding Data to the Publisher Combo Box 4.7. Developing Action for the Query Button 4.8. Developing Action for the Change prices Button
4.1. Copying the JDBC Driver JAR File to the Project Folder ● JAR File: mysql-connector-java bin.jar ● In Eclipse – Create the lib folder: Right-click the project's root folder > New > Folder > Folder name: lib > Finish – Copy the JAR file to the lib folder – Right-click the JAR file > Build Path > Add to Build Path
4.2. Creating a Database Configuration File ● Right-click the project's root folder > New > File > File name: persistence.properties > Finish drivers=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/BOOKSTORE username=... password=...
4.3. Managing the Database Connection Developing a Utility to Create and Close a Database Connection Getting the Connection Closing the Connection When the Frame is Closed
Developing a Utility to Create and Close a Database Connection
Getting the Connection
Closing the Connection When the Frame is Closed
4.4. Declaring a Data Manager to Interact to the Data Tier
4.5. Adding Authors' Names to the Author Combo Box
4.6. Adding Data to the Publisher Combo Box
4.7. Developing Action for the Query Button Both Author and Publisher are “Any” Author is Specific and Publisher is “Any” Author is “Any” and Publisher is Specific Both Author and Publisher are Specific
Both Author and Publisher are “Any”
Author is Specific and Publisher is “Any”
Author is “Any” and Publisher is Specific
Both Author and Publisher are Specific
4.8. Developing Action for the Change Prices Button
III. Exercise ● Improve the application so that it can change prices of all books from a given author and a given publisher