2017-03-27 11 views
1

特定のキャッシュに存在するすべてのテーブルをリストし、Apache Igniteサーバー上にあるすべてのキャッシュをリストする方法はありますか?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); 
      } 

    } 

答えて

2

キャッシュ名はすべてIgnite.cacheNames()です。次に、Ignite.cache(String)を使用してキャッシュインスタンスを取得します。

は、SQLのテーブルを取得します:

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

各クエリエンティティはテーブルを表します。

+0

こんにちは@PavelTupitsyn、私を助けてくれてありがとう:あなたがここに見つけることができるSHOWコマンドについて

QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("SHOW TABLES FROM \""+CACHE_NAME+"\"")); for (List<?> row : cursor) { System.out.println(row.get(0)); } 

詳細:すべてのテーブル名を取得するためには、SHOW TABLESコマンドを使用することができます。 Ignite.cacheNames()は正常に動作しています。しかし、ccfg.getQueryEntities()は私に空白のコレクションを与えて、テーブルに "Select文"を実行してテーブルをキャッシュに入れることができます。おかげで – Sushil

+0

あなたが実行する選択ステートメントは何ですか?どのようにキャッシュを開始しますか? –

+0

基本的には、Selectステートメントを実行する前に、テーブルがキャッシュに存在することを確認します。 – Sushil

0

Ignite.cacheNames()を使用してすべてのキャッシュ名を取得できます。 http://www.h2database.com/html/grammar.html#show

+3

私のIgnite 2.0で「SHOW TABLES」アプローチを試みたときに、私は次の例外を受け取る: 'によって引き起こさ:クラスorg.apache.ignite.IgniteException:サポートされていないクエリ.ignite.internal.processors.query.has.sql.GridSqlQueryParser.assert0(GridSqlQueryParser.java:1198) \t at org.apache.ignite.internal.processors.query.h2.sql.GridSqlQueryParser.parseTable(GridSqlQueryParser.java: 454) \t at org.apache.ignite.internal.processors.query.h2.sql.GridSqlQueryParser.parseTableFilter(GridSqlQueryParser.java:407) ' – drobin

関連する問題