Skip to content

Commit

Permalink
Check for different connection paradigms
Browse files Browse the repository at this point in the history
  • Loading branch information
pvannierop committed Apr 3, 2023
1 parent 4627aff commit 21871a9
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/src/main/java/org/mskcc/cbio/portal/dao/JdbcDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Data source that self-initializes based on cBioPortal configuration.
*/
public class JdbcDataSource extends BasicDataSource {

public JdbcDataSource () {
DatabaseProperties dbProperties = DatabaseProperties.getInstance();

Expand All @@ -23,6 +24,13 @@ public JdbcDataSource () {

Assert.hasText(userName, errorMessage("username", "db.user"));
Assert.hasText(password, errorMessage("password", "db.password"));
Assert.hasText(mysqlDriverClassName, errorMessage("driver class name", "db.driver"));

Assert.isTrue(
!((defined(host) || defined(database) || defined(dbProperties.getDbUseSSL())) && defined(connectionURL)),
"Properties define both db.connection_string and (one of) db.host, db.portal_db_name and db.use_ssl. " +
"Please configure with either db.connection_string (preferred), or db.host, db.portal_db_name and db.use_ssl."
);

// For backward compatibility, build connection URL from individual properties.
if (connectionURL == null) {
Expand Down Expand Up @@ -58,4 +66,8 @@ public JdbcDataSource () {
private String errorMessage(String displayName, String propertyName) {
return String.format("No %s provided for database connection. Please set '%s' in portal.properties.", displayName, propertyName);
}

private boolean defined(String property) {
return property != null && !property.isEmpty();
}
}

0 comments on commit 21871a9

Please sign in to comment.