java.lang.Object
com.example.cab302project.SqliteDAO
- All Implemented Interfaces:
IAppDAO
SQLite-based implementation of the
IAppDAO interface.
This class handles all persistent data storage for the application using an
embedded SQLite database. It manages table creation, data mapping, and CRUD
operations for users and crime records.
The database connection is managed via the SqliteConnection singleton.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddCrime(CrimeRecord crime) Records a new crime incident in the data store.booleanPersists a new user in the data store.booleandeleteCrime(int id) Removes a crime record from the data store based on its unique identifier.Retrieves every crime record currently stored in the system.getCrimeById(int id) Retrieves a specific crime record by its unique identifier.getCrimesByUser(String username) Retrieves all crime incidents reported by a specific user.booleanupdateCrime(CrimeRecord crime) Updates the details of an existing crime record.booleanupdateUser(User user) Updates an existing user's information in the data store.validateUser(String username, String plaintextPassword) Validates a user's credentials against the data store.
-
Constructor Details
-
SqliteDAO
public SqliteDAO()Initializes the SQLite DAO. Establishes a connection to the database and ensures that the required 'users' and 'crimes' tables exist.
-
-
Method Details
-
validateUser
Validates a user's credentials against the data store. Typically used during the login process to verify identity.- Specified by:
validateUserin interfaceIAppDAO- Parameters:
username- The unique username to validate.plaintextPassword- The password provided for validation.- Returns:
- A
Userobject if credentials are correct; null if validation fails.
-
addUser
Persists a new user in the data store. -
updateUser
Updates an existing user's information in the data store.- Specified by:
updateUserin interfaceIAppDAO- Parameters:
user- TheUserobject containing the updated profile data.- Returns:
- true if the update was successful; false otherwise.
-
addCrime
Records a new crime incident in the data store.- Specified by:
addCrimein interfaceIAppDAO- Parameters:
crime- TheCrimeRecordobject containing the incident details.- Returns:
- true if the record was successfully created; false if an error occurred.
-
updateCrime
Updates the details of an existing crime record.- Specified by:
updateCrimein interfaceIAppDAO- Parameters:
crime- TheCrimeRecordobject containing the updated incident data.- Returns:
- true if the record was found and updated successfully; false otherwise.
-
deleteCrime
public boolean deleteCrime(int id) Removes a crime record from the data store based on its unique identifier.- Specified by:
deleteCrimein interfaceIAppDAO- Parameters:
id- The unique primary key of the crime record to be removed.- Returns:
- true if the record was deleted; false if the ID was not found or an error occurred.
-
getCrimeById
Retrieves a specific crime record by its unique identifier.- Specified by:
getCrimeByIdin interfaceIAppDAO- Parameters:
id- The unique primary key of the desired crime.- Returns:
- The
CrimeRecordmatching the ID, or null if no such record exists.
-
getCrimesByUser
Retrieves all crime incidents reported by a specific user.- Specified by:
getCrimesByUserin interfaceIAppDAO- Parameters:
username- The username of the reporter to filter by.- Returns:
- A
ListofCrimeRecordobjects; returns an empty list if the user has no reports.
-
getAllCrimes
Retrieves every crime record currently stored in the system.- Specified by:
getAllCrimesin interfaceIAppDAO- Returns:
- A
Listcontaining allCrimeRecordobjects in the data store.
-