From 21871a967808d34f7daf47adfebf9813aefeefb1 Mon Sep 17 00:00:00 2001 From: Pim van Nierop Date: Thu, 30 Mar 2023 18:06:36 +0200 Subject: [PATCH] Check for different connection paradigms --- .../org/mskcc/cbio/portal/dao/JdbcDataSource.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/main/java/org/mskcc/cbio/portal/dao/JdbcDataSource.java b/core/src/main/java/org/mskcc/cbio/portal/dao/JdbcDataSource.java index d84e028dce4..625fa58a35a 100644 --- a/core/src/main/java/org/mskcc/cbio/portal/dao/JdbcDataSource.java +++ b/core/src/main/java/org/mskcc/cbio/portal/dao/JdbcDataSource.java @@ -9,6 +9,7 @@ * Data source that self-initializes based on cBioPortal configuration. */ public class JdbcDataSource extends BasicDataSource { + public JdbcDataSource () { DatabaseProperties dbProperties = DatabaseProperties.getInstance(); @@ -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) { @@ -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(); + } }