-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Creates an abstract DataSource class to centralize common database configuration logic. - Removed duplicate code across different data source implementations. - Ensured that Logback initialization and Flyway migration setup are handled uniformly. - Improved maintainability and readability of the data source configuration.
- Loading branch information
Showing
7 changed files
with
98 additions
and
180 deletions.
There are no files selected for viewing
85 changes: 0 additions & 85 deletions
85
src/main/java/fr/softsf/sudokufx/utils/database/configuration/CdsDataSourceConfig.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/fr/softsf/sudokufx/utils/database/configuration/DataSourceCds.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package fr.softsf.sudokufx.utils.database.configuration; | ||
|
||
import com.zaxxer.hikari.HikariDataSource; | ||
import fr.softsf.sudokufx.annotations.ExcludedFromCoverageReportGenerated; | ||
import fr.softsf.sudokufx.utils.database.keystore.ApplicationKeystore; | ||
import org.springframework.context.annotation.*; | ||
|
||
import static fr.softsf.sudokufx.utils.MyEnums.Paths.DATABASE_NAME; | ||
|
||
/** | ||
* Overrides Abstract DataSource hikariDataSource for the CDS profile. | ||
* CDS optimizes the startup and memory management of the application without the JRE. | ||
*/ | ||
@Configuration | ||
@Profile("cds") | ||
@PropertySource("classpath:fr/softsf/sudokufx/application-cds.properties") | ||
@ExcludedFromCoverageReportGenerated | ||
public class DataSourceCds extends DataSource { | ||
@Bean | ||
@Override | ||
@DependsOn({"logbackInitialization"}) | ||
HikariDataSource hikariDataSource(final ApplicationKeystore keystore) { | ||
this.setJdbcUrl("jdbc:hsqldb:mem:" + DATABASE_NAME.getPath() + "CDS" + ";shutdown=true"); | ||
this.setPoolName("SudokuFXCDSHikariConnection"); | ||
return super.hikariDataSource(keystore); | ||
} | ||
} | ||
|
84 changes: 0 additions & 84 deletions
84
src/main/java/fr/softsf/sudokufx/utils/database/configuration/DataSourceConfig.java
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
src/main/java/fr/softsf/sudokufx/utils/database/configuration/DataSourceDefault.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package fr.softsf.sudokufx.utils.database.configuration; | ||
|
||
import com.zaxxer.hikari.HikariDataSource; | ||
import fr.softsf.sudokufx.annotations.ExcludedFromCoverageReportGenerated; | ||
import fr.softsf.sudokufx.utils.database.keystore.ApplicationKeystore; | ||
import fr.softsf.sudokufx.utils.os.OsFolderFactoryManager; | ||
import org.springframework.context.annotation.*; | ||
|
||
import static fr.softsf.sudokufx.utils.MyEnums.Paths.DATABASE_NAME; | ||
|
||
/** | ||
* Overrides Abstract DataSource hikariDataSource for the default profile. | ||
*/ | ||
@Configuration | ||
@Profile("default") | ||
@PropertySource("classpath:fr/softsf/sudokufx/application.properties") | ||
@ExcludedFromCoverageReportGenerated | ||
public class DataSourceDefault extends DataSource { | ||
@Bean | ||
@Override | ||
@DependsOn({"logbackInitialization"}) | ||
HikariDataSource hikariDataSource(final ApplicationKeystore keystore) { | ||
OsFolderFactoryManager osFolderFactoryManager = new OsFolderFactoryManager(); | ||
this.setJdbcUrl("jdbc:hsqldb:file:" + osFolderFactoryManager.osFolderFactory().getOsDataFolderPath() + "/" + DATABASE_NAME.getPath() + ";shutdown=true"); | ||
this.setPoolName("SudokuFXHikariConnection"); | ||
return super.hikariDataSource(keystore); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/fr/softsf/sudokufx/utils/database/configuration/DataSourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package fr.softsf.sudokufx.utils.database.configuration; | ||
|
||
import com.zaxxer.hikari.HikariDataSource; | ||
import fr.softsf.sudokufx.annotations.ExcludedFromCoverageReportGenerated; | ||
import fr.softsf.sudokufx.utils.database.keystore.ApplicationKeystore; | ||
import org.springframework.context.annotation.*; | ||
|
||
import static fr.softsf.sudokufx.utils.MyEnums.Paths.DATABASE_NAME; | ||
|
||
/** | ||
* Overrides Abstract DataSource hikariDataSource for the test profile. | ||
*/ | ||
@Configuration | ||
@Profile("test") | ||
@PropertySource("classpath:application-test.properties") | ||
@ExcludedFromCoverageReportGenerated | ||
public class DataSourceTest extends DataSource { | ||
@Bean | ||
@Override | ||
@DependsOn({"logbackInitialization"}) | ||
HikariDataSource hikariDataSource(final ApplicationKeystore keystore) { | ||
this.setJdbcUrl("jdbc:hsqldb:mem:" + DATABASE_NAME.getPath() + "Test" + ";shutdown=true"); | ||
this.setPoolName("SudokuFXTestHikariConnection"); | ||
return super.hikariDataSource(keystore); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters