Search in sources :

Example 1 with CacheJdbcBlobStoreFactory

use of org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStoreFactory 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)

Aggregations

MysqlDataSource (com.mysql.cj.jdbc.MysqlDataSource)1 Ignite (org.apache.ignite.Ignite)1 CacheJdbcBlobStoreFactory (org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStoreFactory)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1