Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicated code #919

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
import java.util.HashMap;
import java.util.Map;

/**
* Created by SMAKINEN on 11.6.2015.
*/
public class DatasourceHelper {

public static final String DEFAULT_DATASOURCE_NAME = "jdbc/OskariPool";
Expand Down Expand Up @@ -158,19 +155,22 @@ public DataSource createDataSource(final String prefix) {
dataSource.setValidationQuery("SELECT 1");
dataSource.setValidationQueryTimeout(100);
try {
// Try getting connection:
// If it fails we can tell the admin that the config is not good and try JNDI instead
dataSource.getConnection().close();
registerDataSource(poolName, dataSource);
} catch (SQLException e) {
getLogger().error(e, "Couldn't create database connection using:", info.url);
// return null so we don't add a non-functioning datasource to localDataSources
// AND this makes the code always try to get a connection using JNDI instead
return null;
}
localDataSources.put(poolName, dataSource);
return dataSource;
}

/**
* Tests a connection from datasource and registers the datasource to local registry if its functional
* @param poolName name to use like "jdbc/OskariPool"
* @param dataSource the datasource to test and register
* @throws SQLException if connection can't be opened/ds is broken
*/
public void registerDataSource(String poolName, DataSource dataSource) throws SQLException {
// Try getting connection:
// If it fails we can tell the admin that the config is not good and try JNDI instead
Expand Down