Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Keller committed Sep 17, 2024
1 parent 25ede84 commit 21a935e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.FileSystems;
Expand Down Expand Up @@ -81,6 +82,19 @@ public static void loadMySqlDataSource(final DataSourceManager dataSourceManager
}
dataSourceManager.load(UserMetadataService.NAME_DATASOURCE, connectionProperties);
}

/**
* Create a JDBC template with a query timeout.
*
* @param dataSource data source
* @param timeoutSec query timeout, in sec
* @return the JDBC template
*/
public static JdbcTemplate createJdbcTemplate(DataSource dataSource, int timeoutSec) {
final JdbcTemplate result = new JdbcTemplate(dataSource);
result.setQueryTimeout(timeoutSec);
return result;
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,23 @@ public class MySqlTagService implements TagService {
/**
* Constructor.
*
* @param config config
* @param jdbcTemplate JDBC template
* @param jdbcTemplateLongTimeout JDBC template for longer running queries
* @param lookupService lookup service
* @param metacatJson json util
* @param userMetadataService user metadata service
* @param config config
* @param jdbcTemplate JDBC template
* @param lookupService lookup service
* @param metacatJson json util
* @param userMetadataService user metadata service
*/
public MySqlTagService(
final Config config,
final JdbcTemplate jdbcTemplate,
final JdbcTemplate jdbcTemplateLongTimeout,
final LookupService lookupService,
final MetacatJson metacatJson,
final UserMetadataService userMetadataService
) {
this.config = Preconditions.checkNotNull(config, "config is required");
this.jdbcTemplate = jdbcTemplate;
this.jdbcTemplateLongTimeout = jdbcTemplateLongTimeout;
this.jdbcTemplateLongTimeout = MySqlServiceUtil.createJdbcTemplate(
jdbcTemplate.getDataSource(), config.getLongMetadataQueryTimeout());
this.lookupService = Preconditions.checkNotNull(lookupService, "lookupService is required");
this.metacatJson = Preconditions.checkNotNull(metacatJson, "metacatJson is required");
this.userMetadataService = Preconditions.checkNotNull(userMetadataService, "userMetadataService is required");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

Expand Down Expand Up @@ -92,25 +91,22 @@ public LookupService lookupService(
/**
* The tag service to use.
*
* @param jdbcTemplate JDBC template
* @param jdbcTemplateLongTimeout JDBC template for longer running queries
* @param config System config to use
* @param metacatJson Json Utilities to use
* @param lookupService Look up service implementation to use
* @param userMetadataService User metadata service implementation to use
* @param jdbcTemplate JDBC template
* @param config System config to use
* @param metacatJson Json Utilities to use
* @param lookupService Look up service implementation to use
* @param userMetadataService User metadata service implementation to use
* @return The tag service implementation backed by MySQL
*/
@Bean
public TagService tagService(
@Qualifier("metadataJdbcTemplate") final JdbcTemplate jdbcTemplate,
@Qualifier("metadataJdbcTemplateLongTimeout") final JdbcTemplate jdbcTemplateLongTimeout,
final Config config,
final MetacatJson metacatJson,
final LookupService lookupService,
final UserMetadataService userMetadataService
) {
return new MySqlTagService(
config, jdbcTemplate, jdbcTemplateLongTimeout, lookupService, metacatJson, userMetadataService);
return new MySqlTagService(config, jdbcTemplate, lookupService, metacatJson, userMetadataService);
}

/**
Expand Down Expand Up @@ -163,28 +159,10 @@ public DataSourceTransactionManager metadataTxManager(
* @return metadata JDBC template
*/
@Bean
@Primary
public JdbcTemplate metadataJdbcTemplate(
@Qualifier("metadataDataSource") final DataSource mySqlDataSource,
final Config config) {
final JdbcTemplate result = new JdbcTemplate(mySqlDataSource);
result.setQueryTimeout(config.getMetadataQueryTimeout());
return result;
}

/**
* mySql metadata JDBC template for longer running queries.
*
* @param mySqlDataSource metadata data source
* @param config System config to use
* @return metadata JDBC template
*/
@Bean
public JdbcTemplate metadataJdbcTemplateLongTimeout(
@Qualifier("metadataDataSource") final DataSource mySqlDataSource,
final Config config) {
final JdbcTemplate result = new JdbcTemplate(mySqlDataSource);
result.setQueryTimeout(config.getLongMetadataQueryTimeout());
return result;
return MySqlServiceUtil.createJdbcTemplate(
mySqlDataSource, config.getMetadataQueryTimeout());
}
}

0 comments on commit 21a935e

Please sign in to comment.