Includes class design: Designs of the (public) Java classes that will comprise your programs:
- Descriptions of all public methods and fields.
- Descriptions of the arguments each method takes and what the method returns.
- Any assumptions (preconditions and postconditions).
- Any checked exceptions that may be thrown by the method, and the circumstances under which the exceptions will be thrown.
- How these classes interact with each other (UML Diagram).
These classes are used to interact with a database. Structure inspired by Week 7 Tutorial.
There are 4 categories of classes:
DBConnection
: Connects the server to a database schema.DataSource
: Executes prepared SQL statement to interact with database.Data
: Uses a DataSource and its methods to retrieve data.DataType
: Stores detailed information of certain objects.
Connects the server to a database schema.
DBConnection |
---|
-instance : Connection |
-DBConnection() + getInstance() : Connection |
private DBConnection()
- Reads from a config file to retrieve database information (url, username, password, schema).
- Uses DriverManager to connect to database & override
instance
.
getInstance()
- If there is no current
instance
, creates one. - Returns
instance
.
Executes prepared SQL statement to interact with database.
Base Class:
DataSource |
---|
+CREATE_TABLE : String - connection : Connection # INSERT : String # GET : String # DELETE : String # add : PreparedStatement # get : PreparedStatement # delete : PreparedStatement |
-DataSource() + add(DataType data) + get(Object key) + delete(Object key) + close() |
DataSource()
- Connects to database.
close()
- Close connection to database.
Each of the following classes extends the DataSource
class and should have at least 3 methods:
add(DataType data)
: Add a new row into the databaseget(Object key)
: Retrieve the row associated to the keydelete(Object key)
: Delete the row associated to the key
The classes below inherits DataSource
and can modify the SQL Strings (INSERT
, GET
, DELETE
) to adapt to each table.
UsersDataSource |
---|
OrganisationsDataSource |
---|
AssetsDataSource |
---|
OrdersDataSource |
---|
Uses a DataSource and its methods to retrieve data.
Stores detailed information of certain objects. These classes will also be used by the client, see Common_Classes Design.