ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tusharnakra <tusharna...@hotmail.com>
Subject How to load 2 tables in a cache
Date Fri, 08 Apr 2016 19:08:39 GMT
I have two tables department (dept_id and dept) and employee(emp_id, dept_id,
firstname, lastname) in a database that I want to load into the cache. I
used the schema import tool and it generated the CacheConfig.java,
DepartmentKey.java, Department.java, Employee.java and EmployeeKey.java
files. Now Now how do I load the cache with both these tables? 

Here's the snippet:

  private static class MySQLDemoStoreFactory<K, V> extends
CacheJdbcPojoStoreFactory<K, V> {
         //{@inheritDoc} 
         @Override public CacheJdbcPojoStore<K, V> create() {
            
            
            MysqlDataSource dataSource = new MysqlDataSource(); 
            dataSource.setURL("jdbc:mysql://localhost/DB"); 
            dataSource.setUser("root"); 
            dataSource.setPassword("pass"); 
            setDataSource(dataSource);
            return super.create();
			
        }
    	
    }

then in main, to load the cache: 

  try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml"))
{
            // Configure cache store.
            CacheConfiguration<EmployeeKey, Employee> cfg =
                CacheConfig.cache("EmpCache", new
MySQLDemoStoreFactory<EmployeeKey, Employee>());

            try (IgniteCache<EmployeeKey, Employee> cache =
ignite.getOrCreateCache(cfg)) {
                // Preload cache from database.
                preload(cache);


This will just load it with the Employee table, right? How do I load it with
the Department and the Employee table both?



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/How-to-load-2-tables-in-a-cache-tp4026.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Mime
View raw message