use of javax.cache.Cache.Entry in project ignite by apache.
the class MutateTask method selectGeneByChromsomeCriteria.
/**
* method assumes ChromosomeCriteria is set.
*
* @param k Gene index in Chromosome.
* @return Primary key of Gene
*/
private long selectGeneByChromsomeCriteria(int k) {
List<Gene> genes = new ArrayList();
StringBuffer sbSqlClause = new StringBuffer("_val like '");
sbSqlClause.append("%");
sbSqlClause.append(config.getChromosomeCriteria().getCriteria().get(k));
sbSqlClause.append("%'");
IgniteCache<Long, Gene> cache = ignite.cache(GAGridConstants.GENE_CACHE);
SqlQuery sql = new SqlQuery(Gene.class, sbSqlClause.toString());
try (QueryCursor<Entry<Long, Gene>> cursor = cache.query(sql)) {
for (Entry<Long, Gene> e : cursor) genes.add(e.getValue());
}
int idx = selectRandomIndex(genes.size());
Gene gene = genes.get(idx);
return gene.id();
}
use of javax.cache.Cache.Entry in project ignite by apache.
the class TruncateSelectionTask method getChromosome.
/**
* Retrieve a chromosome
*
* @param key Primary key of chromosome
* @return Chromosome
*/
private Chromosome getChromosome(Long key) {
IgniteCache<Long, Chromosome> cache = ignite.cache(GAGridConstants.POPULATION_CACHE);
StringBuffer sbSqlClause = new StringBuffer();
sbSqlClause.append("_key IN (");
sbSqlClause.append(key);
sbSqlClause.append(")");
Chromosome chromosome = null;
SqlQuery sql = new SqlQuery(Chromosome.class, sbSqlClause.toString());
try (QueryCursor<Entry<Long, Chromosome>> cursor = cache.query(sql)) {
for (Entry<Long, Chromosome> e : cursor) chromosome = (e.getValue());
}
return chromosome;
}
use of javax.cache.Cache.Entry in project ignite by apache.
the class GAGridUtils method getGenesForChromosome.
/**
* @param ignite Ignite
* @param chromosome Chromosome
* @return List of Genes
*/
public static List<Gene> getGenesForChromosome(Ignite ignite, Chromosome chromosome) {
List<Gene> genes = new ArrayList();
IgniteCache<Long, Gene> cache = ignite.cache(GAGridConstants.GENE_CACHE);
StringBuffer sbSqlClause = new StringBuffer();
sbSqlClause.append("_key IN ");
String sqlInClause = Arrays.toString(chromosome.getGenes());
sqlInClause = sqlInClause.replace("[", "(");
sqlInClause = sqlInClause.replace("]", ")");
sbSqlClause.append(sqlInClause);
SqlQuery sql = new SqlQuery(Gene.class, sbSqlClause.toString());
try (QueryCursor<Entry<Long, Gene>> cursor = cache.query(sql)) {
for (Entry<Long, Gene> e : cursor) genes.add(e.getValue());
}
return genes;
}
use of javax.cache.Cache.Entry in project ignite by apache.
the class GAGridUtils method getChromosomes.
/**
* Retrieve chromosomes
*
* @param ignite Ignite
* @param query Sql
* @return List of Chromosomes
*/
public static List<Chromosome> getChromosomes(Ignite ignite, String query) {
List<Chromosome> chromosomes = new ArrayList();
IgniteCache<Long, Chromosome> populationCache = ignite.getOrCreateCache(PopulationCacheConfig.populationCache());
SqlQuery sql = new SqlQuery(Chromosome.class, query);
try (QueryCursor<Entry<Long, Chromosome>> cursor = populationCache.query(sql)) {
for (Entry<Long, Chromosome> e : cursor) chromosomes.add(e.getValue());
}
return chromosomes;
}
use of javax.cache.Cache.Entry in project camel by apache.
the class IgniteCacheTest method testQuery.
@Test
public void testQuery() {
IgniteCache<String, String> cache = ignite().getOrCreateCache("testcache1");
Set<String> keys = new HashSet<>();
for (int i = 0; i < 100; i++) {
cache.put("k" + i, "v" + i);
keys.add("k" + i);
}
Query<Entry<String, String>> query = new ScanQuery<String, String>(new IgniteBiPredicate<String, String>() {
private static final long serialVersionUID = 1L;
@Override
public boolean apply(String key, String value) {
return Integer.parseInt(key.replace("k", "")) >= 50;
}
});
List results = template.requestBodyAndHeader("ignite:cache:testcache1?operation=QUERY", keys, IgniteConstants.IGNITE_CACHE_QUERY, query, List.class);
assert_().that(results.size()).isEqualTo(50);
}
Aggregations