Class IdGenerator
This class provides thread-safe generation of unique, sequential identifiers for various entities in the BTO Management System. Each ID consists of a entity-specific prefix followed by a zero-padded sequential number.
The class maintains separate counters for each entity type and ensures that IDs remain unique across application restarts by examining existing IDs in the repositories during initialization.
IMPORTANT: The initialize() method MUST be called once at application startup AFTER data repositories have been loaded to ensure ID uniqueness across restarts.
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
Generates a new unique application ID.static String
Generates a new unique booking ID.static String
Generates a new unique enquiry ID.static String
Generates a new unique flat information ID.static String
Generates a new unique officer registration ID.static String
Generates a new unique project ID.static void
initialise
(IProjectRepository projectRepo, IApplicationRepository applicationRepo, IBookingRepository bookingRepo, IEnquiryRepository enquiryRepo, IOfficerRegistrationRepository registrationRepo) Initialises the ID counters by scanning existing IDs from loaded repositories.
-
Method Details
-
initialise
public static void initialise(IProjectRepository projectRepo, IApplicationRepository applicationRepo, IBookingRepository bookingRepo, IEnquiryRepository enquiryRepo, IOfficerRegistrationRepository registrationRepo) Initialises the ID counters by scanning existing IDs from loaded repositories.This method examines all existing IDs in the provided repositories and sets each ID counter to one more than the highest existing ID of that type. This ensures that new IDs will not collide with existing ones, even after application restarts.
This MUST be called once at startup after repositories are loaded to ensure uniqueness across application executions.
- Parameters:
projectRepo
- Loaded IProjectRepository containing existing project IDsapplicationRepo
- Loaded IApplicationRepository containing existing application IDsbookingRepo
- Loaded IBookingRepository containing existing booking IDsenquiryRepo
- Loaded IEnquiryRepository containing existing enquiry IDsregistrationRepo
- Loaded IOfficerRegistrationRepository containing existing registration IDs
-
generateApplicationId
Generates a new unique application ID.The ID consists of the prefix "APP" followed by a zero-padded sequential number. This method is thread-safe and atomically increments the counter.
- Returns:
- A new unique application ID string (e.g., "APP001", "APP002")
-
generateBookingId
Generates a new unique booking ID.The ID consists of the prefix "BOOK" followed by a zero-padded sequential number. This method is thread-safe and atomically increments the counter.
- Returns:
- A new unique booking ID string (e.g., "BOOK001", "BOOK002")
-
generateEnquiryId
Generates a new unique enquiry ID.The ID consists of the prefix "ENQ" followed by a zero-padded sequential number. This method is thread-safe and atomically increments the counter.
- Returns:
- A new unique enquiry ID string (e.g., "ENQ001", "ENQ002")
-
generateOfficerRegId
Generates a new unique officer registration ID.The ID consists of the prefix "REG" followed by a zero-padded sequential number. This method is thread-safe and atomically increments the counter.
- Returns:
- A new unique registration ID string (e.g., "REG001", "REG002")
-
generateProjectId
Generates a new unique project ID.The ID consists of the prefix "PROJ" followed by a zero-padded sequential number. This method is thread-safe and atomically increments the counter.
- Returns:
- A new unique project ID string (e.g., "PROJ001", "PROJ002")
-
generateFlatInfoId
Generates a new unique flat information ID.The ID consists of the prefix "FLAT" followed by a zero-padded sequential number. This method is thread-safe and atomically increments the counter.
- Returns:
- A new unique flat information ID string (e.g., "FLAT001", "FLAT002")
-