use of com.mysql.cj.jdbc.MysqlDataSource in project BoltBot by DiscordBolt.
the class MySQL method init.
private static void init() {
OutputStream output = null;
try {
if (!propertiesPath.toFile().exists()) {
Properties prop = new Properties();
output = new FileOutputStream(propertiesPath.toFile());
prop.setProperty("USERNAME", "root");
prop.setProperty("PASSWORD", "password");
prop.setProperty("HOST", "localhost");
prop.setProperty("DATABASE", "BoltBot");
prop.store(output, "BoltBot MySQL Configuration");
}
} catch (IOException e) {
Logger.error(e.getMessage());
Logger.debug(e);
} finally {
if (output != null) {
try {
output.close();
} catch (IOException e) {
Logger.error("Could not close MySQL Properties file.");
Logger.debug(e);
}
}
}
try {
Properties props = new Properties();
props.load(new FileInputStream(propertiesPath.toFile()));
dataSource = new MysqlDataSource();
dataSource.setUser(props.getProperty("USERNAME"));
dataSource.setPassword(props.getProperty("PASSWORD"));
dataSource.setServerName(props.getProperty("HOST"));
dataSource.setDatabaseName(props.getProperty("DATABASE"));
} catch (IOException e) {
Logger.error(e.getMessage());
Logger.debug(e);
}
}
use of com.mysql.cj.jdbc.MysqlDataSource in project ignite by apache.
the class ExternalStorage method cacheJdbcBlobStoreExample.
// end::person[]
public static void cacheJdbcBlobStoreExample() {
// tag::blob1[]
IgniteConfiguration igniteCfg = new IgniteConfiguration();
CacheConfiguration<Integer, Person> personCacheCfg = new CacheConfiguration<>();
personCacheCfg.setName("PersonCache");
CacheJdbcBlobStoreFactory<Integer, Person> cacheStoreFactory = new CacheJdbcBlobStoreFactory<>();
cacheStoreFactory.setUser("USER_NAME");
MysqlDataSource mysqlDataSrc = new MysqlDataSource();
mysqlDataSrc.setURL("jdbc:mysql://[host]:[port]/[database]");
mysqlDataSrc.setUser("USER_NAME");
mysqlDataSrc.setPassword("PASSWORD");
cacheStoreFactory.setDataSource(mysqlDataSrc);
personCacheCfg.setCacheStoreFactory(cacheStoreFactory);
personCacheCfg.setWriteThrough(true);
personCacheCfg.setReadThrough(true);
igniteCfg.setCacheConfiguration(personCacheCfg);
// end::blob1[]
Ignite ignite = Ignition.start(igniteCfg);
// tag::blob2[]
// Load data from person table into PersonCache.
IgniteCache<Integer, Person> personCache = ignite.cache("PersonCache");
personCache.loadCache(null);
// end::blob2[]
}
use of com.mysql.cj.jdbc.MysqlDataSource in project ignite by apache.
the class ExternalStorage method cacheJdbcPojoStoreExample.
public static void cacheJdbcPojoStoreExample() {
// tag::pojo[]
IgniteConfiguration igniteCfg = new IgniteConfiguration();
CacheConfiguration<Integer, Person> personCacheCfg = new CacheConfiguration<>();
personCacheCfg.setName("PersonCache");
personCacheCfg.setCacheMode(CacheMode.PARTITIONED);
personCacheCfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
personCacheCfg.setReadThrough(true);
personCacheCfg.setWriteThrough(true);
CacheJdbcPojoStoreFactory<Integer, Person> factory = new CacheJdbcPojoStoreFactory<>();
factory.setDialect(new MySQLDialect());
factory.setDataSourceFactory((Factory<DataSource>) () -> {
MysqlDataSource mysqlDataSrc = new MysqlDataSource();
mysqlDataSrc.setURL("jdbc:mysql://[host]:[port]/[database]");
mysqlDataSrc.setUser("YOUR_USER_NAME");
mysqlDataSrc.setPassword("YOUR_PASSWORD");
return mysqlDataSrc;
});
JdbcType personType = new JdbcType();
personType.setCacheName("PersonCache");
personType.setKeyType(Integer.class);
personType.setValueType(Person.class);
// Specify the schema if applicable
// personType.setDatabaseSchema("MY_DB_SCHEMA");
personType.setDatabaseTable("PERSON");
personType.setKeyFields(new JdbcTypeField(java.sql.Types.INTEGER, "id", Integer.class, "id"));
personType.setValueFields(new JdbcTypeField(java.sql.Types.INTEGER, "id", Integer.class, "id"));
personType.setValueFields(new JdbcTypeField(java.sql.Types.VARCHAR, "name", String.class, "name"));
factory.setTypes(personType);
personCacheCfg.setCacheStoreFactory(factory);
QueryEntity qryEntity = new QueryEntity();
qryEntity.setKeyType(Integer.class.getName());
qryEntity.setValueType(Person.class.getName());
qryEntity.setKeyFieldName("id");
Set<String> keyFields = new HashSet<>();
keyFields.add("id");
qryEntity.setKeyFields(keyFields);
LinkedHashMap<String, String> fields = new LinkedHashMap<>();
fields.put("id", "java.lang.Integer");
fields.put("name", "java.lang.String");
qryEntity.setFields(fields);
personCacheCfg.setQueryEntities(Collections.singletonList(qryEntity));
igniteCfg.setCacheConfiguration(personCacheCfg);
// end::pojo[]
}
use of com.mysql.cj.jdbc.MysqlDataSource in project spring-data-jdbc by spring-projects.
the class MySqlDataSourceConfiguration method createDataSource.
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.testing.DataSourceConfiguration#createDataSource()
*/
@Override
protected DataSource createDataSource() {
if (MYSQL_CONTAINER == null) {
MySQLContainer<?> container = new MySQLContainer<>("mysql:8.0.24").withUsername("test").withPassword("test").withConfigurationOverride("");
container.start();
MYSQL_CONTAINER = container;
}
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUrl(MYSQL_CONTAINER.getJdbcUrl());
dataSource.setUser("root");
dataSource.setPassword(MYSQL_CONTAINER.getPassword());
dataSource.setDatabaseName(MYSQL_CONTAINER.getDatabaseName());
return dataSource;
}
use of com.mysql.cj.jdbc.MysqlDataSource in project brave by openzipkin.
the class ITTracingStatementInterceptor 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("?statementInterceptors=").append(TracingStatementInterceptor.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();
}
Aggregations