diff --git a/extensions-core/mysql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/mysql/MySQLConnector.java b/extensions-core/mysql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/mysql/MySQLConnector.java index 78c6826ba8e..46e10331245 100644 --- a/extensions-core/mysql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/mysql/MySQLConnector.java +++ b/extensions-core/mysql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/mysql/MySQLConnector.java @@ -61,24 +61,19 @@ public class MySQLConnector extends SQLMetadataConnector ) { super(config, dbTables); - this.dbi = createDBI(config.get(), driverConfig, connectorSslConfig, getValidationQuery()); + log.info("Loading \"MySQL\" metadata connector driver %s", driverConfig.getDriverClassName()); + tryLoadDriverClass(driverConfig.getDriverClassName(), true); if (driverConfig.getDriverClassName().contains("mysql")) { myTransientExceptionClass = tryLoadDriverClass(MYSQL_TRANSIENT_EXCEPTION_CLASS_NAME, false); } else { myTransientExceptionClass = null; } - } - public static DBI createDBI(MetadataStorageConnectorConfig config, MySQLConnectorDriverConfig driverConfig, MySQLConnectorSslConfig connectorSslConfig, String validationQuery) - { - log.info("Loading \"MySQL\" metadata connector driver %s", driverConfig.getDriverClassName()); - tryLoadDriverClass(driverConfig.getDriverClassName(), true); - - final BasicDataSource datasource = makeDatasource(config, validationQuery); + final BasicDataSource datasource = getDatasource(); // MySQL driver is classloader isolated as part of the extension // so we need to help JDBC find the driver - datasource.setDriverClassLoader(MySQLConnector.class.getClassLoader()); + datasource.setDriverClassLoader(getClass().getClassLoader()); datasource.setDriverClassName(driverConfig.getDriverClassName()); datasource.addConnectionProperty("useSSL", String.valueOf(connectorSslConfig.isUseSSL())); if (connectorSslConfig.isUseSSL()) { @@ -146,10 +141,9 @@ public class MySQLConnector extends SQLMetadataConnector // use double-quotes for quoting columns, so we can write SQL that works with most databases datasource.setConnectionInitSqls(ImmutableList.of("SET sql_mode='ANSI_QUOTES'")); - DBI dbi = new DBI(datasource); + this.dbi = new DBI(datasource); log.info("Configured MySQL as metadata storage"); - return dbi; } @Override @@ -258,10 +252,10 @@ public class MySQLConnector extends SQLMetadataConnector } @Nullable - private static Class tryLoadDriverClass(String className, boolean failIfNotFound) + private Class tryLoadDriverClass(String className, boolean failIfNotFound) { try { - return Class.forName(className, false, MySQLConnector.class.getClassLoader()); + return Class.forName(className, false, getClass().getClassLoader()); } catch (ClassNotFoundException e) { if (failIfNotFound) { diff --git a/extensions-core/mysql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/mysql/MySQLConnectorDriverConfig.java b/extensions-core/mysql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/mysql/MySQLConnectorDriverConfig.java index fba20bea1f1..0f6fa03245d 100644 --- a/extensions-core/mysql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/mysql/MySQLConnectorDriverConfig.java +++ b/extensions-core/mysql-metadata-storage/src/main/java/org/apache/druid/metadata/storage/mysql/MySQLConnectorDriverConfig.java @@ -20,25 +20,13 @@ package org.apache.druid.metadata.storage.mysql; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.Strings; import java.util.Objects; public class MySQLConnectorDriverConfig { - public static final String MYSQL_DRIVER = "com.mysql.jdbc.Driver"; - @JsonProperty - private String driverClassName = MYSQL_DRIVER; - - public static MySQLConnectorDriverConfig create(String driverClassName) - { - MySQLConnectorDriverConfig config = new MySQLConnectorDriverConfig(); - if (!Strings.isNullOrEmpty(driverClassName)) { - config.driverClassName = driverClassName; - } - return config; - } + private String driverClassName = "com.mysql.jdbc.Driver"; @JsonProperty public String getDriverClassName() diff --git a/extensions-core/mysql-metadata-storage/src/test/java/org/apache/druid/metadata/storage/mysql/MySQLConnectorDriverConfigTest.java b/extensions-core/mysql-metadata-storage/src/test/java/org/apache/druid/metadata/storage/mysql/MySQLConnectorDriverConfigTest.java index d86fa6a18d2..c1d2e4e1aed 100644 --- a/extensions-core/mysql-metadata-storage/src/test/java/org/apache/druid/metadata/storage/mysql/MySQLConnectorDriverConfigTest.java +++ b/extensions-core/mysql-metadata-storage/src/test/java/org/apache/druid/metadata/storage/mysql/MySQLConnectorDriverConfigTest.java @@ -22,8 +22,6 @@ package org.apache.druid.metadata.storage.mysql; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.Test; -import static org.junit.Assert.assertEquals; - public class MySQLConnectorDriverConfigTest { @Test @@ -35,13 +33,4 @@ public class MySQLConnectorDriverConfigTest .withNonnullFields("driverClassName") .verify(); } - - @Test - public void testCreate() - { - MySQLConnectorDriverConfig config = MySQLConnectorDriverConfig.create(null); - assertEquals(MySQLConnectorDriverConfig.MYSQL_DRIVER, config.getDriverClassName()); - config = MySQLConnectorDriverConfig.create("myDriver"); - assertEquals("myDriver", config.getDriverClassName()); - } }