Java 类net.sf.ehcache.search.expression.Criteria 实例源码

项目:modinvreg    文件:SearchableEhcache.java   
public Collection<T> fetchByCriteria( Criteria criteria ) {
    net.sf.ehcache.search.Query query = this.cache.createQuery();
    query.includeValues();
    query.addCriteria( criteria );
    Results results = null;
    try {
        results = query.execute();
    } catch ( Exception e ) {
        throw new SearchException( "Query error" );
    }

    if ( results == null ) {
        return null;
    }

    Collection<T> genes = new HashSet<T>( results.size() );

    for ( Result result : results.all() ) {
        genes.add( ( T ) result.getValue() );
    }

    return genes;
}
项目:ehcache-extensions    文件:CacheFailoverDecorator.java   
public TimedRefreshSyncOp(Attribute<Integer> partitionSearchAttribute, Integer partitionId) {
    this.query = delegatedCache.createQuery();
    Criteria searchCriteria = partitionSearchAttribute.eq(partitionId);
    query.addCriteria(searchCriteria);
    query.includeKeys();
    query.end();
}
项目:ehcache-extensions    文件:CachePartitionDecorator.java   
public TimedRefreshSyncOp(Attribute<Integer> partitionSearchAttribute, Integer partitionId) {
    this.query = delegatedCache.createQuery();
    Criteria searchCriteria = partitionSearchAttribute.eq(partitionId);
    query.addCriteria(searchCriteria);
    query.includeKeys();
    query.end();
}
项目:ehcache-search-example    文件:CacheTest.java   
private int performSearch(Criteria... criteria) {
    Query query = createQuery(criteria);
    long start = System.currentTimeMillis();
    Results results = query.execute();
    int count = results.size();
    long duration = System.currentTimeMillis() - start;
    log.info("Searchresult: found {} persons in {} ms.", count, duration);
    results.discard();
    return count;
}
项目:ehcache-search-example    文件:CacheTest.java   
private Query createQuery(Criteria... criteria) {
    Query query = cache.createQuery().includeValues();
    for (Criteria crit : criteria) {
        query.addCriteria(crit);
    }
    query.end();
    return query;
}
项目:modinvreg    文件:GeneCacheImpl.java   
@Override
public Gene fetchById( Long id ) {
    Criteria idCriteria = idAttribute.eq( id );
    Collection<Gene> results = fetchByCriteria( idCriteria );
    if ( results.size() == 0 ) {
        return null;
    } else if ( results.size() > 1 ) {
        log.warn( "Multiple terms match GO ID: (" + id + "), return first hit" );
    }
    return fetchByCriteria( idCriteria ).iterator().next();
}
项目:modinvreg    文件:GeneCacheImpl.java   
/**
 * See Bug 4187 - Improved gene search
 * 
 * <pre>
 * Sort search results using this order : 
 * 1. Gene symbols. Place exact matches first. 
 * 2. Gene name 
 * 3. Gene alias. Since this are concatenated, we loosely use *SYMBOL*
 * </pre>
 */
@Override
public Collection<Gene> fetchByQuery( String queryString, Long taxonId ) {
    ArrayList<Gene> results = new ArrayList<>();
    Criteria taxonCriteria = taxonAttribute.eq( taxonId );

    // 1. Exact Gene Symbols
    String regexQueryString = queryString;
    Criteria symbolCriteria = geneSymbolAttribute.ilike( regexQueryString );
    results.addAll( fetchByCriteria( taxonCriteria.and( symbolCriteria ) ) );

    // 2. Prefix Gene Symbols
    regexQueryString = queryString + "*";
    symbolCriteria = geneSymbolAttribute.ilike( regexQueryString );
    Collection<Gene> tmp = fetchByCriteria( taxonCriteria.and( symbolCriteria ) );
    tmp.removeAll( results );
    results.addAll( tmp );

    // 3. Prefix Gene name
    Criteria nameCriteria = geneNameAttribute.ilike( "*" + queryString + "*" );
    tmp = fetchByCriteria( taxonCriteria.and( nameCriteria ) );
    tmp.removeAll( results );
    results.addAll( tmp );

    // 4. Gene Alias. Special case, these are concatenated by ','
    // see GeneAliasAttributeExtractor
    regexQueryString = "*" + queryString + "*";
    Criteria aliasesCriteria = aliasesAttribute.ilike( regexQueryString );
    tmp = fetchByCriteria( taxonCriteria.and( aliasesCriteria ) );
    tmp.removeAll( results );
    results.addAll( tmp );

    return results;
}
项目:modinvreg    文件:GeneCacheImpl.java   
@Override
public Collection<Gene> fetchBySymbolsAndTaxon( Collection<String> geneSymbols, Long taxonId ) {
    Criteria symbolCriteria = geneSymbolAttribute.in( geneSymbols );

    Criteria taxonCriteria = taxonAttribute.eq( taxonId );

    return fetchByCriteria( taxonCriteria.and( symbolCriteria ) );
}
项目:crigtt    文件:CrigttCache.java   
@Nullable
public <T> T getValue(Class<T> valueClass, Criteria ... criteria) {
    List<T> values = this.getValues(valueClass, 1, criteria);

    return (!CollectionUtils.isEmpty(values) ? values.get(0) : null);
}
项目:crigtt    文件:CrigttCache.java   
public <T> List<T> getValues(Class<T> valueClass, Criteria ... criteria) {
    return this.getValues(valueClass, -1, criteria);
}
项目:crigtt    文件:CrigttCache.java   
public <T> List<T> getValues(Class<T> valueClass, int numMax, Criteria ... criteria) {
    Results results = this.buildQuery(numMax, criteria).includeValues().execute();

    return results.all().stream().map(result -> valueClass.cast(result.getValue())).collect(Collectors.toList());
}
项目:crigtt    文件:CrigttCache.java   
@Nullable
public <T> T getKey(Class<T> keyClass, Criteria ... criteria) {
    List<T> keys = this.getValues(keyClass, 1, criteria);

    return (!CollectionUtils.isEmpty(keys) ? keys.get(0) : null);
}
项目:crigtt    文件:CrigttCache.java   
public <T> List<T> getKeys(Class<T> keyClass, Criteria ... criteria) {
    return this.getKeys(keyClass, -1, criteria);
}
项目:crigtt    文件:CrigttCache.java   
public <T> List<T> getKeys(Class<T> keyClass, int numMax, Criteria ... criteria) {
    Results results = this.buildQuery(numMax, criteria).includeKeys().execute();

    return results.all().stream().map(result -> keyClass.cast(result.getKey())).collect(Collectors.toList());
}
项目:modinvreg    文件:GeneCacheImpl.java   
@Override
public Collection<Gene> fetchBySymbols( Collection<String> geneSymbols ) {
    Criteria symbolCriteria = geneSymbolAttribute.in( geneSymbols );

    return fetchByCriteria( symbolCriteria );
}
项目:modinvreg    文件:GeneCacheImpl.java   
@Override
public Collection<Gene> fetchByTaxons( Collection<Long> taxonIds ) {
    Criteria taxonCriteria = taxonAttribute.in( taxonIds );

    return fetchByCriteria( taxonCriteria );
}
项目:modinvreg    文件:GeneCacheImpl.java   
@Override
public Collection<Gene> fetchByIds( Collection<Long> ids ) {
    Criteria idCriteria = idAttribute.in( ids );

    return fetchByCriteria( idCriteria );
}
项目:crigtt    文件:CrigttCache.java   
public Query buildQuery(int numMax, Criteria ... criteria) {
    Query query = this.getNativeCache().createQuery().maxResults(numMax);

    Stream.of(criteria).forEach(query::addCriteria);

    return query;
}