java - 实现cacheStore时没有ID时如何加载数据来点燃缓存?

标签 java oracle ignite in-memory-database

我正在使用 ignite 缓存,我想缓存一个 id 不相关的 View ,因此当没有 id 时,实现 loadCache 对我来说似乎有些棘手!!!

我应该如何更新下面的示例

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); 这部分是我的逻辑问题,我的 View 没有 ID

最佳答案

您需要一些唯一的 ID 来在 Ignite 中存储数据。如果实际数据中没有合适的内容,您的选择是:

  • UUID.randomUUID()
  • 简单计数器 (id++) 或 LongAdder/AtomicLong - 仅当您从单个节点加载时才有效
  • IgniteAtomicSequence - 适用于整个集群

关于java - 实现cacheStore时没有ID时如何加载数据来点燃缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58910407/

相关文章:

java - 无法使用 Stax 中的 XMLEventReader 检查 XML 中的 CDATA

sql - 直观地概述Oracle SQL数据库的工具

c# - Linq 实体分组依据(外部应用) "oracle 11.2.0.3.0 does not support apply"

java - Apache 点燃: insert SQL with composite key via PreapredStatement

java - 以编程方式或通过命令行分析 SSL 证书

java - 将缓冲图像移动到特定坐标

java - 网络服务器打不开php文件

ORACLE 10.2 Pro*C 预编译器不读取头文件

spring - 由 : java. lang.ClassNotFoundException : org. apache.ignite.internal.util.spring.IgniteSpringHelperImpl 引起

apache-spark - Apache Ignite 和 Tachyon 有什么区别