【发布时间】:2016-04-10 22:43:57
【问题描述】:
我想加载到缓存中的数据库中有两个表部门(dept_id 和部门)和雇员(emp_id,dept_id,名字,姓氏)。我使用了模式导入工具,它生成了 CacheConfig.java、DepartmentKey.java、Department.java、Employee.java 和 EmployeeKey.java 文件。现在现在我如何用这两个表加载缓存?
这是sn-p:
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();
}
}
然后在main中,加载缓存:
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);
这只会将它与 Employee 表一起加载,对吗?如何同时加载 Department 和 Employee 表?
【问题讨论】:
标签: java database caching gridgain