Example usage for org.hibernate Query scroll

List of usage examples for org.hibernate Query scroll

Introduction

In this page you can find the example usage for org.hibernate Query scroll.

Prototype

ScrollableResults scroll(ScrollMode scrollMode);

Source Link

Document

Return the query results as ScrollableResults.

Usage

From source file:org.zanata.search.HTextFlowTargetIndexingStrategy.java

License:Open Source License

@Override
protected ScrollableResults queryResults(int ignoredOffset, FullTextSession session) {
    // TODO move this query into something like HTextFlowTargetStreamingDAO
    Query query = session.createQuery("from HTextFlowTarget tft " + "join fetch tft.locale "
            + "join fetch tft.textFlow " + "join fetch tft.textFlow.document "
            + "join fetch tft.textFlow.document.locale " + "join fetch tft.textFlow.document.projectIteration "
            + "join fetch tft.textFlow.document.projectIteration.project");
    query.setFetchSize(Integer.MIN_VALUE);
    return query.scroll(ScrollMode.FORWARD_ONLY);
}

From source file:org.zanata.search.SimpleClassIndexingStrategy.java

License:Open Source License

@Override
protected ScrollableResults queryResults(int offset, FullTextSession session) {
    Query query = session.createQuery("from " + getEntityType().getName());
    query.setFirstResult(offset);/*from   www  .java2s.  c om*/
    query.setMaxResults(MAX_QUERY_ROWS);
    return query.scroll(ScrollMode.FORWARD_ONLY);
}

From source file:ubic.gemma.persistence.service.expression.bioAssayData.DesignElementDataVectorDaoImpl.java

License:Apache License

private void getVectorsBatch(Map<Long, Collection<Long>> cs2gene, org.hibernate.Query queryObject,
        Map<T, Collection<Long>> dedv2genes, Collection<Long> batch) {
    queryObject.setParameterList("cs", batch);
    queryObject.setFlushMode(FlushMode.MANUAL);
    queryObject.setReadOnly(true);//from  ww  w .  j  a  va2  s.  c  o m
    ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY);

    while (results.next()) {
        @SuppressWarnings("unchecked")
        T dedv = (T) results.get(0);
        Long cs = (Long) results.get(1);
        Collection<Long> associatedGenes = cs2gene.get(cs);
        if (!dedv2genes.containsKey(dedv)) {
            dedv2genes.put(dedv, associatedGenes);
        } else {
            Collection<Long> mappedGenes = dedv2genes.get(dedv);
            mappedGenes.addAll(associatedGenes);
        }
    }

    results.close();
}

From source file:ubic.gemma.persistence.util.CommonQueries.java

License:Apache License

public static Map<CompositeSequence, Collection<Gene>> getCs2GeneMap(Collection<Gene> genes,
        Collection<ArrayDesign> arrayDesigns, Session session) {

    StopWatch timer = new StopWatch();
    timer.start();/*from  w  ww.  j  ava 2s  .  c  om*/
    final String csQueryString = "select distinct cs, gene from Gene as gene"
            + " inner join gene.products gp, BioSequence2GeneProduct ba, CompositeSequence cs "
            + " where ba.bioSequence=cs.biologicalCharacteristic and ba.geneProduct = gp"
            + " and gene in (:genes) and cs.arrayDesign in (:ads) ";

    Map<CompositeSequence, Collection<Gene>> cs2gene = new HashMap<>();
    Query queryObject = session.createQuery(csQueryString);
    queryObject.setCacheable(true);
    queryObject.setParameterList("genes", genes);
    queryObject.setParameterList("ads", arrayDesigns);
    queryObject.setReadOnly(true);
    queryObject.setFlushMode(FlushMode.MANUAL);

    ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY);
    CommonQueries.addGenes(cs2gene, results);
    results.close();
    if (timer.getTime() > 200) {
        CommonQueries.log.info("Get cs2gene for " + genes.size() + " :" + timer.getTime() + "ms");
    }
    return cs2gene;

}

From source file:ubic.gemma.persistence.util.CommonQueries.java

License:Apache License

/**
 * @param genes   genes/*from ww w .java2s . com*/
 * @param session session
 * @return map of probes to input genes they map to. Other genes those probes might detect are not included.
 */
public static Map<CompositeSequence, Collection<Gene>> getCs2GeneMap(Collection<Gene> genes, Session session) {

    StopWatch timer = new StopWatch();
    timer.start();
    final String csQueryString = "select distinct cs, gene from Gene as gene"
            + " inner join gene.products gp, BioSequence2GeneProduct ba, CompositeSequence cs "
            + " where ba.bioSequence=cs.biologicalCharacteristic and ba.geneProduct = gp"
            + " and gene in (:genes)  ";

    Map<CompositeSequence, Collection<Gene>> cs2gene = new HashMap<>();
    org.hibernate.Query queryObject = session.createQuery(csQueryString);
    queryObject.setCacheable(true);
    queryObject.setParameterList("genes", genes);
    queryObject.setReadOnly(true);
    queryObject.setFlushMode(FlushMode.MANUAL);

    ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY);
    CommonQueries.addGenes(cs2gene, results);
    results.close();
    if (timer.getTime() > 200) {
        CommonQueries.log.info("Get cs2gene for " + genes.size() + " :" + timer.getTime() + "ms");
    }
    return cs2gene;
}

From source file:vnpt.media.efinder.model.PaginationResult.java

public PaginationResult(Query query, int page, int maxResult, int maxNavigationPage) {
    final int pageIndex = page - 1 < 0 ? 0 : page - 1;
    int fromRecordIndex = pageIndex * maxResult;
    int maxRecordIndex = fromRecordIndex + maxResult;

    ScrollableResults resultScroll = query.scroll(ScrollMode.SCROLL_INSENSITIVE);

    //resultScroll.g
    List results = new ArrayList<>();
    boolean hasResult = resultScroll.first();
    if (hasResult) {
        // Cuon toi vi tri
        hasResult = resultScroll.scroll(fromRecordIndex);
        if (hasResult) {
            do {/*from ww w  .  j a va 2s .  com*/
                E record = (E) resultScroll.get(0);
                results.add(record);
            } while (resultScroll.next()//
                    && resultScroll.getRowNumber() >= fromRecordIndex
                    && resultScroll.getRowNumber() < maxRecordIndex);
        }

        // chuyen toi ban ghi cuoi
        resultScroll.last();
    }

    // Tong so ban ghi
    this.totalRecords = resultScroll.getRowNumber() + 1;
    this.currentPage = pageIndex + 1;
    this.list = results;
    this.maxResult = maxResult;
    this.totalPages = (this.totalRecords / this.maxResult);
    if (totalRecords % this.maxResult != 0) {
        this.totalPages = this.totalPages + 1;
    }
    this.maxNavigationPage = totalPages;

    if (maxNavigationPage < totalPages) {
        this.maxNavigationPage = maxNavigationPage;
    }

    this.calcNavigationPages();

}