java - 实现cacheStore时没有ID时如何加载数据以点燃缓存?
问题描述
我正在使用 ignite 缓存,我想缓存一个 id 不相关的视图,所以loadCache
当没有 id 时,实现对我来说似乎有点棘手!!!
我应该如何更新下面的示例
public class CacheJdbcPersonStore extends CacheStoreAdapter<Long, Person> {
...
// This method is called whenever "IgniteCache.loadCache()" or
// "IgniteCache.localLoadCache()" methods are called.
@Override public void loadCache(IgniteBiInClosure<Long, Person> clo, Object... args) {
if (args == null || args.length == 0 || args[0] == null)
throw new CacheLoaderException("Expected entry count parameter is not provided.");
final int entryCnt = (Integer)args[0];
Connection conn = null;
try (Connection conn = connection()) {
try (PreparedStatement st = conn.prepareStatement("select * from PERSONS")) {
try (ResultSet rs = st.executeQuery()) {
int cnt = 0;
while (cnt < entryCnt && rs.next()) {
Person person = new Person(rs.getLong(1), rs.getString(2), rs.getString(3));
clo.apply(person.getId(), person);
cnt++;
}
}
}
}
catch (SQLException e) {
throw new CacheLoaderException("Failed to load values from cache store.", e);
}
}
...
}
clo.apply(person.getId(), person);
这部分是我逻辑中的问题我的视图没有 ID
解决方案
您需要一些唯一的 ID 来在 Ignite 中存储数据。如果实际数据中没有合适的内容,您的选择是:
UUID.randomUUID()
- 简单计数器 (
id++
) 或LongAdder
/AtomicLong
- 仅当您从单个节点加载时才有效 IgniteAtomicSequence
- 跨整个集群工作
推荐阅读
- ios - 如何为 Native Base Datepicker 添加确认和取消按钮
- python - 如何使用 Digi XBee Python 模块向远程 XBee 发送 API 帧?
- excel - 将日期添加到选项卡
- .htaccess - .htaccess 限制对根级页面的访问。我该如何阻止这个?
- python - python - 如何将字典与一个键合并到python中的另一个键字典?
- html - Css交换滚动条问题
- python - 将许多文档插入空集合中,如果 mongodb 已经存在具有相同键的文档,则更新
- perforce - 如何通过命令行从 perforce 中的其他工作区获取修订?
- java - Rest Get:如何在 URL 的查询参数中添加“带有查询参数的 URL”?
- azure-data-factory - Azure 数据工厂复制数据 - 无法将“System.String”转换为目标类型“Microsoft.Xrm.Sdk.EntityReference”