Class LateInitDataSource
java.lang.Object
org.springframework.jdbc.datasource.DelegatingDataSource
com.github.seregamorph.testsmartcontext.jdbc.CloseableDelegatingDataSource
com.github.seregamorph.testsmartcontext.jdbc.LateInitDataSource
- All Implemented Interfaces:
Closeable,AutoCloseable,Wrapper,CommonDataSource,DataSource,org.springframework.beans.factory.InitializingBean
DataSource decorator which resolves delegate DataSource on first demand.
This can be an optimization for DataSources created beyond TestContainers-managed Docker containers: the container is only started if needed.
Usage example:
@Bean
public DataSource dataSource(PostgreSQLContainer<?> container) {
// lazy late initialization - the JDBC url is not known yet, because container is not running
return new LateInitDataSource(() -> {
LOGGER.info("Late initialization data source docker container {}", container);
// start only on demand
container.start();
return createHikariDataSourceForContainer(container);
});
}
This DataSource delegates close call to the target.- Author:
- Sergey Chernov
-
Constructor Summary
ConstructorsConstructorDescriptionLateInitDataSource(String name, Supplier<DataSource> dataSourceSupplier) LateInitDataSource(Supplier<DataSource> dataSourceSupplier) -
Method Summary
Methods inherited from class com.github.seregamorph.testsmartcontext.jdbc.CloseableDelegatingDataSource
closeMethods inherited from class org.springframework.jdbc.datasource.DelegatingDataSource
createConnectionBuilder, createShardingKeyBuilder, getConnection, getConnection, getLoginTimeout, getLogWriter, getParentLogger, getTargetDataSource, isWrapperFor, setLoginTimeout, setLogWriter, setTargetDataSource, unwrap
-
Constructor Details
-
LateInitDataSource
-
LateInitDataSource
-
-
Method Details
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Overrides:
afterPropertiesSetin classorg.springframework.jdbc.datasource.DelegatingDataSource
-
obtainTargetDataSource
- Overrides:
obtainTargetDataSourcein classorg.springframework.jdbc.datasource.DelegatingDataSource
-
toString
-