diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/OracleJpaConfiguration.java b/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/OracleJpaConfiguration.java index d485be28..7991a754 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/OracleJpaConfiguration.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/OracleJpaConfiguration.java @@ -34,14 +34,17 @@ public LocalContainerEntityManagerFactoryBean oracleEntityManagerFactory( ) { return builder .dataSource(dataSource) - .properties(Map.of()) + .properties(Map.of( + "hibernate.dialect", "org.hibernate.dialect.OracleDialect", + "hibernate.temp.use_jdbc_metadata_defaults","false" + )) .packages("ca.bc.gov.restapi.results.oracle") .persistenceUnit("oracle") .build(); } @Bean(name = "oracleDataSource") - @ConfigurationProperties(prefix = "spring.datasource.oracle") + @ConfigurationProperties(prefix = "spring.oracle") public DataSource oracleDataSource() { return DataSourceBuilder.create().build(); } diff --git a/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/PostgresJpaConfiguration.java b/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/PostgresJpaConfiguration.java index f18799cf..40ee3110 100644 --- a/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/PostgresJpaConfiguration.java +++ b/backend/src/main/java/ca/bc/gov/restapi/results/common/configuration/PostgresJpaConfiguration.java @@ -35,7 +35,10 @@ public LocalContainerEntityManagerFactoryBean postgresEntityManagerFactory( ) { return builder .dataSource(dataSource) - .properties(Map.of()) + .properties(Map.of( + "hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect", + "hibernate.temp.use_jdbc_metadata_defaults","false" + )) .packages("ca.bc.gov.restapi.results.postgres") .persistenceUnit("postgres") .build(); diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 6d1ae462..be960b07 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -11,6 +11,25 @@ server: spring: application: name: results-api + oracle: + jdbcUrl: jdbc:oracle:thin:@tcps://${DATABASE_HOST:nrcdb03.bcgov}:${DATABASE_PORT:1543}/${SERVICE_NAME:dbq01.nrs.bcgov}?javax.net.ssl.trustStore=${ca.bc.gov.nrs.oracle.keystore}&javax.net.ssl.trustStorePassword=${ca.bc.gov.nrs.oracle.secret}&javax.net.ssl.keyStore=${ca.bc.gov.nrs.oracle.keystore}&javax.net.ssl.keyStorePassword=${ca.bc.gov.nrs.oracle.secret}&oracle.net.ssl_certificate_alias=${ca.bc.gov.nrs.oracle.host}&oracle.net.ssl_server_dn_match=false + url: ${spring.datasource.oracle.jdbcUrl} + username: ${DATABASE_USER} + password: ${DATABASE_PASSWORD} + hikari: + driver-class-name: oracle.jdbc.OracleDriver + jdbcUrl: ${spring.datasource.oracle.jdbcUrl} + url: ${spring.datasource.oracle.jdbcUrl} + username: ${DATABASE_USER} + password: ${DATABASE_PASSWORD} + connectionTimeout: ${DB_POOL_CONN_TIMEOUT:120000} + idleTimeout: ${DB_POOL_IDLE_TIMEOUT:60000} + maxLifetime: ${DB_POOL_MAX_LIFETIME:150000} + keepaliveTime: 30000 + poolName: SilvaOracleConnPool + minimumIdle: ${DB_POOL_MIN_IDLE:1} + maximumPoolSize: ${DB_POOL_MAX_SIZE:1} + leakDetectionThreshold: 60000 datasource: jdbcUrl: jdbc:postgresql://${POSTGRES_HOST:localhost}:5432/${POSTGRES_DB:nr-silva} url: ${spring.datasource.jdbcUrl} @@ -29,25 +48,7 @@ spring: minimumIdle: ${DB_POOL_MIN_IDLE:1} maximumPoolSize: ${DB_POOL_MAX_SIZE:1} leakDetectionThreshold: 60000 - oracle: - jdbcUrl: jdbc:oracle:thin:@tcps://${DATABASE_HOST:nrcdb03.bcgov}:${DATABASE_PORT:1543}/${SERVICE_NAME:dbq01.nrs.bcgov}?javax.net.ssl.trustStore=${ca.bc.gov.nrs.oracle.keystore}&javax.net.ssl.trustStorePassword=${ca.bc.gov.nrs.oracle.secret}&javax.net.ssl.keyStore=${ca.bc.gov.nrs.oracle.keystore}&javax.net.ssl.keyStorePassword=${ca.bc.gov.nrs.oracle.secret}&oracle.net.ssl_certificate_alias=${ca.bc.gov.nrs.oracle.host}&oracle.net.ssl_server_dn_match=false - url: ${spring.datasource.oracle.jdbcUrl} - username: ${DATABASE_USER} - password: ${DATABASE_PASSWORD} - hikari: - driver-class-name: oracle.jdbc.OracleDriver - jdbcUrl: ${spring.datasource.oracle.jdbcUrl} - url: ${spring.datasource.oracle.jdbcUrl} - username: ${DATABASE_USER} - password: ${DATABASE_PASSWORD} - connectionTimeout: ${DB_POOL_CONN_TIMEOUT:120000} - idleTimeout: ${DB_POOL_IDLE_TIMEOUT:60000} - maxLifetime: ${DB_POOL_MAX_LIFETIME:150000} - keepaliveTime: 30000 - poolName: SilvaOracleConnPool - minimumIdle: ${DB_POOL_MIN_IDLE:1} - maximumPoolSize: ${DB_POOL_MAX_SIZE:1} - leakDetectionThreshold: 60000 + jpa: hibernate: ddl-auto: none diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/configuration/MultiFlywayConfig.java b/backend/src/test/java/ca/bc/gov/restapi/results/configuration/MultiFlywayConfig.java deleted file mode 100644 index 4d93434b..00000000 --- a/backend/src/test/java/ca/bc/gov/restapi/results/configuration/MultiFlywayConfig.java +++ /dev/null @@ -1,39 +0,0 @@ -package ca.bc.gov.restapi.results.configuration; - -import javax.sql.DataSource; -import org.flywaydb.core.Flyway; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * Configuration class for setting up multiple Flyway instances for different databases. This - * resides inside the test package to avoid conflicts with the main application. This class is used - * to configure Flyway for PostgreSQL and Oracle databases, so we can make use of the testcontainers - * to recreate the expected database structure. - */ -@Configuration -public class MultiFlywayConfig { - - @Bean - public Flyway flywayPostgres(@Qualifier("postgresDataSource") DataSource dataSource) { - return Flyway.configure() - //We build the datasource as the original Bean uses Hikari, and it failed due to Timeout - .dataSource(dataSource) - .locations("classpath:db/migration", "classpath:migration/postgres") - .baselineOnMigrate(true) - .load(); - } - - @Bean - public Flyway flywayOracle(@Qualifier("oracleDataSource") DataSource dataSource) { - return Flyway.configure() - //We build the datasource as the original Bean uses Hikari, and it failed due to Timeout - .dataSource(dataSource) - .locations("classpath:migration/oracle") - .schemas("THE") - .load(); - } - - -} \ No newline at end of file diff --git a/backend/src/test/java/ca/bc/gov/restapi/results/extensions/AbstractTestContainerIntegrationTest.java b/backend/src/test/java/ca/bc/gov/restapi/results/extensions/AbstractTestContainerIntegrationTest.java index 969847e2..ff0bb325 100644 --- a/backend/src/test/java/ca/bc/gov/restapi/results/extensions/AbstractTestContainerIntegrationTest.java +++ b/backend/src/test/java/ca/bc/gov/restapi/results/extensions/AbstractTestContainerIntegrationTest.java @@ -4,7 +4,6 @@ import org.flywaydb.core.Flyway; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.DynamicPropertyRegistry; @@ -24,19 +23,18 @@ */ @Testcontainers @ExtendWith({SpringExtension.class}) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@SpringBootTest( + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT +) @ContextConfiguration public abstract class AbstractTestContainerIntegrationTest { - /** - * PostgreSQL container instance. - */ static final PostgreSQLContainer postgres; - /** - * Oracle container instance. - */ static final OracleContainer oracle; + static final Flyway flywayPostgres; + static final Flyway flywayOracle; + // Static fields declared like this are instantiated first by the JVM static { postgres = new PostgreSQLContainer("postgres:13") @@ -47,50 +45,44 @@ public abstract class AbstractTestContainerIntegrationTest { postgres.start(); oracle.start(); - } - @Autowired - private Flyway flywayPostgres; + flywayPostgres = + Flyway + .configure() + .dataSource(postgres.getJdbcUrl(), postgres.getUsername(), postgres.getPassword()) + .locations("classpath:db/migration", "classpath:migration/postgres") + .baselineOnMigrate(true) + .load(); - @Autowired - private Flyway flywayOracle; + flywayOracle = + Flyway + .configure() + .dataSource(oracle.getJdbcUrl(), oracle.getUsername(), oracle.getPassword()) + .locations("classpath:migration/oracle") + .schemas("THE") + .baselineOnMigrate(true) + .load(); + + } - /** - * Migrate the databases using Flyway before each test. As we're using flyway, there's no need to - * worry about duplicate insertion - */ @BeforeEach public void setUp() { flywayPostgres.migrate(); flywayOracle.migrate(); } - /** - * Register dynamic properties from the testcontainers. This will overwrite the application - * properties for the databases with the testcontainers configuration. allowing the application to - * connect to the ephemeral databases. As the username and password is randomly generated, there's - * no need to worry about conflicts. - * - * @param registry the dynamic property registry from spring itself - */ @DynamicPropertySource static void registerDynamicProperties(DynamicPropertyRegistry registry) { - // Overwrite the Postgres datasource with the testcontainer configuration - registry.add("spring.datasource.postgres.url", postgres::getJdbcUrl); - registry.add("spring.datasource.postgres.username", postgres::getUsername); - registry.add("spring.datasource.postgres.password", postgres::getPassword); - // Overwrite the Flyway for Postgres with the testcontainer configuration - registry.add("spring.flyway.postgres.url", postgres::getJdbcUrl); - registry.add("spring.flyway.postgres.user", postgres::getUsername); - registry.add("spring.flyway.postgres.password", postgres::getPassword); - // Overwrite the Oracle datasource with the testcontainer configuration - registry.add("spring.datasource.oracle.url", oracle::getJdbcUrl); - registry.add("spring.datasource.oracle.username", oracle::getUsername); - registry.add("spring.datasource.oracle.password", oracle::getPassword); - // Overwrite the Flyway for Oracle with the testcontainer configuration - registry.add("spring.flyway.oracle.url", oracle::getJdbcUrl); - registry.add("spring.flyway.oracle.user", oracle::getUsername); - registry.add("spring.flyway.oracle.password", oracle::getPassword); + + registry.add("spring.datasource.url", postgres::getJdbcUrl); + registry.add("spring.datasource.username", postgres::getUsername); + registry.add("spring.datasource.password", postgres::getPassword); + + registry.add("spring.oracle.url", oracle::getJdbcUrl); + registry.add("spring.oracle.jdbcUrl", oracle::getJdbcUrl); + registry.add("spring.oracle.username", oracle::getUsername); + registry.add("spring.oracle.password", oracle::getPassword); + } }