Package MySTARS
Class Database
java.lang.Object
MySTARS.Database
public final class Database
extends java.lang.Object
The Class that interacts with the files and handles reading and writing of information.
- Since:
- 2020-11-1
- Version:
- 1.0
- Author:
- Bhargav
-
Field Summary
Fields Modifier and Type Field Description protected static java.util.HashMap<java.lang.String,Course>
COURSES
AHashmap<String, Course>
that stores allCourse
s and its contained information.protected static AccessLevel
CURRENT_ACCESS_LEVEL
The current AccessLevel of the currently logged in User.protected static User
CURRENT_USER
A User object that keeps track of the currently logged in User.private static java.lang.String
filePath
The path to the directory where the data files are stored.protected static java.util.HashMap<java.lang.String,java.lang.Object>
SETTINGS
AHashmap<String, Object>
that stores all Miscellaneous settings so that the application can return to its previous state after shutdown.protected static java.util.HashMap<java.lang.String,User>
USERS
AHashmap<String, User>
that stores allUser
s and their contained information. -
Constructor Summary
Constructors Modifier Constructor Description protected
Database()
The initialiser for the Database class. -
Method Summary
Modifier and Type Method Description protected static boolean
deserialise(FileType fileType)
Reads files into its respective Hashmap.private void
resetUsers()
Resets Admin users if they have been deleted.private void
restoreSettings()
Reads and restores key settings from file.protected static boolean
serialise(FileType fileType)
Writes Hashmaps into the respective files.
-
Field Details
-
filePath
private static java.lang.String filePathThe path to the directory where the data files are stored. -
COURSES
AHashmap<String, Course>
that stores allCourse
s and its contained information. -
USERS
AHashmap<String, User>
that stores allUser
s and their contained information. -
SETTINGS
protected static java.util.HashMap<java.lang.String,java.lang.Object> SETTINGSAHashmap<String, Object>
that stores all Miscellaneous settings so that the application can return to its previous state after shutdown. -
CURRENT_USER
A User object that keeps track of the currently logged in User. -
CURRENT_ACCESS_LEVEL
The current AccessLevel of the currently logged in User.
-
-
Constructor Details
-
Database
protected Database()The initialiser for the Database class. Reads Files on startup, resets key Admin Users if they have been deleted and retores all Application Settings from last close.
-
-
Method Details
-
deserialise
Reads files into its respective Hashmap.- Parameters:
fileType
- The type of file being read of typeFileType
.- Returns:
true
if successfully read file.
-
serialise
Writes Hashmaps into the respective files.- Parameters:
fileType
- The type of the file being written.- Returns:
true
if successfully wrote file.
-
resetUsers
private void resetUsers()Resets Admin users if they have been deleted. -
restoreSettings
private void restoreSettings()Reads and restores key settings from file.
-