2727import org .testcontainers .oracle .OracleContainer ;
2828import org .testcontainers .utility .DockerImageName ;
2929
30+ import com .zaxxer .hikari .HikariConfig ;
31+ import com .zaxxer .hikari .HikariDataSource ;
32+
3033/**
3134 * {@link DataSource} setup for Oracle Database XE. Starts a docker container with an Oracle database.
3235 *
33- * @see <a href=
34- * "https://blogs.oracle.com/oraclemagazine/deliver-oracle-database-18c-express-edition-in-containers">Oracle
35- * Docker Image</a>
36+ * @see <a href= "https://blogs.oracle.com/oraclemagazine/deliver-oracle-database-18c-express-edition-in-containers">Oracle Docker Image</a>
3637 * @see <a href="https://www.testcontainers.org/modules/databases/oraclexe/">Testcontainers Oracle</a>
3738 * @author Thomas Lang
3839 * @author Jens Schauder
@@ -43,16 +44,16 @@ public class OracleDataSourceConfiguration extends DataSourceConfiguration {
4344
4445 private static final Log LOG = LogFactory .getLog (OracleDataSourceConfiguration .class );
4546
46- private static OracleContainer ORACLE_CONTAINER ;
47+ private static DataSource DATA_SOURCE ;
4748
4849 public OracleDataSourceConfiguration (TestClass testClass , Environment environment ) {
4950 super (testClass , environment );
5051 }
5152
5253 @ Override
53- protected DataSource createDataSource () {
54+ protected synchronized DataSource createDataSource () {
5455
55- if (ORACLE_CONTAINER == null ) {
56+ if (DATA_SOURCE == null ) {
5657
5758 LOG .info ("Oracle starting..." );
5859 DockerImageName dockerImageName = DockerImageName .parse ("gvenzl/oracle-free:23.3-slim" );
@@ -62,21 +63,33 @@ protected DataSource createDataSource() {
6263 container .start ();
6364 LOG .info ("Oracle started" );
6465
65- ORACLE_CONTAINER = container ;
66+ initDb (container .getJdbcUrl (),container .getUsername (), container .getPassword ());
67+
68+ DATA_SOURCE = poolDataSource (new DriverManagerDataSource (container .getJdbcUrl (),
69+ container .getUsername (), container .getPassword ()));
6670 }
71+ return DATA_SOURCE ;
72+ }
73+
74+ private DataSource poolDataSource (DataSource dataSource ) {
75+
76+ HikariConfig config = new HikariConfig ();
77+ config .setDataSource (dataSource );
6778
68- initDb ();
79+ config .setMaximumPoolSize (10 );
80+ config .setIdleTimeout (30000 );
81+ config .setMaxLifetime (600000 );
82+ config .setConnectionTimeout (30000 );
6983
70- return new DriverManagerDataSource (ORACLE_CONTAINER .getJdbcUrl (), ORACLE_CONTAINER .getUsername (),
71- ORACLE_CONTAINER .getPassword ());
84+ return new HikariDataSource (config );
7285 }
7386
74- private void initDb () {
87+ private void initDb (String jdbcUrl , String username , String password ) {
7588
76- final DriverManagerDataSource dataSource = new DriverManagerDataSource (ORACLE_CONTAINER . getJdbcUrl () , "SYSTEM" ,
77- ORACLE_CONTAINER . getPassword () );
89+ final DriverManagerDataSource dataSource = new DriverManagerDataSource (jdbcUrl , "SYSTEM" ,
90+ password );
7891 final JdbcTemplate jdbc = new JdbcTemplate (dataSource );
79- jdbc .execute ("GRANT ALL PRIVILEGES TO " + ORACLE_CONTAINER . getUsername () );
92+ jdbc .execute ("GRANT ALL PRIVILEGES TO " + username );
8093 }
8194
8295 @ Override
0 commit comments