Search in sources :

Example 1 with MysqlDataSource

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);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) MysqlDataSource(com.mysql.cj.jdbc.MysqlDataSource) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 2 with MysqlDataSource

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[]
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheJdbcBlobStoreFactory(org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStoreFactory) MysqlDataSource(com.mysql.cj.jdbc.MysqlDataSource) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 3 with MysqlDataSource

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[]
}
Also used : JdbcType(org.apache.ignite.cache.store.jdbc.JdbcType) QueryEntity(org.apache.ignite.cache.QueryEntity) MysqlDataSource(com.mysql.cj.jdbc.MysqlDataSource) DataSource(javax.sql.DataSource) LinkedHashMap(java.util.LinkedHashMap) MySQLDialect(org.apache.ignite.cache.store.jdbc.dialect.MySQLDialect) CacheJdbcPojoStoreFactory(org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) MysqlDataSource(com.mysql.cj.jdbc.MysqlDataSource) JdbcTypeField(org.apache.ignite.cache.store.jdbc.JdbcTypeField) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) HashSet(java.util.HashSet)

Example 4 with MysqlDataSource

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

Example 5 with MysqlDataSource

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

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