2015-06-22 45 views
5

我已經使用Automatic Persistence創建了一個緩存,連接到Mysql數據庫。 啓動時將1百萬行填充到該節點中。節點處於PARTITIONED模式apache點燃查詢

當我嘗試使用SQL查詢從該緩存中檢索數據時,它始終返回空數組。 我使用「CacheTypeMetadata」對緩存進行了索引。

請任何人都可以指出我錯過了什麼,或者做錯了。我一直在關注教程,但我無法弄清楚爲什麼我的查詢不能正常工作。

在此先感謝!

  1. 緩存:

    CacheConfiguration CFG = CacheConfigMd5.cache( 「DataMd5Cache」,新JDBCFactory());

  2. DataLoaderMd5Key ::

    公共類Dataloadermd5Key實現Serializable { /** */ 私有靜態最後的serialVersionUID長= 0L;

    /** Value for idClient. */ 
    private int idClient; 
    
    /** Value for clientPropId. */ 
    private String clientPropId; 
    

    ...}

  3. DataLoaderMd5 ::

    公共類DataLoaderMd5實現Serializable { /** */ 私有靜態最後的serialVersionUID長= 0L;

    /** Value for idClient. */ 
    private int idClient; 
    
    /** Value for clientPropId. */ 
    private String clientPropId; 
    
    /** Value for md5. */ 
    private String md5; 
    

    ..}

  4. CacheConfigMd5 ::

    公共靜態CacheConfiguration緩存(字符串名稱,工廠> storeFactory){ 如果(storeFactory == NULL) 拋出新拋出:IllegalArgumentException(「緩存存儲工廠不能爲空。「);

    CacheConfiguration<K, V> ccfg = new CacheConfiguration<>(name); 
    
        ccfg.setCacheStoreFactory(storeFactory); 
        ccfg.setReadThrough(true); 
        ccfg.setWriteThrough(true); 
    
        // Configure cache types. 
        Collection<CacheTypeMetadata> meta = new ArrayList<>(); 
    
        // DataLoaderMd5. 
        CacheTypeMetadata type = new CacheTypeMetadata(); 
    
        meta.add(type); 
    
        type.setDatabaseSchema("abc"); 
        type.setDatabaseTable("dfg"); 
        type.setKeyType(Dataloadermd5Key.class.getName()); 
        type.setValueType(DataLoaderMd5.class.getName()); 
    
        // Key fields for DataLoaderMd5. 
        Collection<CacheTypeFieldMetadata> keys = new ArrayList<>(); 
        keys.add(new CacheTypeFieldMetadata("id_client", Types.INTEGER, "idclient", int.class)); 
        keys.add(new CacheTypeFieldMetadata("client_prop_id", Types.VARCHAR, "clientPropId", String.class)); 
        type.setKeyFields(keys); 
    
        // Value fields for DataLoaderMd5. 
        Collection<CacheTypeFieldMetadata> vals = new ArrayList<>(); 
        vals.add(new CacheTypeFieldMetadata("id_client", Types.INTEGER, "idclient", int.class)); 
        vals.add(new CacheTypeFieldMetadata("client_prop_id", Types.VARCHAR, "clientPropId", String.class)); 
        vals.add(new CacheTypeFieldMetadata("Md5", Types.VARCHAR, "md5", String.class)); 
        type.setValueFields(vals); 
    
        // Query fields for DataLoaderMd5. 
        Map<String, Class<?>> qryFlds = new LinkedHashMap<>(); 
    
        qryFlds.put("idclient", int.class); 
        qryFlds.put("clientPropId", String.class); 
        qryFlds.put("md5", String.class); 
    
        type.setQueryFields(qryFlds); 
    
        // Groups for DataLoaderMd5. 
        Map<String, LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>>> grps = new LinkedHashMap<>(); 
    
        LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>> grpItems = new LinkedHashMap<>(); 
    
        grpItems.put("idclient", new IgniteBiTuple<Class<?>, Boolean>(int.class, false)); 
        grpItems.put("clientPropId", new IgniteBiTuple<Class<?>, Boolean>(String.class, false)); 
    
        grps.put("PRIMARY", grpItems); 
    
        type.setGroups(grps); 
    
        ccfg.setTypeMetadata(meta); 
    
        return ccfg; 
    } 
    
  5. 查詢::

的Ignite點燃= Ignition.start( 「實例/配置/例子-cache.xml」); IgniteCache cache = ignite.cache(CACHE_NAME); Dataloadermd5Key key = new Dataloadermd5Key(); key.setIdClient(98255); key.setClientPropId(「1000008」); SqlQuery qry = 新的SqlQuery(DataLoaderMd5.class,「idClient =?和clientPropId =?」);

// Excecute query System.out.println(「sqlQuery Lookup result ::」+ cache.query(qry).getAll()); System.out.println(「sqlQuery Lookup result ::」+ cache.query(qry.setArgs(key.getIdClient(),key.getClientPropId()))。得到所有());

回答

2

我發現了這個問題。這是因爲我的Ignite版本。 我更新了我的maven版本到1.1.0,並且代碼開始正常工作。

<dependency> 
     <groupId>org.apache.ignite</groupId> 
     <artifactId>ignite-indexing</artifactId> 
     <version>1.1.0-incubating</version> 
    </dependency>