mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-05-13 09:45:56 +00:00
Validate H2 Database Type and URL Consistency for Custom Databases (#3458)
# Description of Changes Please provide a summary of the changes, including: - **What was changed** Introduced a local `isCustomDatabase` flag (based on `datasource.isEnableCustomDatabase()`) to ensure that the H2-specific URL/type consistency checks (and corresponding warnings/exceptions) only run when a custom database configuration is enabled. Refactored the return statement to use this flag (`return !isCustomDatabase || isH2;`) instead of calling `isEnableCustomDatabase()` directly. - **Why the change was made** Previously, even when custom database support was disabled, the method would still validate H2 configuration and potentially throw an `IllegalStateException`. By guarding those checks, we avoid spurious warnings or exceptions in default (non-custom) setups and make the method’s behavior more predictable. --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details.
This commit is contained in:
parent
d95f169ebd
commit
aef64cd7cc
@ -246,26 +246,28 @@ public class DatabaseService implements DatabaseInterface {
|
|||||||
boolean isDBUrlH2 =
|
boolean isDBUrlH2 =
|
||||||
datasource.getCustomDatabaseUrl().contains("h2")
|
datasource.getCustomDatabaseUrl().contains("h2")
|
||||||
|| datasource.getCustomDatabaseUrl().contains("H2");
|
|| datasource.getCustomDatabaseUrl().contains("H2");
|
||||||
|
boolean isCustomDatabase = datasource.isEnableCustomDatabase();
|
||||||
|
|
||||||
if (isTypeH2 && !isDBUrlH2) {
|
if (isCustomDatabase) {
|
||||||
log.warn(
|
if (isTypeH2 && !isDBUrlH2) {
|
||||||
"Datasource type is H2, but the URL does not contain 'h2'. "
|
log.warn(
|
||||||
+ "Please check your configuration.");
|
"Datasource type is H2, but the URL does not contain 'h2'. "
|
||||||
throw new IllegalStateException(
|
+ "Please check your configuration.");
|
||||||
"Datasource type is H2, but the URL does not contain 'h2'. Please check your"
|
throw new IllegalStateException(
|
||||||
+ " configuration.");
|
"Datasource type is H2, but the URL does not contain 'h2'. Please check"
|
||||||
} else if (!isTypeH2 && isDBUrlH2) {
|
+ " your configuration.");
|
||||||
log.warn(
|
} else if (!isTypeH2 && isDBUrlH2) {
|
||||||
"Datasource URL contains 'h2', but the type is not H2. "
|
log.warn(
|
||||||
+ "Please check your configuration.");
|
"Datasource URL contains 'h2', but the type is not H2. "
|
||||||
throw new IllegalStateException(
|
+ "Please check your configuration.");
|
||||||
"Datasource URL contains 'h2', but the type is not H2. Please check your"
|
throw new IllegalStateException(
|
||||||
+ " configuration.");
|
"Datasource URL contains 'h2', but the type is not H2. Please check your"
|
||||||
|
+ " configuration.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isH2 = isTypeH2 && isDBUrlH2;
|
boolean isH2 = isTypeH2 && isDBUrlH2;
|
||||||
|
|
||||||
return !datasource.isEnableCustomDatabase() || isH2;
|
return !isCustomDatabase || isH2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user