From 1f3fc9729a825ec86a8eb45e7aa1cfae087aa38e Mon Sep 17 00:00:00 2001 From: Dario Ghunney Ware Date: Tue, 10 Dec 2024 22:03:22 +0000 Subject: [PATCH] #2270 adding postgres to default profile --- .../docker-compose-latest-security.yml | 6 +++++- .../security/database/DatabaseConfig.java | 18 +++++++++--------- .../SPDF/model/ApplicationProperties.java | 2 +- .../exception/UnsupportedDriverException.java | 7 ------- .../resources/application-mysql.properties | 2 +- .../resources/application-oracle.properties | 2 +- .../resources/application-postgres.properties | 9 --------- src/main/resources/application.properties | 10 ++++++++-- src/main/resources/settings.yml.template | 4 ++-- 9 files changed, 27 insertions(+), 33 deletions(-) delete mode 100644 src/main/java/stirling/software/SPDF/model/exception/UnsupportedDriverException.java delete mode 100644 src/main/resources/application-postgres.properties diff --git a/exampleYmlFiles/docker-compose-latest-security.yml b/exampleYmlFiles/docker-compose-latest-security.yml index b4d6fd0d22a..eb6130f705b 100644 --- a/exampleYmlFiles/docker-compose-latest-security.yml +++ b/exampleYmlFiles/docker-compose-latest-security.yml @@ -32,10 +32,14 @@ services: SYSTEM_MAXFILESIZE: "100" METRICS_ENABLED: "true" SYSTEM_GOOGLEVISIBILITY: "true" + SPRING_PROFILES_ACTIVE: postgres SPRING_DATASOURCE_URL: "jdbc:postgresql://db:5432/stirling_pdf" SPRING_DATASOURCE_USERNAME: "admin" SPRING_DATASOURCE_PASSWORD: "stirling" - SPRING_JPA_HIBERNATE_DDL_AUTO: "update" + SPRING_DATASOURCE_DRIVER_CLASS_NAME: "org.postgresql.Driver" +# SPRING_JPA_HIBERNATE_DDL_AUTO: "update" + SPRING_JPA_PROPERTIES_HIBERNATE_DIALECT: "org.hibernate.dialect.PostgreSQLDialect" +# SPRING_JPA_DATABASE_PLATFORM: "org.hibernate.dialect.PostgreSQLDialect" restart: on-failure:5 db: diff --git a/src/main/java/stirling/software/SPDF/config/security/database/DatabaseConfig.java b/src/main/java/stirling/software/SPDF/config/security/database/DatabaseConfig.java index e2f73fea3cd..8b7e61c74e4 100644 --- a/src/main/java/stirling/software/SPDF/config/security/database/DatabaseConfig.java +++ b/src/main/java/stirling/software/SPDF/config/security/database/DatabaseConfig.java @@ -10,13 +10,16 @@ import lombok.Getter; import stirling.software.SPDF.model.ApplicationProperties; -import stirling.software.SPDF.model.exception.UnsupportedDriverException; @Getter @Configuration public class DatabaseConfig { - @Autowired private ApplicationProperties applicationProperties; + private final ApplicationProperties applicationProperties; + + public DatabaseConfig(@Autowired ApplicationProperties applicationProperties) { + this.applicationProperties = applicationProperties; + } @Bean public Connection connection() throws SQLException { @@ -24,7 +27,7 @@ public Connection connection() throws SQLException { applicationProperties.getSystem().getDatasource(); DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create(); - dataSourceBuilder.driverClassName(getDriverClassName(datasource.getDriverClassName())); + dataSourceBuilder.driverClassName(getDriverClassName(datasource.getDriver())); dataSourceBuilder.url(datasource.getUrl()); dataSourceBuilder.username(datasource.getUsername()); dataSourceBuilder.password(datasource.getPassword()); @@ -34,18 +37,15 @@ public Connection connection() throws SQLException { private String getDriverClassName(ApplicationProperties.Driver driverName) { switch (driverName) { - case POSTGRESQL -> { - return "org.postgresql.Driver"; - } case ORACLE -> { return "oracle.jdbc.OracleDriver"; } case MY_SQL -> { return "com.mysql.cj.jdbc.Driver"; } - default -> - throw new UnsupportedDriverException( - "The database driver " + driverName + " is not supported."); + default -> { + return "org.postgresql.Driver"; + } } } } diff --git a/src/main/java/stirling/software/SPDF/model/ApplicationProperties.java b/src/main/java/stirling/software/SPDF/model/ApplicationProperties.java index ea3d5ff96ea..36b8fa6fe43 100644 --- a/src/main/java/stirling/software/SPDF/model/ApplicationProperties.java +++ b/src/main/java/stirling/software/SPDF/model/ApplicationProperties.java @@ -255,7 +255,7 @@ public static class System { @Data public static class Datasource { private String url; - private Driver driverClassName; + private Driver driver; private String username; private String password; } diff --git a/src/main/java/stirling/software/SPDF/model/exception/UnsupportedDriverException.java b/src/main/java/stirling/software/SPDF/model/exception/UnsupportedDriverException.java deleted file mode 100644 index b52101e9373..00000000000 --- a/src/main/java/stirling/software/SPDF/model/exception/UnsupportedDriverException.java +++ /dev/null @@ -1,7 +0,0 @@ -package stirling.software.SPDF.model.exception; - -public class UnsupportedDriverException extends RuntimeException { - public UnsupportedDriverException(String message) { - super(message); - } -} diff --git a/src/main/resources/application-mysql.properties b/src/main/resources/application-mysql.properties index 02d4b117ddf..60e768b8da8 100644 --- a/src/main/resources/application-mysql.properties +++ b/src/main/resources/application-mysql.properties @@ -1,4 +1,4 @@ -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +spring.datasource.driver=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/stirling_pdf?createDatabaseIfNotExist=true spring.datasource.username=admin spring.datasource.password=stirling diff --git a/src/main/resources/application-oracle.properties b/src/main/resources/application-oracle.properties index 7bf0d98051b..8a7c8805ead 100644 --- a/src/main/resources/application-oracle.properties +++ b/src/main/resources/application-oracle.properties @@ -1,4 +1,4 @@ -spring.datasource.driver-class-name=oracle.jdbc.OracleDriver +spring.datasource.driver=oracle.jdbc.OracleDriver spring.datasource.url=jdbc:oracle:thin:@localhost:1521:stirling_pdf spring.datasource.username=admin spring.datasource.password=stirling diff --git a/src/main/resources/application-postgres.properties b/src/main/resources/application-postgres.properties deleted file mode 100644 index 9ab14949f98..00000000000 --- a/src/main/resources/application-postgres.properties +++ /dev/null @@ -1,9 +0,0 @@ -spring.datasource.driver-class-name=org.postgresql.Driver -spring.datasource.url=jdbc:postgresql://db:5432/postgres -spring.datasource.username=postgres -spring.datasource.password=postgres -spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect -spring.jpa.open-in-view=false -spring.jpa.generate-ddl=true -spring.jpa.hibernate.ddl-auto=update -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b48c8343d58..0914fb3572d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,3 @@ -spring.profiles.active=postgres - multipart.enabled=true logging.level.org.springframework=WARN @@ -41,6 +39,14 @@ spring.mvc.async.request-timeout=${SYSTEM_CONNECTIONTIMEOUTMILLISECONDS:1200000} #spring.thymeleaf.prefix=file:/customFiles/templates/,classpath:/templates/ #spring.thymeleaf.cache=false +spring.datasource.driver=org.postgresql.Driver +spring.datasource.url=jdbc:postgresql://localhost:5432/postgres +spring.datasource.username=postgres +spring.datasource.password=postgres +spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect +spring.jpa.open-in-view=false +spring.jpa.hibernate.ddl-auto=update +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect server.servlet.session.timeout=30m # Change the default URL path for OpenAPI JSON springdoc.api-docs.path=/v1/api-docs diff --git a/src/main/resources/settings.yml.template b/src/main/resources/settings.yml.template index bde341333d8..486f1bbf1f3 100644 --- a/src/main/resources/settings.yml.template +++ b/src/main/resources/settings.yml.template @@ -77,7 +77,7 @@ legal: impressum: '' # URL to the impressum of your application (e.g. https://example.com/impressum). Empty string to disable or filename to load from local file in static folder system: - springProfilesActive: postgres # set the default environment (e.g. 'postgres', 'mysql', 'oracle') + springProfilesActive: '' # set the default environment (e.g. 'mysql', 'oracle') defaultLocale: en-US # set the default language (e.g. 'de-DE', 'fr-FR', etc) googlevisibility: false # 'true' to allow Google visibility (via robots.txt), 'false' to disallow enableAlphaFunctionality: false # set to enable functionality which might need more testing before it fully goes live (this feature might make no changes) @@ -88,7 +88,7 @@ system: enableAnalytics: undefined # set to 'true' to enable analytics, set to 'false' to disable analytics; for enterprise users, this is set to true datasource: url: jdbc:postgresql://localhost:5432/postgres - driverClassName: postgresql + driver: postgresql username: postgres password: postgres