use of com.mysql.cj.jdbc.MysqlDataSource in project knox by apache.
the class JDBCUtils method createMySqlDataSource.
private static DataSource createMySqlDataSource(GatewayConfig gatewayConfig, AliasService aliasService) throws AliasServiceException, SQLException {
MysqlDataSource dataSource = new MysqlDataSource();
if (gatewayConfig.getDatabaseConnectionUrl() != null) {
dataSource.setUrl(gatewayConfig.getDatabaseConnectionUrl());
} else {
dataSource.setDatabaseName(gatewayConfig.getDatabaseName());
dataSource.setServerName(gatewayConfig.getDatabaseHost());
dataSource.setPortNumber(gatewayConfig.getDatabasePort());
dataSource.setUser(getDatabaseUser(aliasService));
dataSource.setPassword(getDatabasePassword(aliasService));
configureMysqlSsl(gatewayConfig, aliasService, dataSource);
}
return dataSource;
}
use of com.mysql.cj.jdbc.MysqlDataSource in project knox by apache.
the class JDBCUtilsTest method testGetMySqlDatasourceFromJdbcConnectionUrl.
@Test
public void testGetMySqlDatasourceFromJdbcConnectionUrl() throws Exception {
String connectionUrl = "jdbc:mysql://mysql_host:1234/testDb?user=user&password=secret&ssl=true&sslmode=verify-ca&sslrootcert=/var/lib/knox/gateway/conf/postgresql/root.crt";
GatewayConfig gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class);
EasyMock.expect(gatewayConfig.getDatabaseType()).andReturn(JDBCUtils.MYSQL_DB_TYPE).anyTimes();
EasyMock.expect(gatewayConfig.getDatabaseConnectionUrl()).andReturn(connectionUrl).anyTimes();
EasyMock.replay(gatewayConfig);
MysqlDataSource dataSource = (MysqlDataSource) JDBCUtils.getDataSource(gatewayConfig, null);
assertEquals(connectionUrl, dataSource.getUrl());
EasyMock.verify(gatewayConfig);
}
Aggregations