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();
}
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);
}
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);
}
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);
}
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;
}
Aggregations