Heavily refactored DatabaseManager.java and SimpleDatabaseManager.java. Fully refactored DatabaseGoodCasesTest.java and DatabaseBadCasesTest.java.

This commit is contained in:
Riley Schneider
2025-12-08 17:50:21 +01:00
parent 292d6c74c3
commit e9b2ad0a57
5 changed files with 254 additions and 225 deletions

View File

@@ -1,16 +1,115 @@
package hhn.temp.project.provider;
import jdk.jshell.spi.ExecutionControl;
import hhn.temp.project.Task;
import hhn.temp.project.Worker;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Collection;
public interface DatabaseManager<E> extends Database {
public void saveObjects(Collection<E> objects) throws SQLException;
public Collection<E> getObjects() throws SQLException;
public void saveObject(E object) throws SQLException;
public E getObject(int taskId) throws SQLException;
public void deleteObject(int taskId) throws SQLException;
public E updateObject(int taskId, E object) throws SQLException;
/**
* Simple Database Manager to handle simple command such as insertion, deletion, updating of Task and Worker objects.
* @author Riley Schneider
*/
public interface DatabaseManager extends Database {
/**
* Saves a Task object into the database
* @param task Task to be saved into the database
* @throws SQLException Thrown if database error occurs
*/
void saveTask(Task task) throws SQLException;
/**
* Saves a collection of Task objects into the database
* @param tasks Tasks to be saved into the database
* @throws SQLException Thrown if database error occurs
*/
void saveTasks(Collection<Task> tasks) throws SQLException;
/**
* Saves a Worker object into the database
* @param worker Worker to be saved into the database
* @throws SQLException Thrown if database error occurs
*/
void saveWorker(Worker worker) throws SQLException;
/**
* Saves a collection Worker objects into the database
* @param workers Workers to be saved into the database
* @throws SQLException Thrown if database error occurs
*/
void saveWorkers(Collection<Worker> workers) throws SQLException;
/**
* Updates a Task object that already exists in the database
* @param taskId The ID of the given task
* @param newTaskObject The new Task object that will overwrite the existent task on database
* @throws SQLException Thrown if database error occurs
*/
void updateTask(int taskId, Task newTaskObject) throws SQLException;
/**
* Updates a Worker object that already exists in the database
* @param workerId The ID of the given worker
* @param newWorkerObject The new Worker object that will overwrite the existent task on database
* @throws SQLException Thrown if database error occurs
*/
void updateWorker(int workerId, Worker newWorkerObject) throws SQLException;
/**
* Deletes a task from the database
* @param taskId The ID of the given task that needs to be deleted
* @throws SQLException Thrown if database error occurs
*/
void deleteTask(int taskId) throws SQLException;
/**
* Deletes a worker from the database
* @param workerId The ID of the given worker that needs to be deleted
* @throws SQLException Thrown if database error occurs
*/
void deleteWorker(int workerId) throws SQLException;
/**
* Gets a collection of all tasks available in the database
* @return A collection of tasks (empty if no task available)
* @throws SQLException Thrown if database error occurs
*/
Collection<Task> getTasks() throws SQLException;
/**
* Gets a collection of all workers available in the database
* @return A collection of workers (empty if no task available)
* @throws SQLException Thrown if database error occurs
*/
Collection<Worker> getWorkers() throws SQLException;
/**
* Gets a task given by its ID from the database
* @param taskId The task ID
* @return A task from the database (NULL if no task found)
* @throws SQLException Thrown if database error occurs
*/
Task getTaskByTaskId(int taskId) throws SQLException;
/**
* Gets a worker given by its ID from the database
* @param workerId The worker ID
* @return A worker from the database (NULL if no worker found)
* @throws SQLException Thrown if database error occurs
*/
Worker getWorkerByWorkerId(int workerId) throws SQLException;
/**
* Gets the total number of available tasks in the database.
* @return The total number of tasks (0 = zero entries; -1 = error)
* @throws SQLException Thrown if database error occurs
*/
int getTotalNumberOfTasks() throws SQLException;
/**
* Gets the total number of available workers in the database.
* @return The total number of workers (0 = zero entries; -1 = error)
* @throws SQLException Thrown if database error occurs
*/
int getTotalNumberOfWorkers() throws SQLException;
}