本文整理汇总了Java中org.apache.ignite.IgniteCache.query方法的典型用法代码示例。如果您正苦于以下问题:Java IgniteCache.query方法的具体用法?Java IgniteCache.query怎么用?Java IgniteCache.query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ignite.IgniteCache
的用法示例。
在下文中一共展示了IgniteCache.query方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: selectGeneByChromsomeCriteria
import org.apache.ignite.IgniteCache; //导入方法依赖的package包/类
/**
* method assumes ChromosomeCriteria is set.
*
* @param k
* - gene index in Chromosome.
* @return
*/
private long selectGeneByChromsomeCriteria(int k) {
List<Gene> genes = new ArrayList();
StringBuffer sbSqlClause = new StringBuffer("_val like '");
sbSqlClause.append("%");
sbSqlClause.append(config.getChromosomeCritiera().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();
}
示例2: getChromosomes
import org.apache.ignite.IgniteCache; //导入方法依赖的package包/类
/**
* Retrieve chromosomes
*
* @param ignite
* @param query
* @return
*/
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;
}
示例3: getGenesForChromosome
import org.apache.ignite.IgniteCache; //导入方法依赖的package包/类
/**
*
* @param ignite
* @param chromosome
* @return List<Gene>
*/
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;
}
示例4: selectGeneByChromsomeCriteria
import org.apache.ignite.IgniteCache; //导入方法依赖的package包/类
/**
* method assumes ChromosomeCriteria is set.
*
* @param k - gene index in Chromosome.
*
* @return long
*/
private long selectGeneByChromsomeCriteria(int k) {
List<Gene> genes = new ArrayList();
StringBuffer sbSqlClause = new StringBuffer("_val like '");
sbSqlClause.append("%");
sbSqlClause.append(config.getChromosomeCritiera().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();
}
示例5: getChromosome
import org.apache.ignite.IgniteCache; //导入方法依赖的package包/类
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;
}
示例6: executeWithHints
import org.apache.ignite.IgniteCache; //导入方法依赖的package包/类
private Iterable<List<?>> executeWithHints(IgniteCache<Object, BinaryObject> cache, SqlFieldsQuery sqlQuery, QueryHints hints) {
Iterable<List<?>> result;
if ( hints.isLocal() ) {
if ( !provider.isClientMode() ) {
sqlQuery.setLocal( true );
}
}
if ( hints.isAffinityRun() ) {
result = provider.affinityCall( cache.getName(), hints.getAffinityKey(), sqlQuery );
}
else {
result = cache.query( sqlQuery );
}
return result;
}
示例7: getNumberOfAssociations
import org.apache.ignite.IgniteCache; //导入方法依赖的package包/类
@Override
public long getNumberOfAssociations(SessionFactory sessionFactory) {
int associationCount = 0;
IgniteDatastoreProvider datastoreProvider = getProvider( sessionFactory );
for ( CollectionPersister collectionPersister : ( (SessionFactoryImplementor) sessionFactory ).getCollectionPersisters().values() ) {
AssociationKeyMetadata associationKeyMetadata = ( (OgmCollectionPersister) collectionPersister ).getAssociationKeyMetadata();
if ( associationKeyMetadata.getAssociationKind() == AssociationKind.ASSOCIATION ) {
IgniteCache<Object, BinaryObject> associationCache = getAssociationCache( sessionFactory, associationKeyMetadata );
StringBuilder query = new StringBuilder( "SELECT " )
.append( StringHelper.realColumnName( associationKeyMetadata.getColumnNames()[0] ) )
.append( " FROM " ).append( associationKeyMetadata.getTable() );
SqlFieldsQuery sqlQuery = datastoreProvider.createSqlFieldsQueryWithLog( query.toString(), null );
Iterable<List<?>> queryResult = associationCache.query( sqlQuery );
Set<Object> uniqs = new HashSet<>();
for ( List<?> row : queryResult ) {
Object value = row.get( 0 );
if ( value != null ) {
uniqs.add( value );
}
}
associationCount += uniqs.size();
}
}
return associationCount;
}
示例8: getMostPopulatedCities
import org.apache.ignite.IgniteCache; //导入方法依赖的package包/类
private static void getMostPopulatedCities(IgniteCache countryCache) {
SqlFieldsQuery query = new SqlFieldsQuery(
"SELECT name, population FROM country " +
"ORDER BY population DESC LIMIT 10");
FieldsQueryCursor<List<?>> cursor = countryCache.query(query);
Iterator<List<?>> iterator = cursor.iterator();
System.out.println();
System.out.println(">>> 10 Most Populated Cities:");
while (iterator.hasNext()) {
List row = iterator.next();
System.out.println(" >>> " + row.get(1) + " people live in " + row.get(0));
}
}
示例9: getTopCitiesInThreeCountries
import org.apache.ignite.IgniteCache; //导入方法依赖的package包/类
private static void getTopCitiesInThreeCountries(IgniteCache countryCache) {
SqlFieldsQuery query = new SqlFieldsQuery(
"SELECT country.name, city.name, MAX(city.population) as max_pop FROM country " +
"JOIN city ON city.countrycode = country.code " +
"WHERE country.code IN ('USA','RUS','CHN') " +
"GROUP BY country.name, city.name ORDER BY max_pop DESC LIMIT 3");
FieldsQueryCursor<List<?>> cursor = countryCache.query(query);
Iterator<List<?>> iterator = cursor.iterator();
System.out.println();
System.out.println(">>> 3 Most Populated Cities in US, RUS and CHN:");
while (iterator.hasNext()) {
List row = iterator.next();
System.out.println(" >>> " + row.get(2) + " people live in " + row.get(1) + ", " + row.get(0));
}
}
示例10: getGenesInOrderForChromosome
import org.apache.ignite.IgniteCache; //导入方法依赖的package包/类
/**
*
* Retrieve genes in order
*
* @param ignite
* @param chromosome
* @return List<Gene>
*/
public static List<Gene> getGenesInOrderForChromosome(Ignite ignite, Chromosome chromosome) {
List<Gene> genes = new ArrayList();
IgniteCache<Long, Gene> cache = ignite.cache(GAGridConstants.GENE_CACHE);
long[] primaryKeys = chromosome.getGenes();
for (int k =0; k< primaryKeys.length; k++)
{
StringBuffer sbSqlClause = new StringBuffer();
sbSqlClause.append("_key IN ");
sbSqlClause.append("(");
sbSqlClause.append(primaryKeys[k]);
sbSqlClause.append(")");
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;
}
示例11: calculateAverageFitness
import org.apache.ignite.IgniteCache; //导入方法依赖的package包/类
/**
* Calculate average fitness value
*
* @return Double
*/
private Double calculateAverageFitness() {
double avgFitnessScore = 0;
IgniteCache<Long, Gene> cache = ignite.cache(GAGridConstants.POPULATION_CACHE);
// Execute query to get names of all employees.
SqlFieldsQuery sql = new SqlFieldsQuery("select AVG(FITNESSSCORE) from Chromosome");
// Iterate over the result set.
try (QueryCursor<List<?>> cursor = cache.query(sql)) {
for (List<?> row : cursor)
avgFitnessScore = (Double) row.get(0);
}
return avgFitnessScore;
}
示例12: getCityDetails
import org.apache.ignite.IgniteCache; //导入方法依赖的package包/类
private static void getCityDetails(IgniteCache cityCache, int cityId) {
SqlFieldsQuery query = new SqlFieldsQuery("SELECT * FROM City WHERE id = ?").setArgs(cityId);
FieldsQueryCursor<List<?>> cursor = cityCache.query(query);
Iterator<List<?>> iterator = cursor.iterator();
int colCount = cursor.getColumnsCount();
System.out.println();
System.out.println(">>> City Info:");
while (iterator.hasNext()) {
List row = iterator.next();
for (int i = 0; i < colCount; i++)
System.out.println(row.get(i));
}
}