Search in sources :

Example 11 with MysqlDataSource

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;
}
Also used : MysqlDataSource(com.mysql.cj.jdbc.MysqlDataSource)

Example 12 with MysqlDataSource

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);
}
Also used : MysqlDataSource(com.mysql.cj.jdbc.MysqlDataSource) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Aggregations

MysqlDataSource (com.mysql.cj.jdbc.MysqlDataSource)12 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)3 Test (org.junit.Test)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 AliasService (org.apache.knox.gateway.services.security.AliasService)2 Before (org.junit.Before)2 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Properties (java.util.Properties)1 DataSource (javax.sql.DataSource)1 Ignite (org.apache.ignite.Ignite)1 QueryEntity (org.apache.ignite.cache.QueryEntity)1 CacheJdbcBlobStoreFactory (org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStoreFactory)1