Example usage for org.hibernate ScrollMode FORWARD_ONLY

List of usage examples for org.hibernate ScrollMode FORWARD_ONLY

Introduction

In this page you can find the example usage for org.hibernate ScrollMode FORWARD_ONLY.

Prototype

ScrollMode FORWARD_ONLY

To view the source code for org.hibernate ScrollMode FORWARD_ONLY.

Click Source Link

Document

Requests a scrollable result that is only scrollable forwards.

Usage

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 w  w .j  a  va2 s .  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//  w ww .j  av a2 s .c  om
 * @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:ubic.gemma.persistence.util.CommonQueries.java

License:Apache License

/**
 * @param session session/*  w  w w  .  j ava2s  .  c  o m*/
 * @param probes  probes
 * @return map of probes to all the genes 'detected' by those probes. Probes that don't map to genes will have an
 * empty gene collection.
 */
public static Map<Long, Collection<Long>> getCs2GeneMapForProbes(Collection<Long> probes, Session session) {
    if (probes.isEmpty())
        return new HashMap<>();

    Map<Long, Collection<Long>> cs2genes = new HashMap<>();

    String queryString = "SELECT CS AS csid, GENE AS geneId FROM GENE2CS g WHERE g.CS IN (:probes) ";
    org.hibernate.SQLQuery queryObject = session.createSQLQuery(queryString);
    queryObject.addScalar("csid", LongType.INSTANCE);
    queryObject.addScalar("geneId", LongType.INSTANCE);
    queryObject.setParameterList("probes", probes, LongType.INSTANCE);
    queryObject.setReadOnly(true);
    queryObject.setFlushMode(FlushMode.MANUAL);

    ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY);
    CommonQueries.addGeneIds(cs2genes, results);
    results.close();

    return cs2genes;
}

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

License:Apache License

public static Collection<Long> filterProbesByPlatform(Collection<Long> probes, Collection<Long> arrayDesignIds,
        Session session) {/*  w  ww.j  a v a 2s.  c om*/
    assert probes != null && !probes.isEmpty();
    assert arrayDesignIds != null && !arrayDesignIds.isEmpty();
    String queryString = "SELECT CS AS csid FROM GENE2CS WHERE AD IN (:adids) AND CS IN (:probes)";
    org.hibernate.SQLQuery queryObject = session.createSQLQuery(queryString);
    queryObject.addScalar("csid", LongType.INSTANCE);
    queryObject.setParameterList("probes", probes, LongType.INSTANCE);
    queryObject.setParameterList("adids", arrayDesignIds, LongType.INSTANCE);

    ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY);
    List<Long> r = new ArrayList<>();
    while (results.next()) {
        r.add(results.getLong(0));

    }
    results.close();
    return r;
}