2015-06-22 25 views
5

Utworzyłem cache za pomocą Automatic Persistence, łącząc się z bazą danych MySQL. Po uruchomieniu do tego węzła wpisuje się 1 milion wierszy. Węzeł jest w trybie PARTYCYJNYapache ignite query

Kiedy próbuję pobrać dane z tej pamięci podręcznej za pomocą zapytań SQL, zawsze zwraca pustą tablicę. Zindeksowałem pamięć podręczną za pomocą "CacheTypeMetadata".

Czy ktoś może wskazać, co straciłem lub zrobiłam niepoprawnie. Śledziłem tutoriale, ale nie mogę się domyślić, dlaczego moje zapytanie nie działa poprawnie.

Z góry dziękuję!

  1. skrzynki:

    CacheConfiguration cfg = CacheConfigMd5.cache ("DataMd5Cache" nowy JDBCFactory());

  2. DataLoaderMd5Key ::

    public class Dataloadermd5Key implementuje Serializable { /** */private static final długo serialVersionUID = 0L;

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

    ...}

  3. DataLoaderMd5 ::

    public class DataLoaderMd5 implementuje Serializable { /** */private static final długo serialVersionUID = 0L;

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

    ..}

  4. CacheConfigMd5 ::

    public static CacheConfiguration cache (String name, Fabryka> storeFactory) { if (storeFactory == null) rzut nowy IllegalArgumentException ("Cache Fabryka składowania nie może mieć wartości NULL. ");

    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; 
    } 
    
    1. Zapytanie ::

    Wzniecam zapalić = Ignition.start ("Przykłady/konfiguracji/PRZYKŁAD cache.xml"); IgniteCache cache = ignite.cache (CACHE_NAME); Klucz Dataloadermd5Key = nowy Dataloadermd5Key(); key.setIdClient (98255); key.setClientPropId ("1000008");

    SqlQuery qry = nowy SqlQuery (DataLoaderMd5.class, "idClient =? And clientPropId =?");

    // Wywołanie zapytania System.out.println ("Wynik wyszukiwania sqlQuery ::" + cache.query (qry) .getAll());

    System.out.println ("Wynik wyszukiwania sqlQuery ::" + cache.query (qry.setArgs (key.getIdClient(), key.getClientPropId())).getAll());

Odpowiedz

2

Dowiedziałem się o problemie. To z powodu mojej wersji Ignite. Zaktualizowałem wersję na moim komputerze do wersji 1.1.0, a kod zaczął działać poprawnie.

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