Search in sources :

Example 6 with MysqlDataSource

use of com.mysql.cj.jdbc.MysqlDataSource in project brave by openzipkin.

the class ITTracingQueryInterceptor method init.

@Before
public void init() throws SQLException {
    StringBuilder url = new StringBuilder("jdbc:mysql://");
    url.append(envOr("MYSQL_HOST", "127.0.0.1"));
    url.append(":").append(envOr("MYSQL_TCP_PORT", 3306));
    String db = envOr("MYSQL_DB", null);
    if (db != null)
        url.append("/").append(db);
    url.append("?queryInterceptors=").append(TracingQueryInterceptor.class.getName());
    if (exceptionsTraced) {
        url.append("&exceptionInterceptors=").append(TracingExceptionInterceptor.class.getName());
    }
    url.append("&zipkinServiceName=").append("myservice");
    url.append("&serverTimezone=").append("UTC");
    MysqlDataSource dataSource = new MysqlDataSource();
    dataSource.setUrl(url.toString());
    dataSource.setUser(System.getenv("MYSQL_USER"));
    assumeTrue("Minimally, the environment variable MYSQL_USER must be set", dataSource.getUser() != null);
    dataSource.setPassword(envOr("MYSQL_PASS", ""));
    connection = dataSource.getConnection();
    spans.clear();
}
Also used : MysqlDataSource(com.mysql.cj.jdbc.MysqlDataSource) Before(org.junit.Before)

Example 7 with MysqlDataSource

use of com.mysql.cj.jdbc.MysqlDataSource in project knox by apache.

the class JDBCUtilsTest method shouldReturnMySqlDataSource.

@Test
public void shouldReturnMySqlDataSource() throws Exception {
    final GatewayConfig gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class);
    EasyMock.expect(gatewayConfig.getDatabaseType()).andReturn(JDBCUtils.MYSQL_DB_TYPE).anyTimes();
    final AliasService aliasService = EasyMock.createNiceMock(AliasService.class);
    EasyMock.expect(aliasService.getPasswordFromAliasForGateway(EasyMock.anyString())).andReturn(null).anyTimes();
    EasyMock.replay(gatewayConfig, aliasService);
    assertTrue(JDBCUtils.getDataSource(gatewayConfig, aliasService) instanceof MysqlDataSource);
}
Also used : AliasService(org.apache.knox.gateway.services.security.AliasService) MysqlDataSource(com.mysql.cj.jdbc.MysqlDataSource) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 8 with MysqlDataSource

use of com.mysql.cj.jdbc.MysqlDataSource in project knox by apache.

the class JDBCUtilsTest method testMysqlDataSourceShouldHaveProperConnectionProperties.

@Test
public void testMysqlDataSourceShouldHaveProperConnectionProperties() throws Exception {
    GatewayConfig gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class);
    AliasService aliasService = EasyMock.createNiceMock(AliasService.class);
    EasyMock.expect(gatewayConfig.getDatabaseType()).andReturn(JDBCUtils.MYSQL_DB_TYPE).anyTimes();
    EasyMock.expect(gatewayConfig.getDatabaseHost()).andReturn("localhost").anyTimes();
    EasyMock.expect(gatewayConfig.getDatabasePort()).andReturn(5432).anyTimes();
    EasyMock.expect(gatewayConfig.getDatabaseName()).andReturn("sampleDatabase");
    EasyMock.expect(aliasService.getPasswordFromAliasForGateway(JDBCUtils.DATABASE_USER_ALIAS_NAME)).andReturn("user".toCharArray()).anyTimes();
    EasyMock.expect(aliasService.getPasswordFromAliasForGateway(JDBCUtils.DATABASE_PASSWORD_ALIAS_NAME)).andReturn("password".toCharArray()).anyTimes();
    EasyMock.replay(gatewayConfig, aliasService);
    MysqlDataSource dataSource = (MysqlDataSource) JDBCUtils.getDataSource(gatewayConfig, aliasService);
    assertEquals("localhost", dataSource.getServerName());
    assertEquals(5432, dataSource.getPortNumber());
    assertEquals("sampleDatabase", dataSource.getDatabaseName());
    assertEquals("user", dataSource.getUser());
    assertEquals("password", dataSource.getPassword());
    assertTrue(dataSource.getUseSSL());
    EasyMock.verify(gatewayConfig);
}
Also used : AliasService(org.apache.knox.gateway.services.security.AliasService) MysqlDataSource(com.mysql.cj.jdbc.MysqlDataSource) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Test(org.junit.Test)

Example 9 with MysqlDataSource

use of com.mysql.cj.jdbc.MysqlDataSource in project steve by RWTH-i5-IDSG.

the class BeanConfiguration method initDataSource.

/**
 * https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
 */
private void initDataSource() {
    MysqlDataSource ds = new MysqlDataSource();
    // set standard params
    ds.setServerName(CONFIG.getDb().getIp());
    ds.setPort(CONFIG.getDb().getPort());
    ds.setDatabaseName(CONFIG.getDb().getSchema());
    ds.setUser(CONFIG.getDb().getUserName());
    ds.setPassword(CONFIG.getDb().getPassword());
    // set non-standard params
    ds.getModifiableProperty(PropertyDefinitions.PNAME_cachePrepStmts).setValue(true);
    ds.getModifiableProperty(PropertyDefinitions.PNAME_prepStmtCacheSize).setValue(250);
    ds.getModifiableProperty(PropertyDefinitions.PNAME_prepStmtCacheSqlLimit).setValue(2048);
    ds.getModifiableProperty(PropertyDefinitions.PNAME_characterEncoding).setValue("utf8");
    ds.getModifiableProperty(PropertyDefinitions.PNAME_serverTimezone).setValue("UTC");
    HikariConfig hc = new HikariConfig();
    hc.setDataSource(ds);
    dataSource = new HikariDataSource(hc);
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) MysqlDataSource(com.mysql.cj.jdbc.MysqlDataSource) HikariConfig(com.zaxxer.hikari.HikariConfig)

Example 10 with MysqlDataSource

use of com.mysql.cj.jdbc.MysqlDataSource in project spring-data-jdbc by spring-projects.

the class MySqlDataSourceConfiguration method createRootDataSource.

private DataSource createRootDataSource() {
    MysqlDataSource dataSource = new MysqlDataSource();
    dataSource.setUrl(MYSQL_CONTAINER.getJdbcUrl());
    dataSource.setUser("root");
    dataSource.setPassword(MYSQL_CONTAINER.getPassword());
    dataSource.setDatabaseName(MYSQL_CONTAINER.getDatabaseName());
    return dataSource;
}
Also used : MysqlDataSource(com.mysql.cj.jdbc.MysqlDataSource)

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