gpt4 book ai didi

java - Apache 点燃 : How to list all tables and all Caches

转载 作者:塔克拉玛干 更新时间:2023-11-01 23:04:11 26 4
gpt4 key购买 nike

有没有办法列出特定缓存中存在的所有表并列出 Apache Ignite 服务器上存在的所有缓存?

--------------------------------更新------------ --------------你好,我正在运行以下代码来了解缓存名称并列出缓存中存在的所有表。该程序列出了服务器上存在的所有缓存名称。但是,表格列表打印为空白集合。同时,示例中的 SQL 查询工作正常。

public static void main(String[] args) throws Exception {
System.out.println("Run Spring example!!");
Ignition.setClientMode(true);
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setIncludeEventTypes( EVTS_CACHE);
cfg.setPeerClassLoadingEnabled(true);
TcpDiscoveryMulticastIpFinder discoveryMulticastIpFinder = new TcpDiscoveryMulticastIpFinder();
Set<String> set = new HashSet<>();

set.add("hostname:47500..47509");

discoveryMulticastIpFinder.setAddresses(set);

TcpDiscoverySpi discoverySpi = new TcpDiscoverySpi();
discoverySpi.setIpFinder(discoveryMulticastIpFinder);

cfg.setDiscoverySpi(discoverySpi);

cfg.setPeerClassLoadingEnabled(true);
cfg.setIncludeEventTypes(EVTS_CACHE);
Ignite ignite = Ignition.start(cfg);

System.out.println("All Available Cache on server : "+ignite.cacheNames());

CacheConfiguration<String, BinaryObject> cacheConfiguration = new CacheConfiguration<>(CACHE_NAME);

Collection<QueryEntity> entities = cacheConfiguration.getQueryEntities();
System.out.println("All available tables in cache : "+entities);

cacheConfiguration.setIndexedTypes(String.class, BinaryObject.class);
//cacheConfiguration.setCacheMode(CacheMode.PARTITIONED);

IgniteCache<String, BinaryObject> cache = ignite.getOrCreateCache(cacheConfiguration).withKeepBinary();

System.out.println();





QueryCursor<List<?>> query = cache.query(new SqlFieldsQuery("select Field1 from table1 where Field1='TEST'"));
List<List<?>> all = query.getAll();
for (List<?> l : all) {
System.out.println(l);
}

}

最佳答案

获取所有缓存名称:Ignite.cacheNames()。然后使用Ignite.cache(String)获取缓存实例。

获取 SQL 表:

CacheConfiguration ccfg = cache.getConfiguration(CacheConfiguration.class);
Collection<QueryEntity> entities = ccfg.getQueryEntities();

每个查询实体代表一个表。

关于java - Apache 点燃 : How to list all tables and all Caches,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43049782/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com