8484import org .springframework .context .ApplicationContext ;
8585import org .springframework .context .annotation .Bean ;
8686import org .springframework .context .annotation .Configuration ;
87+ import org .springframework .core .io .Resource ;
8788import org .springframework .web .servlet .config .annotation .AsyncSupportConfigurer ;
8889import org .springframework .web .servlet .config .annotation .WebMvcConfigurer ;
8990
@@ -218,31 +219,25 @@ public VirtualStudyExportDecoratorService virtualStudyAwareExportService(
218219 return new VirtualStudyExportDecoratorService (virtualStudyService , exportService );
219220 }
220221
222+ @ Bean ("exportMapperLocations" )
223+ public Resource [] clickhouseExportMapperLocations (ApplicationContext applicationContext )
224+ throws IOException {
225+ return applicationContext .getResources ("classpath:mappers/export/*.xml" );
226+ }
227+
221228 @ Bean ("exportSqlSessionFactory" )
222229 public SqlSessionFactoryBean exportSqlSessionFactory (
223- @ Qualifier ("exportDataSource" ) DataSource dataSource , ApplicationContext applicationContext )
224- throws IOException {
230+ @ Qualifier ("exportDataSource" ) DataSource dataSource , Resource [] exportMapperLocations ) {
225231 SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean ();
226232 sessionFactory .setDataSource (dataSource );
227- sessionFactory .setMapperLocations (
228- applicationContext .getResources ("classpath:mappers/export/*.xml" ));
233+ sessionFactory .setMapperLocations (exportMapperLocations );
229234 return sessionFactory ;
230235 }
231236
232- @ Bean
233- public DataSource exportDataSource (DataSourceProperties dataSourceProperties ) {
234- HikariConfig hikariConfig = new HikariConfig ();
235- hikariConfig .setJdbcUrl (dataSourceProperties .getUrl ());
236- hikariConfig .setUsername (dataSourceProperties .getUsername ());
237- hikariConfig .setPassword (dataSourceProperties .getPassword ());
238-
239- // Set streaming properties for data export
240- Properties dsProperties = new Properties ();
241- dsProperties .setProperty ("useCursorFetch" , "true" );
242- dsProperties .setProperty ("defaultFetchSize" , "1000" );
243- hikariConfig .setDataSourceProperties (dsProperties );
244-
245- return new HikariDataSource (hikariConfig );
237+ @ Bean ("exportDataSource" )
238+ public DataSource clickhouseExportDataSource (DataSourceProperties dataSourceProperties ) {
239+ // TODO How to use cursor fetch with ClickHouse to minimize memory usage during export?
240+ return createDataSource (dataSourceProperties , null );
246241 }
247242
248243 @ Value ("${feature.study.export.timeout_ms:600000}" ) // 10 minutes timeout by default
@@ -253,6 +248,23 @@ public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
253248 configurer .setDefaultTimeout (timeoutMs );
254249 }
255250
251+ private DataSource createDataSource (
252+ DataSourceProperties dataSourceProperties , Properties dataSourcePropertiesOverrides ) {
253+ HikariConfig hikariConfig = new HikariConfig ();
254+ hikariConfig .setJdbcUrl (dataSourceProperties .getUrl ());
255+ hikariConfig .setUsername (dataSourceProperties .getUsername ());
256+ hikariConfig .setPassword (dataSourceProperties .getPassword ());
257+
258+ if (dataSourceProperties .getDriverClassName () != null ) {
259+ hikariConfig .setDriverClassName (dataSourceProperties .getDriverClassName ());
260+ }
261+ if (dataSourcePropertiesOverrides != null ) {
262+ hikariConfig .setDataSourceProperties (dataSourcePropertiesOverrides );
263+ }
264+
265+ return new HikariDataSource (hikariConfig );
266+ }
267+
256268 @ Bean
257269 public List <Exporter > exporters (
258270 CancerStudyMetadataExporter cancerStudyMetadataExporter ,
0 commit comments